Skip to content

Commit c941f7d

Browse files
committed
testing many sketches
1 parent 7d6330e commit c941f7d

File tree

4 files changed

+128
-56
lines changed

4 files changed

+128
-56
lines changed

Boids.html

+102-49
Original file line numberDiff line numberDiff line change
@@ -10,84 +10,137 @@
1010

1111
<!-- CDNs -->
1212
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
13-
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.0/p5.js"></script>
13+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.2/p5.min.js" integrity="sha512-1YMgn4j8cIL91s14ByDGmHtBU6+F8bWOMcF47S0cRO3QNm8SKPNexy4s3OCim9fABUtO++nJMtcpWbINWjMSzQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
1414

15-
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/prism.min.js" integrity="sha512-UOoJElONeUNzQbbKQbjldDf9MwOHqxNz49NNJJ1d90yp+X9edsHyJoAs6O4K19CZGaIdjI5ohK+O2y5lBTW6uQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
16-
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/components/prism-javascript.min.js" integrity="sha512-yvw5BDA/GQu8umskpIOBhX2pDLrdOiriaK4kVxtD28QEGLV5rscmCfDjkrx52tIgzLgwzs1FsALV6eYDpGnEkQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
17-
<!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism-twilight.min.css" integrity="sha512-6rkEt5SymQMcnlRz1dHwAMSfMnDaFX28qdr3wyaa+XRCR8dTSWE4U6vjiTVuB6Mq9FgYOLVOTk0lrOeCnodcgA==" crossorigin="anonymous" referrerpolicy="no-referrer" /> -->
15+
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.23.0/themes/prism.min.css" rel="stylesheet">
16+
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.23.0/prism.min.js"></script>
1817

1918
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
2019
<link href="/SimulationLabs/Stylesheets/Default.css" rel="stylesheet">
2120

2221
<!-- Simulations -->
2322
<script src="/SimulationLabs/Scripts/Boids/Boids.js" defer></script>
24-
23+
<script src="/SimulationLabs/Scripts/Boids/Circles1.js" defer></script>
24+
<script src="/SimulationLabs/Scripts/Boids/Circles2.js" defer></script>
2525
</head>
2626

2727
<body>
2828
{% include HeaderBar.html %}
2929

30-
<!-- Page content -->
31-
<p> This is the boids page </p>
32-
33-
<h2> Contents </h2>
30+
<div class="section">
31+
<!-- Page content -->
32+
<p> This is the boids page </p>
33+
34+
<h2> Contents </h2>
3435

35-
<ul>
36-
<p> There's probably a bootstrap component for this... </p>
37-
</ul>
36+
<ul>
37+
<p> There's probably a bootstrap component for this... </p>
38+
</ul>
3839

39-
<h2> What you'll create </h2>
40+
<h2> What you'll create </h2>
4041

41-
<div id="BoidContainer"></div>
42+
<div id="BoidContainer"></div>
4243

43-
<emph> (This is not an actual boids sketch btw - this is a random stepper) </emph>
44+
<emph> (This is not an actual boids sketch btw - this is a random stepper) </emph>
4445

45-
<h2> Prereqs </h2>
46+
<h2> Prereqs </h2>
4647

47-
<ul> Know how to program using a procedural language e.g. Python, Java, C#, JavaScript etc. </ul>
48-
<ul> Basic OOP i.e. you know what a class is </ul>
48+
<ul> Know how to program using a procedural language e.g. Python, Java, C#, JavaScript etc. </ul>
49+
<ul> Basic OOP i.e. you know what a class is </ul>
4950

50-
<p> We will be coding in JavaScript but don't worry about knowing the ins and outs of the language; you should be able to pick it up as we go! </p>
51+
<p> We will be coding in JavaScript but don't worry about knowing the ins and outs of the language; you should be able to pick it up as we go! </p>
5152

52-
<h2> Introduction to p5.js </h2>
53-
54-
We will be using JavaScript and a library called <strong> p5.js</strong>, made by the lovely <a href="https://processingfoundation.org/"> Processing Foundation</a>.
55-
56-
<ol>
57-
<li> <p>To get started, create an account for the <a href="https://editor.p5js.org/signup">web editor</a>. </p> </li>
58-
<li> <p> Open a new sketch (File->New) </p> </li>
59-
</ol>
60-
61-
<p> Your new sketch should have 2 functions: </p>
53+
<h2> Introduction to p5.js </h2>
54+
55+
We will be using JavaScript and a library called <strong> p5.js</strong>, made by the lovely <a href="https://processingfoundation.org/"> Processing Foundation</a>.
56+
57+
<ol>
58+
<li> <p>To get started, create an account for the <a href="https://editor.p5js.org/signup">web editor</a>. </p> </li>
59+
<li> <p> Open a new sketch (File->New) </p> </li>
60+
</ol>
61+
62+
<p> Your new sketch should have 2 functions: </p>
63+
64+
<ul>
65+
<li> <strong> setup() </strong> which is a function executed once at the start </li>
66+
<li> <strong> draw() </strong> which is a function executed every frame (by default, about 60 times a second) </li>
67+
</ul>
6268

