วันจันทร์ที่ 25 สิงหาคม พ.ศ. 2557

Lab 2 : Task#4 - draw() is called after setup() [Disorder]



int c;
int c_change,c_range,c_range_low,c_range_high,c_mean;
int count=0;

void setup()
{
  c_range_low=55;
  c_range_high=200;
  c_range=c_range_high-c_range_low;
  c_mean=(c_range_low+c_range_high)/2;
  c=c_mean;
  size(500,500);
  background(c_mean);
  frameRate(60);
}

void draw()
{
  for(int i=0; i<width*height/5000; i=i+1){draw_circle();}
  if(count<c_range){change_colour_P();}
  if(count>=c_range){change_colour_N();}
  if(count<c_range*2){count=count+c_change;}
  if(count>=c_range*2){count=0;}
}

void draw_circle()
{
  float px,py,w,h;
  float r;
  r=20; //set radius
  c_change=50; //set colour change per frame
  w=r*2;
  h=r*2;
  fill(c,50);
  px=random(0,width);
  py=random(0,height);
  ellipse(px,py,w,h);
}

void change_colour_P()
{
c=c+c_change;
if(c>c_range_high){c=c_range_high;}
}

void change_colour_N()
{
c=c-c_change;
if(c<c_range_low){c=c_range_low;}
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น