You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p> The aim of this workshop is to recreate boids, which are a simulation of birds and other flocking entities (like fishes).
46
+
Hopefully, you'll be able to apply this in your own projects!
47
+
Along the way, we'll learn a little bit about p5.js, rendering, and physics. </p>
43
48
44
49
<divid="BoidContainer"></div>
45
50
46
-
<emph> (This is not an actual boids sketch btw - this is a random stepper) </emph>
51
+
<em> (This is not an actual boids sketch btw - this is a random stepper) </em>
47
52
48
-
<h2>Prereqs</h2>
53
+
<h2>Prerequisites</h2>
49
54
<ul>
50
55
<li> Know how to program using a procedural language e.g. Python, Java, C#, JavaScript etc. </li>
51
56
<li> Basic OOP i.e. you know what a class is </li>
57
+
<li> Some physics knowledge - vectors, position, velocity, acceleration </li>
52
58
</ul>
53
59
54
60
<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>
@@ -62,6 +68,9 @@ <h2> Introduction to p5.js </h2>
62
68
<li><p> Open a new sketch (File->New) </p></li>
63
69
</ol>
64
70
71
+
<h3> What is a sketch? </h3>
72
+
<emph>Insert brief description (couple lines) on what a sketch is, and what frames are... </emph>
73
+
65
74
<p> Your new sketch should have 2 functions: </p>
66
75
67
76
<ul>
@@ -73,6 +82,10 @@ <h2> Introduction to p5.js </h2>
73
82
74
83
<pre>
75
84
<codeclass="language-js">
85
+
function setup() {
86
+
createCanvas(400, 400);
87
+
}
88
+
76
89
function draw() {
77
90
let redV = 128; // if you're new to js, use "let" to declare variables
78
91
let greenV = 12;
@@ -81,8 +94,9 @@ <h2> Introduction to p5.js </h2>
81
94
}
82
95
</code>
83
96
</pre>
84
-
85
-
This difference matters when it comes to sketches with changing elements; see the difference in the following sketches, where we draw a circle at the mouse's position every frame. One draws a background once, and the other draws a background every frame.
97
+
<p><em> If you're unfamiliar with RGB values, go <ahref="/SimulationLabs/Docs/RGBValues">here</a></em></p>
98
+
99
+
<p>This difference matters when it comes to sketches with changing elements; see the difference in the following sketches, where we draw a circle at the mouse's position every frame. One draws a background once, and the other draws a background every frame. </p>
<emph> Background is called just once - at the start - and many circles are drawn over it. </emph>
107
-
121
+
122
+
<p>Note the use of <strong>mouseX</strong> and <strong>mouseY</strong> which are variables updated every frame! </p>
123
+
108
124
<h3> Circles 2 - Background Drawn Every Frame </h3>
109
125
110
126
<divid="Circles2Container"></div>
@@ -146,6 +162,19 @@ <h3> Task: Multicolour </h3>
146
162
147
163
<strong><emph>Hint:</emph></strong> The range of colours is 0-255 (anything >255 will be interpreted as 255), so you will have to use modulus (<strong>%</strong>) or if statements to ensure RGB values don't go outside that range!
148
164
165
+
<h2> Using Arrays and Objects </h2>
166
+
167
+
Useful: <ahref="https://p5js.org/reference/#Shape"> Not sure which chapter to put this in yet...</a>
0 commit comments