BLOG POST: P3D





Marble[] ball= new Marble[10];


void setup() {
  size(600, 600, P3D);
  background(0);
  for (int x = 0; x < ball.length; x +=1) {
    ball[x] = new Marble();
  }
}

void draw() {


  background(0);
  for (int x = 0; x < ball.length; x ++) {
    ball[x].update();
    ball[x].display();
  }

  // saveFrame("output/gol_####.png");
}




////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////

class Marble {
  float r, g, b; ///mapping color
  float angle;////rotate
  float z;     ///z axis


  Marble() {
  }
  void update() {
    angle+=1;   

    noFill();

    translate(width/2, height/2);  //make it in center

    rotateZ(radians(angle));///rotate
    // rotateX(radians(angle));///rotate
    // rotateY(radians(angle));///rotate
  }

  void display() {
    for ( int x = 1; x <50; x +=30) { ////create more spheres

      pushMatrix();
      translate(100, 100);
      float r = map(mouseX, 0, width, 0, 255);
      float g = map(mouseY, height, 0, 0, 100);

      float b = map(x, 0, width, 255, 0);

      stroke(r+x, g+x, b, 50); //changing color when moving mouse


      strokeWeight(10);

      sphere(x);

      popMatrix();
    }
  }
 
}

Comments

Popular Posts