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

Lab 2 : Task#5 - draw() is called without setup() [Order]



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

void setup()
{
  c_range_low=0;
  c_range_high=255;
  c_range=c_range_high-c_range_low;
  c_mean=(c_range_low+c_range_high)/2;
  c=c_mean;
  size(500,500);
  frameRate(60);
  py=height-30;
  noStroke();
}

void draw()
{
  background(255-c);
  for(int i=0; i<520; i=i+20)
  {
    draw_circle_py(i,py);
    draw_circle_py(i,py-50);
    draw_circle_py(i,py-100);
    draw_circle_py(i,py-150);
    draw_circle_py(i,py-200);
    draw_circle_py(i,py-250);
    draw_circle_py(i,py-300);
    draw_circle_py(i,py-350);
    draw_circle_py(i,py-400);
    draw_circle_py(i,py-450);
    draw_circle_py(i,py-500);
   
    draw_circle_px(i,py);
    draw_circle_px(i,py-50);
    draw_circle_px(i,py-100);
    draw_circle_px(i,py-150);
    draw_circle_px(i,py-200);
    draw_circle_px(i,py-250);
    draw_circle_px(i,py-300);
    draw_circle_px(i,py-350);
    draw_circle_px(i,py-400);
    draw_circle_px(i,py-450);
    draw_circle_px(i,py-500);
  }
  py=py+1;
  if(py>=height+20){py=height-30;}
  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_py(int px,float py)
{
  float w,h;
  float r;
  r=15; //set radius
  c_change=10; //set colour change per frame
  w=r*2;
  h=r*2;
  fill(c);
  ellipse(px,py,w,h);
}

void draw_circle_px(int py,float px)
{
  float w,h;
  float r;
  r=15; //set radius
  c_change=10; //set colour change per frame
  w=r*2;
  h=r*2;
  fill(c);
  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;}
}

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

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