Apply wind force on this code

Here is the code and Id apply wind force instead of friction,

int NrDisks = 120;
float Gravity   = 0.03;
float Fri  = -0.9;
Disk[] disks    = new Disk[NrDisks];



void setup() {
  size(700, 700);
  for (int i = 0; i < NrDisks; i++) {
    disks [i] = new Disk(-random(height ), -random(width)/2, random(20, 20), i, disks );
  }
  noStroke();
  fill(255, 204);
}




void draw() {
  background(0);
  for (Disk disk : disks ) {
    disk.move();
    disk.display();
  }
}

class Disk {
  float r = random(255);
  float g = random(255);
  float b = random(255);

  float posx, posy;
  float diameter;
  float velx = -2;
  float vely = 2;
  int id;
  Disk[] others;


  Disk(float xin, float yin, float d, int idin, Disk[] oin) {
    posx = xin;
    posy = yin;
    diameter = d;
    id = idin;
    others = oin;
  } 


  void move() {
    vely += Gravity;
    posx -= velx;
    posy += vely;


    if (diameter/2 > width) {
      posx = width - diameter/2;
      velx *=  Fri;
    } else if (posy - diameter > height) {
      posy = height - diameter;
      vely *=  Fri;
    }
  }

  void display() {
    fill(r, g, b);
    ellipse(posx, posy, diameter, diameter);
  }
}

Same for all the posts you made, but you have to format the code with </> button in the editor :slight_smile:

thanks, I just made the edit, is is it working now ? :grinning:

yes but the indentation is gone :frowning: you can ctrl+t (or command+t) in the the Processing IDE (not forum) to format the code and then paste it here again.

Regarding the question, do you have “equations” of how a wind force is calculated?

1 Like

I just edited as requested, hope it works :face_with_head_bandage:

Hello,

Google search this:

image

:)

1 Like