63-
64-
<pre>
65-
<code class="language-js">
66-
console.log('hello world');
67-
</code>
68-
</pre>
69+
We create the canvas (arguments being the width and length) in <strong> setup() </strong> since we only need to do this once, and draw background (which you can call with RGB colour arguments as below) is called every frame in <strong> draw()</strong>!
6970

70-
<h3> Task </h3>
71+
<pre>
72+
<code class="language-js">
73+
function draw() {
74+
redV = 128
75+
greenV = 12
76+
blueV = 128
77+
background(redV, greenV, blueV); // my favourite colour; purple!
78+
}
79+
</code>
80+
</pre>
7181

72-
73-
<h2> Autonomous Agents Intro </h2>
82+
This difference matters when it comes to sketches with changing elements. See the difference in the following sketch, where we draw a circle at the mouse's position every frame.
7483

75-
<p> Applying forces, basic goals </p>
84+
<h3> Circles 1 - Background Drawn Once </h3>
85+
86+
<div id="Circles1Container"></div>
7687

77-
<h2> Creating boid flocks </h2>
88+
<pre>
89+
<code class="language-js">
90+
function setup() {
91+
createCanvas(400, 400);
92+
background(222, 222, 222);
93+
}
7894

79-
<p> With room for more behaviours! </p>
95+
let circleSize = 10;
8096

81-
<h2> Extension Material</h2>
97+
function draw() {
98+
circle(mouseX, mouseY, circleSize);
99+
}
100+
</code>
101+
</pre>
82102

83-
<p> Link to an <a href="/SimulationLabs/BoidsExtension"> extension site </a> with scope for learning how to host your own </p>
103+
<h3> Circles 2 - Background Drawn Every Frame </h3>
104+
105+
<div id="Circles2Container"></div>
84106

85-
<h2> Further Reading </h2>
107+
<pre>
108+
<code class="language-js">
109+
function setup() {
110+
createCanvas(400, 400);
111+
}
86112

87-
<ul>
88-
<li> <a href="https://www.youtube.com/watch?v=yGhfUcPjXuE"> Dear Game Developers, Stop Messing This Up! </a> - YT Video on delta-time and basic physics </li>
89-
<li> <a href="https://natureofcode.com/"> Nature of Code </a> - A book by Daniel Shiffman which these labs take inspiration from! It features a section on boids and many more simulations of things from nature (highly recommend) </li>
90-
<li> <a href="https://www.youtube.com/watch?v=bqtqltqcQhw">Coding Adventure: Boids</a> - Sebastian Lague's brilliant video on boids is the main inspiration for this lab! He takes boids into 3D and explores a raycasting approach to collision avoidance </li>
91-
</ul>
113+
let circleSize = 10;
114+
115+
function draw() {
116+
background(222, 222, 222); // background drawn every frame!
117+
circle(mouseX, mouseY, circleSize);
118+
}
119+
</code>
120+
</pre>
121+
122+
<h3> Task </h3>
123+
124+
125+
<h2> Autonomous Agents Intro </h2>
126+
127+
<p> Applying forces, basic goals </p>
128+
129+
<h2> Creating boid flocks </h2>
130+
131+
<p> With room for more behaviours! </p>
132+
133+
<h2> Extension Material</h2>
134+
135+
<p> Link to an <a href="/SimulationLabs/BoidsExtension"> extension site </a> with scope for learning how to host your own </p>
136+
137+
<h2> Further Reading </h2>
138+
139+
<ul>
140+
<li> <a href="https://www.youtube.com/watch?v=yGhfUcPjXuE"> Dear Game Developers, Stop Messing This Up! </a> - YT Video on delta-time and basic physics </li>
141+
<li> <a href="https://natureofcode.com/"> Nature of Code </a> - A book by Daniel Shiffman which these labs take inspiration from! It features a section on boids and many more simulations of things from nature (highly recommend) </li>
142+
<li> <a href="https://www.youtube.com/watch?v=bqtqltqcQhw">Coding Adventure: Boids</a> - Sebastian Lague's brilliant video on boids is the main inspiration for this lab! He takes boids into 3D and explores a raycasting approach to collision avoidance </li>
143+
</ul>
144+
</section>
92145
</body>
93146
</html>

Scripts/Boids/Circles1.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function setup() {
2+
var cnv = createCanvas(400, 400);
3+
cnv.parent('Circles1Container');
4+
5+
background(222, 222, 222);
6+
}
7+
8+
var circleSize = 10;
9+
10+
function draw() {
11+
circle(mouseX, mouseY, circleSize);
12+
}

Scripts/Boids/Circles2.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
console.log("this script is run!");
2+
3+
function setup() {
4+
console.log("script is setup...");
5+
var cnv = createCanvas(400, 400);
6+
cnv.parent('Circles2Container');
7+
}
8+
9+
var circleSize = 10;
10+
11+
function draw() {
12+
background(222, 222, 222); // background drawn every frame!
13+
circle(mouseX, mouseY, circleSize);
14+
}

Stylesheets/Default.css

-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +0,0 @@
1-
.headerStyle {
2-
3-
}
4-
5-
/* pre {
6-
background-color: black;
7-
} */

0 commit comments

Comments
 (0)