PleunProcessing150928

From XPUB & Lens-Based wiki
Revision as of 11:46, 6 October 2015 by Pleun (talk | contribs) (Created page with "== // Sketch - object oriented == box b; ArrayList<box> boxes = new ArrayList<box>(); boolean record = false; void setup() { size(600, 600); b = new box(100, 100, 25,...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

// Sketch - object oriented

box b;

ArrayList<box> boxes = new ArrayList<box>();

boolean record = false;

void setup() {

 size(600, 600);
 b = new box(100, 100, 25, 25);
 int v = 255;
 //int x = 0;
 //int y = 10;
 background (0);
 for (int i = 0; i <1000; i++) {  // i++ = i + 1, i-- = i - 1 
   int x = (int)random(width-25);
   int y = (int)random(height-25);
   color c = color (v, v, v);
   v = (int)random(255);
   box b = new circle(x, y, 25, 25);
   b.setColor(c);
   b.setSpeed((int)random(5,10), (int)random(5,10));
   boxes.add(b);
 }

}

void draw () {

 //b.paint();
 for (int i = 0;i < boxes.size(); i++) {
   boxes.get(i).paint();
   boxes.get(i).move();
 }
 
 if(record) {
  saveFrame ("frames/#####.png"); 
 }
 

}

void keyPressed() {

if (key == 's') {
  record = !record;
} 

}


box

public class box {

 int x = 10;  // properties
 int y = 10;
 int w = 50;
 int h = 50;
 color c = color (255);
 
 int speedX = 0;
 int speedY = 0;
 public box () {
 }
 public box(int x, int y, int w, int h) {
   this.x = x;
   this.y = y;
   this.w = w;
   this.h = h;
 }
 void setColor(color c) {
   this.c = c;
 }
 void setSpeed (int speedX, int speedY) {
   this.speedX = speedX;
   this.speedY = speedY;
 }
 void move() {
   x = x + speedX;
   if (x > width || x<0) {
     speedX = -speedX;
   }
   y = y + speedY;
   if (y > width || y<0) {
     speedY = -speedY;
   }
 }
 void paint() {
   fill(c);
   rect(x, y, w, h);
   noStroke();
 }
 

}


circle

public class circle extends box {

 public circle() {
 }
 public circle (int x, int y, int w, int h) {
   this.x = x;
   this.y = y;
   this.h = h;
   this.w = w;
 }
 void paint() {
   fill(c);
   ellipse(x, y, w, h);
   noStroke();
 }

}