|
Author |
Topic: triangle (Read 702 times) |
|
rgovostes
|
triangle
« on: Aug 30th, 2003, 7:25pm » |
|
as my second project in processing, i was trying to implement langton's ant algorithm. however, when i ran my code it produced a right triangle which grows each iteration. unintentional, but i thought it was kinda nifty. nothing too spectacular. Code:int x = 100; int y = 100; int dir = 90; color on; color off; void setup () { size(200, 200); colorMode(RGB); noBackground(); on = color(0, 0, 0); off = color(255, 255, 255); } void loop() { color c = getPixel(x, y); if (c == on) { setPixel(x, y, off); } else { setPixel(x, y, on); } if (dir == 0) { y = max(y - 1, 0); } if (dir == 90) { x = min(x + 1, width); } if (dir == 180) { y = min(y + 1, height); } if (dir == 270) { x = max(x - 1, 0); } c = getPixel(x, y); if (c == off) { dir = (dir + 90) % 360; } else { dir = (dir - 90) % 360; } } |
| if anyone sees why it doesn't work as intended, please point it out. thanks!
|
« Last Edit: Aug 30th, 2003, 9:54pm by rgovostes » |
|
|
|
|
|