Skip to content

This started as a travel in New York and Boston in November 2017.
The travel was realized thanks to Fuorirotta, who supported me with a crowdfunding campaign. The travel was conceived to record a series of audio-interviews on science, creativity and how they can mix to engage the public.


It started and never progressed, and ideas changed, and never progressed…


It is now an evolving research project on:

—rationality, science creativity—

Please note the previous sentence is affected by incessant processes of mutation and adaptation. Science and creativity will always be part of it, but I commit to stick to what feels to me most true and compulsory in the moment.

show code

<p>// The Nature of Code<br />// Daniel Shiffman<br />//</p>
<p>// Demonstration of Craig Reynolds' "Flocking" behavior<br />// See:<br />// Rules: Cohesion, Separation, Alignment</p>
<p>// Click mouse to add boids into the system<br />PShape boh,me;<br />Flock flock;<br />float gravity=3;<br />float mass=2;<br />int life;<br />public static float bound=90;<br />//public static float BBound=50;</p>
<p>void setup() {<br />size(900,200);<br />flock = new Flock();<br />boh = loadShape("");<br />PShape MARIO = loadShape("");<br />PShape Anonimo = loadShape("");<br />PShape Martino = loadShape("");<br />PShape Nathan = loadShape("");<br />// PShape LALLA = loadShape("");<br />PShape aldo = loadShape("");<br />PShape matto = loadShape("");<br />PShape parrot = loadShape("");<br />PShape piero = loadShape("");<br />PShape nada = loadShape("");<br />PShape cactolo = loadShape("");<br />PShape magolo = loadShape("");<br />PShape genio = loadShape("");<br />PShape next = loadShape("");<br />// PShape pollo = loadShape("");<br />PShape hoho = loadShape("");<br />PShape zorro = loadShape("");</p>
<p>me = loadShape("");<br />life=-1; // this way never goes to zero</p>
<p>// Add an initial set of boids into the system<br />flock.addBoid(new Boid(random(width),random(height), me,80,gravity,mass,life));<br />flock.addBoid(new Boid(random(width),random(height), MARIO,80,gravity,mass,life));<br />flock.addBoid(new Boid(random(width),random(height), Anonimo,80,gravity,mass,life));<br />// flock.addBoid(new Boid(random(width),random(height), Martino,80,gravity,mass,life));<br />// flock.addBoid(new Boid(random(width),random(height), Nathan,80,gravity,mass,life));<br />// flock.addBoid(new Boid(random(width),random(height), LALLA,80,gravity,mass,life));<br />// flock.addBoid(new Boid(random(width),random(height), aldo,80,gravity,mass,life));<br />// flock.addBoid(new Boid(random(width),random(height), matto,80,gravity,mass,life));<br />// flock.addBoid(new Boid(random(width),random(height), parrot,80,gravity,mass,life));<br />// flock.addBoid(new Boid(random(width),random(height), piero,80,gravity,mass,life));<br />// flock.addBoid(new Boid(random(width),random(height), nada,80,gravity,mass,life));<br />// flock.addBoid(new Boid(random(width),random(height), cactolo,80,gravity,mass,life));<br />// flock.addBoid(new Boid(random(width),random(height), magolo,80,gravity,mass,life));<br />flock.addBoid(new Boid(random(width),random(height), genio,80,gravity,mass,life));<br />// flock.addBoid(new Boid(random(width),random(height), next,80,gravity,mass,life));<br />// flock.addBoid(new Boid(random(width),random(height), pollo,80,gravity,mass,life));<br />flock.addBoid(new Boid(random(width),random(height), hoho,80,gravity,mass,life));<br />flock.addBoid(new Boid(random(width),random(height), zorro,80,gravity,mass,life));<br />for (int i = 0; i &lt; 2; i++) { Boid b = new Boid(width/2,height/2, boh,20,gravity,mass,life); flock.addBoid(b); } } void draw() { background(255); stroke(175); noFill(); rectMode(CENTER); //rect(width/2, height/2, width-bound*2, height-bound*2); //rect(width/2, height/2, width-BBound*2, height-BBound*2); PVector mouse = new PVector(mouseX, mouseY);; // Instructions fill(0); //text("Clicca per mescolare il raguDrag the mouse to generate new boids.",10,height-16); } //Add a new boid into the System void mouseDragged() { if (keyPressed == true) { life=1000; flock.addBoid(new Boid(mouseX,mouseY,boh,20,gravity,mass,life)); } } // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // @@@@@@@@@@@@@@start Boid@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // The Nature of Code // Daniel Shiffman // // Boid class // Methods for Separation, Cohesion, Alignment added class Boid { PVector position; PVector velocity; PVector acceleration; float r; float maxforce; // Maximum steering force float maxspeed; // Maximum speed @@@ posso farla anche random!! PShape boh; PVector mouse; boolean moreaway; float gravity; //gravity variable float mass; //mass variable int life; float dist; int rFig; Boid(float x, float y, PShape tboh, int trFig,float tgravity,float tmass,int tlife) { life=tlife; rFig=trFig; acceleration = new PVector(0,0); boh=tboh; gravity=tgravity; mass=tmass; velocity = new PVector(random(-1,1),random(-1,1)); position = new PVector(x,y); r = 3.0; maxspeed = 3; maxforce = 0.02; } void run(ArrayList boids, PVector tmouse) {<br />if (life!=0) {//checking if it is still alive<br />life=life-1;<br />}<br />mouse=tmouse;<br />flock(boids);</p>
<p>//checkEdges();<br />update();</p>
<p>void applyForce(PVector force) {<br />// We could add mass here if we want A = F / M<br />acceleration.add(force);<br />}</p>
<p>// We accumulate a new acceleration each time based on three rules<br />void flock(ArrayList boids) {<br />PVector sep = separate(boids); // Separation<br />PVector ali = align(boids); // Alignment<br />PVector coh = cohesion(boids); // Cohesion</p>
<p>PVector mescola = new PVector(0,0);<br />PVector mouse = new PVector(mouseX,mouseY);<br />PVector diff = PVector.sub(position,mouse);<br />if ((mousePressed== true)&amp;&amp;(keyPressed == false)&amp;&amp;(diff.mag()&gt;20) ) {<br />mescola = mix(mouseX,mouseY);<br />}</p>
<p>// Arbitrarily weight these forces<br />sep.mult(0.2);<br />ali.mult(0.1);<br />coh.mult(0.1);<br />mescola.mult(0.2);</p>
<p>// Add the force vectors to acceleration<br />applyForce(sep);<br />applyForce(ali);<br />applyForce(coh);</p>
<p>// Method to update position<br />void update() {<br />// Update velocity<br />velocity.add(acceleration);<br />// Limit speed<br />velocity.limit(maxspeed);</p>
<p>// questo lo metto qui perchè prima voglio aver calcolato la velocità x o y complessiva (che uso in boundaries)<br />PVector away = boundaries(); // check the proximity to boundaries of this boid</p>
<p>if (away!=null) {<br />//if (moreaway==false) {<br />away.mult(0.8);<br />//else {away.mult(2.5);}<br />applyForce(away);<br />// REUpdate velocity<br />velocity.add(acceleration);<br />// RELimit speed<br />velocity.limit(maxspeed);<br />}</p>
<p>position.add(velocity);<br />// Reset accelertion to 0 each cycle<br />acceleration.mult(0);<br />}</p>
<p>// A method that calculates and applies a steering force towards a target<br />// STEER = DESIRED MINUS VELOCITY<br />PVector seek(PVector target) {<br />PVector desired = PVector.sub(target,position); // A vector pointing from the position to the target<br />//@@@ steering force = desired velocity - current velocity</p>
<p>// Normalize desired and scale to maximum speed<br />desired.normalize();<br />desired.mult(maxspeed);<br />// Steering = Desired minus Velocity<br />PVector steer = PVector.sub(desired,velocity);<br />steer.limit(maxforce); // Limit to maximum steering force<br />return steer;<br />}</p>
<p>void render() {<br />// Draw a triangle rotated in the direction of velocity<br />float theta = velocity.heading2D() + radians(90);<br />fill(175);<br />stroke(0);<br />pushMatrix();<br />translate(position.x,position.y);<br />rotate(theta);<br />beginShape();<br />shape(boh, 0,0, rFig, rFig);<br />//ellipse(0,0,20, 20);</p>
<p>// vertex(0, -r*2);<br />// vertex(-r, r*2);<br />// vertex(r, r*2);<br />endShape();<br />popMatrix();<br />}</p>
<p>// Wraparound<br />//void borders() {<br />// if (position.x &lt; -r) position.x = width+r; // if (position.y &lt; -r) position.y = height+r; // if (position.x &gt; width+r) position.x = -r;<br />// if (position.y &gt; height+r) position.y = -r;<br />//}</p>
<p>// Separation<br />// Method checks for nearby boids and steers away<br />PVector separate (ArrayList boids) {<br />float desiredseparation = 25.0f;<br />PVector steer = new PVector(0,0,0);<br />int count = 0;<br />// For every boid in the system, check if it's too close<br />for (Boid other : boids) {<br />float d = PVector.dist(position,other.position);<br />// If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself)<br />if ((d &gt; 0) &amp;&amp; (d &lt; desiredseparation)) { // Calculate vector pointing away from neighbor PVector diff = PVector.sub(position,other.position); diff.normalize(); diff.div(d); // Weight by distance steer.add(diff); count++; // Keep track of how many } } // Average -- divide by how many if (count &gt; 0) {<br />steer.div((float)count);<br />}</p>
<p>// As long as the vector is greater than 0<br />if (steer.mag() &gt; 0) {<br />// Implement Reynolds: Steering = Desired - Velocity<br />steer.normalize();<br />steer.mult(maxspeed);<br />steer.sub(velocity);<br />steer.limit(maxforce);<br />}<br />return steer;<br />}</p>
<p>// Alignment<br />// For every nearby boid in the system, calculate the average velocity<br />PVector align (ArrayList boids) {<br />float neighbordist = 50;<br />PVector sum = new PVector(0,0);<br />int count = 0;<br />for (Boid other : boids) {<br />float d = PVector.dist(position,other.position);<br />if ((d &gt; 0) &amp;&amp; (d &lt; neighbordist)) { sum.add(other.velocity); count++; } } if (count &gt; 0) {<br />sum.div((float)count);<br />sum.normalize();<br />sum.mult(maxspeed);<br />PVector steer = PVector.sub(sum,velocity);<br />steer.limit(maxforce);<br />return steer;<br />} else {<br />return new PVector(0,0);<br />}<br />}</p>
<p>// Cohesion<br />// For the average position (i.e. center) of all nearby boids, calculate steering vector towards that position<br />PVector cohesion (ArrayList boids) {<br />float neighbordist = 50;<br />PVector sum = new PVector(0,0); // Start with empty vector to accumulate all positions<br />int count = 0;<br />for (Boid other : boids) {<br />float d = PVector.dist(position,other.position);<br />if ((d &gt; 0) &amp;&amp; (d &lt; neighbordist)) { sum.add(other.position); // Add position count++; } } if (count &gt; 0) {<br />sum.div(count);<br />return seek(sum); // Steer towards the position<br />} else {<br />return new PVector(0,0);<br />}<br />}</p>
<p>PVector boundaries() {</p>
<p>PVector steer = null;<br />moreaway=false;</p>
<p>PVector desired = null;</p>
<p>if (position.x &lt; bound) { desired = new PVector(maxspeed, velocity.y); } else if (position.x &gt; width -bound) {<br />desired = new PVector(-maxspeed, velocity.y);<br />}</p>
<p>if (position.y &lt; bound) { desired = new PVector(velocity.x, maxspeed); } else if (position.y &gt; height-bound) {<br />desired = new PVector(velocity.x, -maxspeed);<br />}</p>
<p>if (desired != null) {<br />desired.normalize();<br />desired.mult(maxspeed);<br />steer = PVector.sub(desired, velocity);<br />steer.limit(maxforce);<br />//applyForce(steer);<br />}<br />return(steer);<br />}</p>
<p>//math for attraction and repulsion forces<br />//tx and ty are the co-ordinates attraction/repulsion will be applied to<br />PVector mix(float tx, float ty){<br />PVector targetLoc = new PVector(tx, ty); //creating new vector for attractive/repulsive x and y values<br />PVector dir = PVector.sub(position, targetLoc); //calculate the direction between a particle and targetLoc<br />dist = dir.mag(); //calculate how far away the particle is from targetLoc<br />dir.normalize(); //convert the measurement to a unit vector</p>
<p>//calculate the strength of the force by factoring in a gravitational constant and the mass of a particle<br />//multiply by distance^2<br />float force = (gravity*mass) / (dist*dist);</p>
<p>//if the mouse is pressed, turn on repulsion by multiplying direction by 1<br />//if(mousePressed){<br />dir.mult(-1);<br />//}<br />//else multiply the direction by -1 to switch the direction the particle travels in (attraction)<br />//else{<br />// dir.mult(-1);<br />//}</p>
<p>//apply directional vector<br />//applyRepulsion(dir);<br />dir.div(mass);<br />return(dir);<br />}</p>
<p>//method to apply a force vector to the particle<br />//void applyRepulsion(PVector force){<br />//force.div(mass);<br />//acc.add(force);<br />//}<br />//<br />//void checkEdges() { if (position.x &gt; width) {<br />// position.x = width;<br />// }<br />// else if (position.x &lt; 0) { // position.x = 0; // } // if (position.y &gt; height) {<br />// position.y = height;<br />// }<br />// else if (position.y &lt; 0) { position.y = 0; // } // } } // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // @@@@@@@@@@@@@@start Flock@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // The Nature of Code // Daniel Shiffman // // Flock class // Does very little, simply manages the ArrayList of all the boids class Flock { ArrayList boids; // An ArrayList for all the boids<br />ArrayList toremove;</p>
<p>Flock() {<br />boids = new ArrayList(); // Initialize the ArrayList<br />}</p>
<p>void run(PVector tmouse) {<br />toremove=new ArrayList(0);<br />for (Boid b : boids) {<br />,tmouse);<br />if ( {<br />toremove.add(b);<br />}<br />// Passing the entire list of boids to each boid individually<br />}</p>
<p>for (Boid b : toremove) {<br />boids.remove(b);<br />}</p>
<p>void addBoid(Boid b) {<br />boids.add(b);<br />}</p>

After the campaign, I drew a few simple shapes, one for each supporter, and after the travel I drew new ones, one for each people I interviewed. I let them simmer and interact in this space, which I envision as virtual ragu’ sauce, the key ingredient for a great lasagna.