Wig­g­l­e­r Class

by Harrison McEwen

This sketch has a wiggle object which is an ellipse wiggling down the screen. I put this object into an array and duplicated it 60 times

  • Show Code
/** @peep sketch */
 
//NUMBER OF OBJECTS
 
int count = 60;
 
///DECLARING ALL ARRAY VARIABLES
wiggle[] Wiggle;
 
float[] xRan;
float[] rRan;
float[] yPos;
float[] counter;
 
void setup() {
 
size(500,500);
colorMode(HSB);
strokeWeight(0.5);
 
Wiggle = new wiggle[count];
 
xRan = new float[count];
rRan = new float[count];
yPos = new float[count];
 
counter = new float[count];
 
//INTIALISING ALL ARRAYS
 for (int i = 0; i < count; i++) {
 
//RANDOMISING VALUES FOR THE WIGGLE OBJECT
 
   yPos[i] = random(-600,0);
   rRan[i] = random(20,50);
   xRan[i] = random(width-width/10*9,width/10*9);
   counter[i] = random(60);
 
   Wiggle[i] = new wiggle(xRan[i], yPos[i] -100, rRan[i], counter[i]);
 
 }
 
}
 
void draw() {
 
  //CLASS FUNCTIONS
  for(int i = 0; i < count; i++) {
 
   Wiggle[i].display();
   Wiggle[i].move();
 
  }
 
  //BACKGROUND FADER
  noStroke();
  fill(255,0,255,10);
  rect(0,0,width,height);
 
}
 
//WIGGLE CLASS
 
class wiggle {
 
 float xPos;
 float yPos;
 float r;
 float counter;
 
 wiggle(float xPos_, float yPos_, float r_, float counter_) {
 
  xPos = xPos_;
  yPos = yPos_;
  r = r_;
  counter = counter_;
 
 }
 
 void display() {
 
   stroke(counter/2,255,255,255);
   noFill();
   ellipse(xPos, yPos, r,r);
 
 }
 
 void move () {
 
  //SOURCE OF WIGGLING
  float wiggler = sin(counter*0.1)*2;
  xPos = xPos + wiggler;
 
  //POSITION RESET
 
  if (yPos < height+100) {
  yPos+=0.5;
  counter+=0.2;
 
  } else { 
   counter = 0;
  yPos = -50;
 
  if(xPos > width) {
   xPos = width/2-200; 
  }
 
  }
 
 }
 
}

Comments

Nobody has said anything yet.