Skip to content

Commit 608518d

Browse files
committed
Corrected emph to em
1 parent 4aa6541 commit 608518d

File tree

5 files changed

+132
-7
lines changed

5 files changed

+132
-7
lines changed

Boids.html

+39-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<script src="/SimulationLabs/Scripts/Boids/Circles1.js" defer></script>
2424
<script src="/SimulationLabs/Scripts/Boids/Circles2.js" defer></script>
2525
<script src="/SimulationLabs/Scripts/Boids/RainbowCircles.js" defer></script>
26+
<script src="/SimulationLabs/Scripts/Boids/RainbowTrails.js" defer></script>
2627
</head>
2728

2829
<body>
@@ -40,15 +41,20 @@ <h2> Contents </h2>
4041
</ul>
4142

4243
<h2> What you'll create </h2>
44+
45+
<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>
4348

4449
<div id="BoidContainer"></div>
4550

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>
4752

48-
<h2> Prereqs </h2>
53+
<h2> Prerequisites </h2>
4954
<ul>
5055
<li> Know how to program using a procedural language e.g. Python, Java, C#, JavaScript etc. </li>
5156
<li> Basic OOP i.e. you know what a class is </li>
57+
<li> Some physics knowledge - vectors, position, velocity, acceleration </li>
5258
</ul>
5359

5460
<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>
6268
<li> <p> Open a new sketch (File->New) </p> </li>
6369
</ol>
6470

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+
6574
<p> Your new sketch should have 2 functions: </p>
6675

6776
<ul>
@@ -73,6 +82,10 @@ <h2> Introduction to p5.js </h2>
7382

7483
<pre>
7584
<code class="language-js">
85+
function setup() {
86+
createCanvas(400, 400);
87+
}
88+
7689
function draw() {
7790
let redV = 128; // if you're new to js, use "let" to declare variables
7891
let greenV = 12;
@@ -81,8 +94,9 @@ <h2> Introduction to p5.js </h2>
8194
}
8295
</code>
8396
</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 <a href="/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>
86100

87101
<h3> Circles 1 - Background Drawn Once </h3>
88102

@@ -104,7 +118,9 @@ <h3> Circles 1 - Background Drawn Once </h3>
104118
</pre>
105119

106120
<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+
108124
<h3> Circles 2 - Background Drawn Every Frame </h3>
109125

110126
<div id="Circles2Container"></div>
@@ -146,6 +162,19 @@ <h3> Task: Multicolour </h3>
146162

147163
<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!
148164

165+
<h2> Using Arrays and Objects </h2>
166+
167+
Useful: <a href="https://p5js.org/reference/#Shape"> Not sure which chapter to put this in yet...</a>
168+
169+
Useful: use framerate to debug
170+
171+
<h3> Task: Rainbow Trails </h3>
172+
173+
<div id="RainbowTrailsContainer"></div>
174+
175+
<h2> May the Force be with you </h2>
176+
177+
<p> To make our boids move, </p>
149178
<h2> Autonomous Agents Intro </h2>
150179

151180
<p> Applying forces, basic goals </p>
@@ -154,10 +183,14 @@ <h2> Creating boid flocks </h2>
154183

155184
<p> With room for more behaviours! </p>
156185

186+
<h2> Next Time... </h2>
187+
188+
Next workshop, we'll be looking at using procedural generation.
189+
157190
<h2> Extension Material</h2>
158191

159192
<p> Link to an <a href="/SimulationLabs/BoidsExtension"> extension site </a> with scope for learning how to host your own </p>
160-
193+
161194
<h2> Further Reading </h2>
162195

163196
<ul>

BoidsExtension.html

+7
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,12 @@
2525
<h2> Styling </h2>
2626

2727
<p> Probably how to style and host your own p5 sketches in websites </p>
28+
29+
<h2> Ideas for this ext </h2>
30+
31+
<ul>
32+
<li> Extra parts like using describe() </li>
33+
<li> Extra events like doubleClicked() </li>
34+
</ul>
2835
</body>
2936
</html>

Docs/RGBValues.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: RGB Values
3+
---
4+
5+
Insert notes on RGB values here...

Scripts/Boids/RainbowTrails.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
let rainbowTrails = new p5((sk) => {
2+
sk.setup = () => {
3+
let cnv = sk.createCanvas(400, 400);
4+
cnv.parent("RainbowTrailsContainer");
5+
}
6+
7+
const circleSize = 10;
8+
let redV = 134;
9+
let greenV = 213;
10+
let blueV = 21;
11+
12+
const rShift = 13;
13+
const gShift = 5;
14+
const bShift = 27;
15+
16+
const trails = [];
17+
const trailLength = 10;
18+
19+
class trailObject {
20+
constructor(colour, position){
21+
this.colour = colour
22+
this.position = position
23+
}
24+
}
25+
26+
function updateTrail(){
27+
if(trails.length == trailLength){ // should remove one
28+
trails.shift(); // god these method names
29+
}
30+
31+
// create trail object to insert
32+
trailObj = new trailObject(sk.color(redV, greenV, blueV), sk.createVector(sk.mouseX, sk.mouseY));
33+
trails.push(trailObj);
34+
}
35+
36+
function drawTrail(){
37+
for(let i = 0; i < trails.length; i++){
38+
let trailObj = trails[i];
39+
40+
// update pen
41+
sk.stroke(trailObj.colour);
42+
sk.fill(trailObj.colour);
43+
44+
// draw
45+
sk.circle(trailObj.position.x, trailObj.position.y, circleSize);
46+
}
47+
}
48+
49+
sk.draw = () => {
50+
// update rgb values
51+
redV = (redV + rShift) % 256;
52+
greenV = (greenV + gShift) % 256;
53+
blueV = (blueV + bShift) % 256;
54+
55+
// update the colours
56+
sk.stroke(redV, greenV, blueV);
57+
sk.fill(redV, greenV, blueV);
58+
59+
60+
sk.background(222, 222, 222); // background drawn every frame!
61+
sk.circle(sk.mouseX, sk.mouseY, circleSize);
62+
63+
// trail stuff
64+
drawTrail();
65+
updateTrail();
66+
}
67+
});
68+

Solutions/Boids/Task1Part1.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,17 @@ title: Boids - Task 1, Part 1
55
Insert writeup here...
66

77
```js
8-
console.log("hello world!");
8+
function setup() {
9+
createCanvas(400, 400);
10+
}
11+
12+
let circleSize = 10;
13+
14+
function draw() {
15+
stroke(230, 215, 255); // outlines are now lilac!
16+
fill(135, 31, 120); // areas are now purple!
17+
18+
background(222, 222, 222); // background drawn every frame!
19+
circle(mouseX, mouseY, circleSize);
20+
}
921
```

0 commit comments

Comments
 (0)