Skip to content

Commit a6f3ff7

Browse files
committed
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
1 parent 6026d2c commit a6f3ff7

File tree

14 files changed

+196
-27
lines changed

14 files changed

+196
-27
lines changed

src/_includes/layouts/base.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,30 @@
1919
<body>
2020
{% block content %}
2121
{{ content | safe }}
22+
23+
<nav class="chapter-navigation">
24+
<div class="prev-container">
25+
{% if prevPage %}
26+
<a href="{{ prevPage | url }}" class="prev-link">
27+
<span class="nav-arrow"></span> Previous
28+
</a>
29+
{% endif %}
30+
</div>
31+
32+
<div class="home-container">
33+
<a href="{{ '/' | url }}" class="home-link">
34+
<span class="nav-icon"></span> Home
35+
</a>
36+
</div>
37+
38+
<div class="next-container">
39+
{% if nextPage %}
40+
<a href="{{ nextPage | url }}" class="next-link">
41+
Next <span class="nav-arrow"></span>
42+
</a>
43+
{% endif %}
44+
</div>
45+
</nav>
2246
{% endblock %}
2347
</body>
2448
</html>

src/appendix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
tags: [appendix, simulation, p5]
33
title: 'Appendix: How to run p5 sketches'
44
layout: 'base'
5+
prevPage: '/bibliography/'
56
---
67
# Appendix: How to run p5 sketches
78

