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
feat: add interactivity to ch4 - 4th example, navigation functionality
- add lines to code and content, to incorporate an interactive slider to
the 4th example of chapter 4.
- add front matter attribute to all main content pages, to enable navigation
functionality.
- add template for the navigation items to base.html
- add styling rules for these navigation items
Copy file name to clipboardExpand all lines: src/chapter3/_section3_1.md
+22-20Lines changed: 22 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -105,54 +105,55 @@ Applied parameters:
105
105
106
106
* Direction, directly through $x, y$ coordinates of velocity,
107
107
108
-
range = $(-3, 3)$
108
+
range = $(-4, 4)$
109
109
* Velocity (both magnitude and direction)
110
-
111
110
range:
112
-
- mag $\in (0,$ diameter $/2)$,
111
+
- mag $\in (0,$ radius $\times 1.5)$,
113
112
- direction $\in (-1,1)$
114
113
```js
115
114
/* Code for a 2D RW that is manupilated according to perlin noise.
116
115
Walk is performed by picking a noise value separately for the x-coord and y-coord
117
-
Hereafter noise value will be referred as n-value*/
116
+
In this program noise value will be referred as n-value
117
+
*/
118
118
119
119
classWalker {
120
-
/* Setting class fields - offests for each co-ordinate (starting point in time for the noise function)
121
-
x and y offests are always increased and z offest only when step() affecting_parameter is 'step'*/
122
-
xoff =0;
123
-
yoff =1000; ////Note that the difference is arbitrary, but it is important,
124
-
zoff =2000; //in order to avoid co-orrelation between each direction (in a given time t)
120
+
// Setting class fields - offests for each co-ordinate
121
+
// i.e. (starting point in time for the noise function)
122
+
// x and y offests are always increased and mag offest only when update() affecting_parameter is 'step'
123
+
xOffset =0;
124
+
yOffset =1000; // Note that the difference is arbitrary, but it is important,
125
+
magOffset =2000; // in order to avoid co-orrelation between each direction (in a given time t)
125
126
constructor(x,y,r) {
126
127
this.x= x;
127
128
this.y= y;
128
129
this.r= r;
130
+
this.D=this.r*2;
129
131
}
130
132
131
133
display() {
132
-
//Displays the walker at the current location with a circle of radius r
133
134
stroke(0);
134
135
fill(100);
135
-
circle(this.x, this.y,this.r);
136
+
circle(this.x, this.y,this.D);
136
137
}
137
138
138
-
step(affecting_params='direction') {
139
+
update(affecting_params='direction') {
139
140
//Switch statement to determine the which parameter is being affected. Default: direction
140
141
//All of them are affected by Perlin noise
141
142
switch(affecting_params){
142
143
// Changing the direction in which the walker is moving
143
144
case'direction':
144
-
this.x+=map(noise(this.xoff),0,1,-1,1)*3; //map() scales n-value to (-1,1) from (0,1) - Enabling RW to move in all directions
145
-
this.y+=map(noise(this.yoff),0,1,-1,1)*3; //3 is the maginitude of the step. An arbitrary standard accross all RW methods
145
+
this.x+=map(noise(this.xoff),0,1,-1,1)*4; //map() scales n-value to (-1,1) from (0,1) - Enabling RW to move in all directions
146
+
this.y+=map(noise(this.yoff),0,1,-1,1)*4; //4 is the maginitude of the step. An arbitrary standard accross all RW methods
146
147
break;
147
148
// Directly changing the location of the walker
148
149
case'location':
149
-
this.x=noise(this.xoff)*width; //noise(t)*k - scales n-value to (0,k) from (0,1)
150
-
this.y=noise(this.yoff)*height; //Therefore here x-values are (0,width) and y-values are (0,height)
150
+
this.x=noise(this.xoff)*width; //noise(t)*k - scales n-value to (0,k) from (0,1)
151
+
this.y=noise(this.yoff)*height; //Therefore here x-values are (0,width) and y-values are (0,height)
151
152
break;
152
153
153
154
// Changing both step size and direction
154
155
case'step':
155
-
let vel_mag =noise(this.zoff)*(this.r/2);
156
+
let vel_mag =noise(this.zoff)*(this.r*1.5);
156
157
this.x+=map(noise(this.xoff),0,1,-1,1)*vel_mag;
157
158
this.y+=map(noise(this.yoff),0,1,-1,1)*vel_mag;
158
159
this.zoff+=0.01;
@@ -168,19 +169,20 @@ let w;
168
169
functionsetup() {
169
170
createCanvas(windowWidth, windowHeight);
170
171
background(255);
171
-
w =newWalker(width/2, height/2, 20);
172
+
w =newWalker(width/2, height/2, 8);
172
173
}
173
174
174
175
functiondraw() {
175
176
// Be aware of which function you call first according to the step type you chose
176
177
w.display();
177
-
w.step('direction');
178
+
w.update('direction');
178
179
}
179
180
```
181
+
Note that the implementation [code for the simulation](https://github.com/beeezal/Honours-website-project/blob/main/src/assets/scripts/chap3_01.js) is syntatically different from the above code, but the ideas are the same. Main difference is that the order of calling `display()` and `update()` is taken care of by the program, and instead of a switch statement we use an object (with a function for each param).
180
182
181
183
{% include "simulation-grid.html" %}
182
184
183
-
A simulation of a similar implementation of the Perlin Noise walker is added to the 4^th^ chapter, in section [4.3.4](../chapter4/#434-comparing-implementations-of-random-motion-behaviours)
185
+
A simulation of a similar implementation of the Perlin Noise walker is added to the 4^th^ chapter, in section [4.3.4](../chapter4/#434-comparing-implementations-of-random-motion-behaviours).
0 commit comments