วันอาทิตย์ที่ 18 ธันวาคม พ.ศ. 2559

โค้ดวาดรูป 16 ทางพร้อมกัน

int r = 50;
int g = 50;
int b = 50;

void setup(){
 size(900, 900);
 background(0);
 translate(450,450);
 stroke(255);
 line(-450, 0, 450, 0);
 line(0, 450, 0, -450);
 line(-450, -450, 450, 450);
 line(-450, 450, 450, -450);
 rotate(radians(22.5));
 line(-550, 0, 550, 0);
 line(0, 550, 0, -550);
 line(-550, -550, 550, 550);
 line(-550, 550, 550, -550);
}

void draw(){
  int x = mouseX-450;
  int y = mouseY-450;
  translate(450,450);
  stroke(r, g, b);
  strokeWeight(5);
  if(mousePressed){
    draw_zero(x, y);
    draw_second(x, y);
  }
}

void draw_zero(int x, int y){
 point(x, y);
 point(-x, y);
 point(x, -y);
 point(-x, -y);
 point(y, x);
 point(-y, x);
 point(y, -x);
 point(-y, -x);
}

void draw_second(int x, int y){
 rotate(radians(45));
 point(x, y);
 point(-x, y);
 point(x, -y);
 point(-x, -y);
 point(y, x);
 point(-y, x);
 point(y, -x);
 point(-y, -x);
}

void mouseWheel(){
  r = int(random(50, 255));
  g = int(random(50, 255));
  b = int(random(50, 255));
  println(r);
  println(g);
  println(b);
  println();
}

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

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