2012年10月2日 星期二


void setup()
{
size(500,400);
background(255,255,255);
fill(255,0,0);
rect(0,0,50,50);
fill(255,100,0);
rect(0,50,50,50);
fill(255,255,0);
rect(0,100,50,50);
fill(0,255,0);
rect(0,150,50,50);
fill(0,0,255);
rect(0,200,50,50);
fill(255,0,255);
rect(0,250,50,50);
fill(255,255,255);
rect(450,0,50,50);
fill(255,255,255);
ellipse(475, 25, 2,2);
fill(255);
rect(450,50,50,50);
ellipse(475, 75, 6, 6);
stroke(255,0,0);
strokeWeight(1);
}

int ray=5;
void draw()
{
  if(mouseX < 50 && mouseY<50 && mousePressed)
  {
  stroke(255,0,0);
  }
  else if(mouseX < 50 && mouseY<100 && mousePressed)
  {
  stroke(255,100,0);
  }
  else if(mouseX < 50 && mouseY<150 && mousePressed)
  {
  stroke(255,255,0);
  }
  else if(mouseX < 50 && mouseY<200 && mousePressed)
  {
  stroke(0,255,0);
  }
  else if(mouseX < 50 && mouseY<250 && mousePressed)
  {
  stroke(0,0,255);
  }
  else if(mouseX < 50 && mouseY<300 && mousePressed)
  {
  stroke(255,0,255);
  }
   else if(mousePressed && mouseX>450 && mouseY<50)
  {
    strokeWeight(++ray);
  }
  else if(mousePressed && mouseX>450 && mouseY<1000)
  {
    strokeWeight(--ray);
    if(ray<2)ray=2;
  }
  else if(mousePressed)  line(mouseX, mouseY, pmouseX, pmouseY);
}

好玩自製的小畫家,不需要太艱難的程式碼就可以有成就感。

1 則留言: