The Nature of Code

Skolekoding.no > Tekst-koding > p5.js > The Nature of Code


Simulating
Natural Systems
with
JavaScript

Daniel Shiffman

natureofcode.com

The Nature of Code er en fantastisk bok om programmering. Boka tar for seg simuleringer av naturlige prosesser som gravitasjon, friksjon, bevegelse i stim, vekst, nevrale nettnerk, evolusjon m.m. Den er skrevet med en entusiasme og en omtanke for leseren som jeg aldri har sett maken til i denne sjangeren.

Den er ingen nybegynnerbok, da anbefaler jeg heller «Getting Started with p5.js», men den er likevel en bok som krever lite forkunnskaper. Forfatteren er svært flink til å gjøre stoffet interessant og lettfattelig.

Boka ble utgitt i 2012 for Processing, men kommer i ny utgave i 2024 for p5.js. Bestill et fjernlån på biblioteket, kjøp den på på natureofcode.com eller les den gratis på natureofcode.com.

Følg Daniel Shiffmans videogjennomgang av alle kapitlene:
The Nature of Code 2 (p5.js)


Utvalgte emner fra boka trinn for trinn:
Vektorer, akselerasjon, gravitasjon og friksjon

Mer om p5.js:
Kurs og veiledninger


Jeg leste boka i 2020 og oversatte den gang mange av eksemplene fra Processing til p5.js. Klikk, test og endre koden:
Vær oppmerksom på at programmene kan være oppdelt i flere deler som er fordelt på mapper i editoren. På PC vises mappene ved å klikke på haken under «kjør»-pila. På mobil er det et mappesymbol. Alle filer med .js som filendelse er programmer. sketch.js er hovedprogrammet.
Example 1.3 page 39. Vector subtraction.
Example 1.4 page 41. Multiplying a vector.
Example 1.5 page 43. Vector magnitude.
Example 1.6 page 45. Normalizing a vector.
Example 1.7 page 48. Motion 101 (velocity).
Example 1.8 page 52. Motion 101 (velocity and constant acceleration).
Example 1.9 page 53. Motion 101 (velocity and random acceleration).
Example 1.10. Accelerating towards the mouse.
Example 1.11 page 59. Array of movers accelerating towards the mouse.
Example 2.1 page 73. Forces.
Example 2.2 page 77. Forces acting on manny objects.
Example 2.3 page 78. Gravity scaled by mass.
Example 2.4 page 82. Introducing friction.
Example 2.5 page 87. Fluid resistance.
Example 2.6 page 95. Attraction.
Example 2.7 page 96. Attraction with many Movers.
Example 2.8 page 99. Mutual attraction.
Example 2.8 page 99. Mutual attraction (colors).
Example 3.1 page 105. Angular motion using rotate().
Example 3.2 page 107. Forces with (arbitrary) angular motion.
Example 3.3 page 111. Pointing in the direction of motion.
Example 3.4 page 114. Polar to Cartesian.
Example 3.5 page 119. Simple Harmonic Motion.
Example 3.6, page 120. Simple Harmonic Motion II.
Example 3.7 page 121. Oscillator objects.
Example 3.7 page 121. Oscillator objects (modified: linear ocsillation).
Example 3.7 page 121. Oscillator objects (modified: constant amplitude).
Example 3.7 page 121. Oscillator objects (modified: constant velocity and amplitude)
Example 3.7 page 121. Oscillator objects (modified: size and colors).
Example 3.8 page 124. Static wave drawn as a continuous line.
Example 3.9 page 125. The Wave.
Example 3.10 page 131. Swinging pendulum.
Example 3.11 page 140. A Spring connection.
Example 4.1 page 147. A single particle.
Example 4.2 page 154. Array with particles and backwards iteration. (Not arrayList of particles with iterator…).
Example 4.3 page 156. Simple Single Particle System.
Example 4.4 page 159. System of systems.
Example 4.5 page 172. Particle system inheritance and polymorphism.
Example 4.6 page 177. Particle system with forces.
Example 6.1 page 268. Seeking a target.
Example 6.2 page 272. Arrive steering behavior.
Example 6.3 page 276. «Stay within walls» steering behavior.
Example 6.4 page NNN. Flow field following.
Example 6.5 page 293. Simple path following.
Example 6.6 page NNN. Path following.
Example 6.7 page NNN. Group behavior: Separation
Example 6.7 page NNN. Group behavior: Separation (modified: inside canvas).
Example 6.8 page NNN. Combining steering behaviors: Seek and separate.
Example 6.9 page NNN. Flocking.
Example 7.1 page NNN. Wolfram elementary cellular automata (random rulset).
Example 7.1 page NNN. Wolfram elementary cellular automata (decimlal).
Example 7.1 page NNN. Wolfram elementary cellular automata (binary rule).
Example 7.1 page NNN. Wolfram elementary cellular automata (step mouse).
Example 7.1 page NNN. Wolfram elementary cellular automata (step arrow keys).
Example 7.1 page NNN. Wolfram elementary cellular automata (end cells connect).


skolekoding.no
Stein Olav Kivle