src/assets/cssStyle/generic.css

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ html{
55

66
body {
77
margin: 0 auto;
8-
padding: 0 3rem;
8+
padding: 0 3rem 3rem 3rem;
99
width: 100%;
1010
box-sizing: border-box;
1111
}
@@ -224,4 +224,70 @@ pre:not([class*="language-"]) {
224224
padding: 1em 1em 1em 1.5em;
225225
font-size: 16px;
226226
line-height: 1.5;
227+
}
228+
229+
/* Styling for chapter navigation buttons */
230+
.chapter-navigation {
231+
display: grid;
232+
grid-template-columns: 1fr 1fr 1fr;
233+
align-items: center;
234+
margin-top: 3rem;
235+
padding-top: 1.5rem;
236+
border-top: 1px solid rgba(0, 0, 0, 0.1);
237+
gap: 1rem;
238+
}
239+
240+
.chapter-navigation a {
241+
display: inline-flex;
242+
align-items: center;
243+
text-decoration: none;
244+
color: #333;
245+
padding: 0.5rem 0.8rem;
246+
border-radius: 5px;
247+
transition: background-color 0.2s, color 0.2s;
248+
font-weight: 500;
249+
width: auto;
250+
}
251+
252+
.chapter-navigation a:hover {
253+
background-color: #f4f6fa;
254+
color: #0056b3;
255+
}
256+
257+
.nav-arrow, .nav-icon {
258+
display: inline-flex;
259+
align-items: center;
260+
justify-content: center;
261+
font-size: 1.2em;
262+
}
263+
264+
/* Container divs for positioning links */
265+
.prev-container {
266+
grid-column: 1;
267+
display: flex;
268+
justify-content: flex-start;
269+
}
270+
271+
.home-container {
272+
grid-column: 2;
273+
display: flex;
274+
justify-content: center;
275+
}
276+
277+
.next-container {
278+
grid-column: 3;
279+
display: flex;
280+
justify-content: flex-end;
281+
}
282+
283+
.prev-link .nav-arrow {
284+
margin-right: 0.5rem;
285+
}
286+
287+
.next-link .nav-arrow {
288+
margin-left: 0.5rem;
289+
}
290+
291+
.home-link .nav-icon {
292+
margin-right: 0.5rem;
227293
}

src/assets/scripts/chap4_04.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ let perlinScript = function (p) {
3131
p.circle(this.pos.x, this.pos.y, this.r * 2);
3232
}
3333

34-
step(vel_mag = 3, chk_edges = true) {
34+
step(noisyStepSize = false, vel_mag = 3, chk_edges = true, relativeMaxStepSize = 0.75) {
3535
this.updatePosHistory();
3636

37+
if(noisyStepSize){
38+
vel_mag = p.noise(this.magOffset)*(this.r*relativeMaxStepSize);
39+
this.magOffset += 0.01;
40+
}
3741
PerlinWalker.noisyVelocity(this.xOffset, this.yOffset, this.vel);
3842

3943
this.vel.setMag(vel_mag);
@@ -46,8 +50,8 @@ let perlinScript = function (p) {
4650
}
4751

4852
static noisyVelocity(xOffset, yOffset, vector) {
49-
vector.set(p.map(p.noise(xOffset), 0, 1, -1, 1),
50-
p.map(p.noise(yOffset), 0, 1, -1, 1)
53+
vector.set((p.noise(xOffset) - 0.5)*2 ,
54+
(p.noise(yOffset) - 0.5)*2
5155
);
5256
}
5357

@@ -73,6 +77,8 @@ let perlinScript = function (p) {
7377
}
7478

7579
let noiseWalker = new PerlinWalker(p.width / 2, p.height / 2, 12);
80+
let container, maxStepSlider, relativeMaxStepSize, label;
81+
let noisyStepSize = true;
7682

7783
p.initializeSketch = function () {
7884
noiseWalker.pos.set(p.width / 2, p.height / 2);
@@ -87,13 +93,26 @@ let perlinScript = function (p) {
8793
let canvas = p.createCanvas(850, 550);
8894
canvas.parent('sec4');
8995

96+
container = p.select('#interactive-controls-sec4');
97+
98+
maxStepSlider = p.createSlider(0, 1, 0.75, 0);
99+
maxStepSlider.parent(container);
100+
label = p.createSpan('Max(NoisyStepSize): r*' + 0.75);
101+
label.parent(container);
102+
103+
maxStepSlider.input(() => {
104+
relativeMaxStepSize = maxStepSlider.value();
105+
noisyStepSize = (relativeMaxStepSize > 0);
106+
label.html('Max(NoisyStepSize): r*' + relativeMaxStepSize.toFixed(2));
107+
});
108+
90109
p.initializeSketch();
91110
}
92111

93112
p.draw = function () {
94113
p.background(255);
95114
noiseWalker.display();
96-
noiseWalker.step(3, true);
115+
noiseWalker.step(noisyStepSize, 3, true, relativeMaxStepSize);
97116
}
98117
}
99118

src/bibliography.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ tags: [main, bibliography, simulation]
33
title: Bibliography
44
layout: 'base'
55
order: 8
6+
prevPage: '/conclusion/'
7+
nextPage: '/appendix/'
68
---
79
# Bibliography
810

src/chapter0/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ title: Introduction
44
layout: 'base'
55
number: 0
66
order: 1
7+
nextPage: '/chapter1/'
78
---
89

910
# Chapter 0

src/chapter1/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
layout: 'base'
55
number: 1
66
order: 2
7+
prevPage: '/chapter0/'
8+
nextPage: '/chapter2/'
79
---
810

911
<h1>Chapter 1</h1>

src/chapter2/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
layout: 'base'
55
number: 2
66
order: 3
7+
prevPage: '/chapter1/'
8+
nextPage: '/chapter3/'
79
---
810

911
<h1>Chapter 2</h1>

src/chapter3/_section3_1.md

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -105,54 +105,55 @@ Applied parameters:
105105

106106
* Direction, directly through $x, y$ coordinates of velocity,
107107

108-
range = $(-3, 3)$
108+
range = $(-4, 4)$
109109
* Velocity (both magnitude and direction)
110-
111110
range:
112-
- mag $\in (0,$ diameter $/2)$,
111+
- mag $\in (0,$ radius $\times 1.5)$,
113112
- direction $\in (-1,1)$
114113
```js
115114
/* Code for a 2D RW that is manupilated according to perlin noise.
116115
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+
*/
118118

119119
class Walker {
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)
125126
constructor(x,y,r) {
126127
this.x = x;
127128
this.y = y;
128129
this.r = r;
130+
this.D = this.r * 2;
129131
}
130132

131133
display() {
132-
//Displays the walker at the current location with a circle of radius r
133134
stroke(0);
134135
fill(100);
135-
circle(this.x, this.y,this.r);
136+
circle(this.x, this.y,this.D);
136137
}
137138

138-
step(affecting_params='direction') {
139+
update(affecting_params='direction') {
139140
//Switch statement to determine the which parameter is being affected. Default: direction
140141
//All of them are affected by Perlin noise
141142
switch(affecting_params){
142143
// Changing the direction in which the walker is moving
143144
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
146147
break;
147148
// Directly changing the location of the walker
148149
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)
151152
break;
152153

153154
// Changing both step size and direction
154155
case 'step':
155-
let vel_mag = noise(this.zoff)*(this.r/2);
156+
let vel_mag = noise(this.zoff)*(this.r*1.5);
156157
this.x += map(noise(this.xoff),0,1,-1,1)*vel_mag;
157158
this.y += map(noise(this.yoff),0,1,-1,1)*vel_mag;
158159
this.zoff += 0.01;
@@ -168,19 +169,20 @@ let w;
168169
function setup() {
169170
createCanvas(windowWidth, windowHeight);
170171
background(255);
171-
w = new Walker(width/2, height/2, 20);
172+
w = new Walker(width/2, height/2, 8);
172173
}
173174

174175
function draw() {
175176
// Be aware of which function you call first according to the step type you chose
176177
w.display();
177-
w.step('direction');
178+
w.update('direction');
178179
}
179180
```
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).
180182
181183
{% include "simulation-grid.html" %}
182184
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).
184186
185187
## Notes:
186188

src/chapter3/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
layout: 'base'
55
number: 3
66
order: 4
7+
prevPage: '/chapter2/'
8+
nextPage: '/chapter4/'
79
---
810

911
<h1>Chapter 3</h1>

0 commit comments

Comments
 (0)