Tuesday, 25 September 2012

Arrays Tutorial

// I am learning how to use an array. This is what we did in class:


int dotcount=10;

float [] xn = new float [dotcount];
float [] yn = new float [dotcount];
float [] s = new float [dotcount];


void setup (){
 size (500,500);
 
  int i=0;
  while (i < dotcount){
 
  xn[i] = random (500);
  yn[i] = random (500);
  s[i] = random (40);
  i=i+1;
  }
}
  void draw(){
    background(255,255,255);
   
    int i=0;
  while (i < dotcount){
 
    ellipse (xn[i],yn[i],60,10);
    xn[i]=xn[i]+s[i];
    if (xn[i]>500){
      xn[i]=0;
    }
   
  i=i+1;
 
  }

}

Also these videos are helpful for learning code:
http://www.youtube.com/playlist?list=PL632BB8C3F7E776BA&feature=plcp&fb_source=message

No comments:

Post a Comment