To make a great lasagna, the first thing is the ragù sauce.

show code

// Great credit to Daniel and Craig, I hope you don't mind of my mis-use of your code!

// The Nature of Code
// Daniel Shiffman

// Demonstration of Craig Reynolds' "Flocking" behavior
// See:
// Rules: Cohesion, Separation, Alignment

// Click mouse to add boids into the system
PShape boh,me;
Flock flock;
float gravity=3;
float mass=2;
int life;
public static  float bound=90;
//public static  float  BBound=50;

void setup() {
  flock = new Flock();

     me = loadShape("");
    boh = loadShape("");
    PShape MARIO = loadShape("");
    PShape Anonimo = loadShape("");
    PShape Martino = loadShape("");
    PShape Nathan = loadShape("");
    //PShape LALLA = loadShape("");
    PShape aldo = loadShape("");
    PShape matto = loadShape("");
    PShape parrot = loadShape("");
    PShape piero = loadShape("");
    PShape nada = loadShape("");
    PShape cactolo = loadShape("");
    // PShape magolo = loadShape("");
    // PShape genio = loadShape("");
    //  PShape next = loadShape("");
    // PShape pollo = loadShape("");
    // PShape hoho = loadShape("");
    PShape tulipano = loadShape("");
    PShape dragolo = loadShape("");


  life=-1; // this way never goes to zero

  // Add an initial set of boids into the system
  flock.addBoid(new Boid(random(width),random(height), me,80,gravity,mass,life));
  flock.addBoid(new Boid(random(width),random(height), MARIO,80,gravity,mass,life));
  flock.addBoid(new Boid(random(width),random(height), Anonimo,80,gravity,mass,life));
  flock.addBoid(new Boid(random(width),random(height), Martino,80,gravity,mass,life));
  flock.addBoid(new Boid(random(width),random(height), Nathan,80,gravity,mass,life));
  //flock.addBoid(new Boid(random(width),random(height), LALLA,80,gravity,mass,life));
  flock.addBoid(new Boid(random(width),random(height), aldo,80,gravity,mass,life));
  flock.addBoid(new Boid(random(width),random(height), matto,80,gravity,mass,life));
  //flock.addBoid(new Boid(random(width),random(height), parrot,80,gravity,mass,life));
  flock.addBoid(new Boid(random(width),random(height), piero,80,gravity,mass,life));
  flock.addBoid(new Boid(random(width),random(height), nada,80,gravity,mass,life));
  flock.addBoid(new Boid(random(width),random(height), cactolo,80,gravity,mass,life));
  // flock.addBoid(new Boid(random(width),random(height), magolo,80,gravity,mass,life));
  // flock.addBoid(new Boid(random(width),random(height), genio,80,gravity,mass,life));
  //  flock.addBoid(new Boid(random(width),random(height), next,80,gravity,mass,life));
  // flock.addBoid(new Boid(random(width),random(height), pollo,80,gravity,mass,life));
  // flock.addBoid(new Boid(random(width),random(height), hoho,80,gravity,mass,life));
  flock.addBoid(new Boid(random(width),random(height), tulipano,80,gravity,mass,life));
  //flock.addBoid(new Boid(random(width),random(height), dragolo,80,gravity,mass,life));

  //for (int i = 0; i < 2; i++) {
  //  Boid b = new Boid(width/2,height/2, boh,20,gravity,mass,life);
  //  flock.addBoid(b);

void draw() {
    //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
  //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)  {
  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) {
    acceleration = new PVector(0,0);
    velocity = new PVector(random(-1,1),random(-1,1));
    position = new PVector(x,y);
    r = 3.0;
    maxspeed = 3;
    maxforce = 0.05;

  void run(ArrayList<Boid> boids, PVector tmouse) {
    if (life!=0) {//checking if it is still alive

  void applyForce(PVector force) {
    // We could add mass here if we want A = F / M

  // We accumulate a new acceleration each time based on three rules
  void flock(ArrayList<Boid> boids) {
    PVector sep = separate(boids);   // Separation
    PVector ali = align(boids);      // Alignment
    PVector coh = cohesion(boids);   // Cohesion
    PVector mescola = new PVector(0,0);
    PVector mouse = new PVector(mouseX,mouseY);
    PVector diff = PVector.sub(position,mouse);
    if ((mousePressed== true)&&(keyPressed == false)&&(diff.mag()>20) ) {  
      mescola = mix(mouseX,mouseY);

    // Arbitrarily weight these forces

    // Add the force vectors to acceleration

  // Method to update position
  void update() {
    // Update velocity
    // Limit speed
    //   questo lo metto qui perchè  prima voglio aver calcolato la velocità x o y  complessiva (che uso in boundaries)
    PVector away = boundaries();   // check the proximity to boundaries of this boid

    if (away!=null) {
    //if (moreaway==false)  {
    //else {away.mult(2.5);}
        // REUpdate velocity
    // RELimit speed
    // Reset accelertion to 0 each cycle

  // A method that calculates and applies a steering force towards a target
  PVector seek(PVector target) {
    PVector desired = PVector.sub(target,position);  // A vector pointing from the position to the target
      //@@@ steering force = desired velocity - current velocity
      // Normalize desired and scale to maximum speed
    // Steering = Desired minus Velocity
    PVector steer = PVector.sub(desired,velocity);
    steer.limit(maxforce);  // Limit to maximum steering force
    return steer;
  void render() {
    // Draw a triangle rotated in the direction of velocity
    float theta = velocity.heading2D() + radians(90);
    shape(boh, 0,0, rFig, rFig);
    //ellipse(0,0,20, 20);

//    vertex(0, -r*2);
//    vertex(-r, r*2);
//    vertex(r, r*2);

  // Wraparound
  //void borders() {
  //  if (position.x < -r) position.x = width+r;
  //  if (position.y < -r) position.y = height+r;
  //  if (position.x > width+r) position.x = -r;
  //  if (position.y > height+r) position.y = -r;

  // Separation
  // Method checks for nearby boids and steers away
  PVector separate (ArrayList<Boid> boids) {
    float desiredseparation = 25.0f;
    PVector steer = new PVector(0,0,0);
    int count = 0;
    // For every boid in the system, check if it's too close
    for (Boid other : boids) {
      float d = PVector.dist(position,other.position);
      // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself)
      if ((d > 0) && (d < desiredseparation)) {
        // Calculate vector pointing away from neighbor
        PVector diff = PVector.sub(position,other.position);
        diff.div(d);        // Weight by distance
        count++;            // Keep track of how many
    // Average -- divide by how many
    if (count > 0) {

    // As long as the vector is greater than 0
    if (steer.mag() > 0) {
      // Implement Reynolds: Steering = Desired - Velocity
    return steer;

  // Alignment
  // For every nearby boid in the system, calculate the average velocity
  PVector align (ArrayList<Boid> boids) {
    float neighbordist = 50;
    PVector sum = new PVector(0,0);
    int count = 0;
    for (Boid other : boids) {
      float d = PVector.dist(position,other.position);
      if ((d > 0) && (d < neighbordist)) {
    if (count > 0) {
      PVector steer = PVector.sub(sum,velocity);
      return steer;
    } else {
      return new PVector(0,0);

  // Cohesion
  // For the average position (i.e. center) of all nearby boids, calculate steering vector towards that position
  PVector cohesion (ArrayList<Boid> boids) {
    float neighbordist = 50;
    PVector sum = new PVector(0,0);   // Start with empty vector to accumulate all positions
    int count = 0;
    for (Boid other : boids) {
      float d = PVector.dist(position,other.position);
      if ((d > 0) && (d < neighbordist)) {
        sum.add(other.position); // Add position
    if (count > 0) {
      return seek(sum);  // Steer towards the position
    } else {
      return new PVector(0,0);
  PVector boundaries() {

  PVector steer = null;

   PVector desired = null;

    if (position.x < bound) {
      desired = new PVector(maxspeed, velocity.y);
    else if (position.x > width -bound) {
      desired = new PVector(-maxspeed, velocity.y);

    if (position.y < bound) {
      desired = new PVector(velocity.x, maxspeed);
    else if (position.y > height-bound) {
      desired = new PVector(velocity.x, -maxspeed);

    if (desired != null) {
      steer = PVector.sub(desired, velocity);
    //math for attraction and repulsion forces
  //tx and ty are the co-ordinates attraction/repulsion will be applied to
  PVector mix(float tx, float ty){
    PVector targetLoc = new PVector(tx, ty);  //creating new vector for attractive/repulsive x and y values
    PVector dir = PVector.sub(position, targetLoc);  //calculate the direction between a particle and targetLoc
    dist = dir.mag();  //calculate how far away the particle is from targetLoc
    dir.normalize();  //convert the measurement to a unit vector
    //calculate the strength of the force by factoring in a gravitational constant and the mass of a particle
    //multiply by distance^2
    float force = (gravity*mass) / (dist*dist);
    //if the mouse is pressed, turn on repulsion by multiplying direction by 1
    //else multiply the direction by -1 to switch the direction the particle travels in (attraction)
    //  dir.mult(-1);
    //apply directional vector
    //method to apply a force vector to the particle
  //void applyRepulsion(PVector force){
  //void checkEdges() { if (position.x > width) { 
  //  position.x = width;
  //  } 
  //  else if (position.x < 0) { 
  //    position.x = 0;
  //  }
  //    if (position.y > height) { 
  //      position.y = height;
  //    } 
  //    else if (position.y < 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<Boid> boids; // An ArrayList for all the boids
  ArrayList<Boid> toremove;

  Flock() {
    boids = new ArrayList<Boid>(); // Initialize the ArrayList

  void run(PVector tmouse) {
    toremove=new ArrayList<Boid>(0);
    for (Boid b : boids) {,tmouse);
        if ( {
  // Passing the entire list of boids to each boid individually
    for (Boid b : toremove) {

  void addBoid(Boid b) {


Click to stir the ragu’, key pressed+drag the mouse for more ingredients!

Essentially this is it  

  • A travel to New York and Boston for 10 days, planned for the beginning of November, 2017!
  • Here, I will chat with original researchers and creative minds to discover more about the most recent cross-pollinations between science and the arts. I’m excited to learn if, how and why science can produce widely enjoyable experiences.

My questions, always too many     

  1. What do scientific and artistic creative processes have in common?
  2. Can scientific concepts and results be at the same time rigorous and appealing?
  3. Research activities that involve also citizens, termed as citizen science, have already been proposed and organized. Can they produce significant and reliable results?
  4. If 2. is yes, is then 3. more likely yes as well?

So far, before the travel    

  • The proposal of this travel was awarded with a special mention by the association Fuorirotta and supported with a crowdfunding campaign. Thanks to many generous donors 810 euros were collected , and these will help me realize it.
  • For each of the donors, I am creating a simple shape that will keep simmering quietly in the ragù and interacting with the others. Very much like these shapes, all donors and participants will be allowed to interact. Me too I’m an ingredient, waiting for you to join me…  

During the travel     

  • Visit some organizations and academic institutions that are very prolific in artistic or scientific research. A few examples:

SciArt Center, in many ways fosters collaborations between artists and scientists.

MIT Media Lab, the most famous academic institution in this field, is a monument to creativity.

Sprout & co. offers citizens of all ages new interactions with science.

Boslab works to make access to science and biotechnologies more open to the community.

  • Meet scientists and artists in person, inside their offices, ateliers, or simply sat down in a coffee shop. I’ll start friendly , curious to learn more about their passion and their creative processes.
  • Produce recordings of the dialogs. I strongly believe that sharing contents freely is a great way to enhance a wider discussion with people that are curious to these themes but physically distant

After the travel  

  • Re-elaborate the audio material and upload it regularly, as episodes of a podcast  .
  • As a collaboration with artists met during my travel and Galleria Moitre, the showcase Ristorante Belvedere will host tech-art installations in public spaces in Turin
    Like dishes in a restaurant, inside this showcase will be served artistic works, more or less directly inspired by scientific data and concepts collected during my travel. With Ristorante Belvedere I am setting the goal to trigger a reflection, or sequence, even short, of thoughts, able to attract observer’s attention on a science-related subject.
  • A simple scientific experiment with a format (you won’t be bored!) will engage the people met in the travel as well as those who supported me.

Before, during and after     

  • Build a network of connections to foster future scientific and artistic projects. New ragù sauce for new lasagnas!

Ok, I got it. But who are you??

Do you want to contribute to   ?

  • More than just a crowdfunding, aims to become a crowdsourcing project. If the theme somehow intrigues you or if you have any advice, please write me without overthinking it!
Find me!Tweet about this on TwitterShare on LinkedInShare on Google+