Can you interpret this particle code for me?

edited April 2018 in Questions about Code

Hello Processing Community,I have used this particle case, but there are a few sentences about abs(), sqrt() can't read, can you help me understand this?

    float circleSize = 400;
    float radius = circleSize/2;
    int period = 5; //speed
    float x = 0;
    float particleY;
    float amplitude;
    float sineEl;

    int randomPart[] = new int[100];
    int partSize[] = new int[100];


    void setup() {
      size(600, 600);
      for (int i = 0; i < randomPart.length; i++) {
        randomPart[i] = int(random(100, 500));
        partSize[i] = int(random(2, 11));
      }
    }

    void draw() {
      background(0);
      x += 0.01;

      for (int yRand = 0; yRand < randomPart.length; yRand++) {

        particleY = randomPart[yRand];

        float sine = sin((3*PI*x)/period + randomPart[yRand]);//this 
        amplitude = sqrt(sq(radius) - sq(abs(height/2 - particleY))); // and this
        sineEl = width/2 + sine * amplitude;//and this i don't konw

        float particleSize = partSize[yRand];
        //rotation
        pushMatrix();
        translate(width/2, height/2);
        translate(-width/2, -height/2);
        stroke(255);
        noStroke();
        fill(255);
        ellipse(sineEl, particleY, particleSize, particleSize);
        println(sineEl, particleY, particleSize, particleSize);
        popMatrix();
      }

      noFill();
      stroke(0);
    }

particlesize

Tagged:

Answers

Sign In or Register to comment.