Last active
August 29, 2015 13:57
-
-
Save vampjaz/9698068 to your computer and use it in GitHub Desktop.
Several cellular automata I invented with processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int x,y; | |
int direction; | |
int w = 500; | |
int h = 500; | |
int on = (int)color(0,0,0); //black = on | |
int off = (int)color(255,255,255); //white = off | |
void setup() { | |
size(w,h); | |
direction = 1; | |
x = (int)(w / 2); | |
y = (int)(h / 2); | |
background(255,255,255); | |
} | |
void draw() { | |
loadPixels(); | |
for (int i = 0; i < 200; i++) { | |
move(); | |
if (pixels[x+y*height] == on) { | |
pixels[x+y*height] = off; | |
left(); | |
move(); | |
right(); | |
} else { | |
pixels[x+y*height] = on; | |
right(); | |
} | |
} | |
updatePixels(); | |
} | |
void move() { | |
if (direction == 1){ | |
x--; | |
} | |
if (direction == 2){ | |
y++; | |
} | |
if (direction == 3){ | |
x++; | |
} | |
if (direction == 4){ | |
y--; | |
} | |
if (x < 0) x = height - 1; | |
if (x > width - 1) x = 0; | |
if (y < 0) y = height - 1; | |
if (y > height - 1) y = 0; | |
} | |
void right() { | |
if (direction < 4){ | |
direction++; | |
} else { | |
direction = 1; | |
} | |
} | |
void left() { | |
if (direction > 1){ | |
direction--; | |
} else{ | |
direction = 4; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int x,y; | |
int direction; | |
int w = 500; | |
int h = 500; | |
int on = (int)color(0,0,0); //black = on | |
int off = (int)color(255,255,255); //white = off | |
void setup() { | |
size(w,h); | |
direction = 1; | |
x = (int)(w / 2); | |
y = (int)(h / 2); | |
background(255,255,255); | |
} | |
void draw() { | |
loadPixels(); | |
for (int i = 0; i < 200; i++) { | |
move(); | |
if (pixels[x+y*height] == on) { | |
pixels[x+y*height] = off; | |
move(); | |
right(); | |
} else { | |
pixels[x+y*height] = on; | |
move(); | |
left(); | |
} | |
} | |
updatePixels(); | |
} | |
void move() { | |
if (direction == 1){ | |
x--; | |
} | |
if (direction == 2){ | |
y++; | |
} | |
if (direction == 3){ | |
x++; | |
} | |
if (direction == 4){ | |
y--; | |
} | |
if (x < 0) x = height - 1; | |
if (x > width - 1) x = 0; | |
if (y < 0) y = height - 1; | |
if (y > height - 1) y = 0; | |
} | |
void right() { | |
if (direction < 4){ | |
direction++; | |
} else { | |
direction = 1; | |
} | |
} | |
void left() { | |
if (direction > 1){ | |
direction--; | |
} else{ | |
direction = 4; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int x,y; | |
int direction; | |
int w = 500; | |
int h = 500; | |
int on = (int)color(0,0,0); //black = on | |
int off = (int)color(255,255,255); //white = off | |
void setup() { | |
size(w,h); | |
direction = 1; | |
x = (int)(w / 2); | |
y = (int)(h / 2); | |
background(255,255,255); | |
} | |
void draw() { | |
loadPixels(); | |
for (int i = 0; i < 200; i++) { | |
move(); | |
if (pixels[x+y*height] == on) { | |
pixels[x+y*height] = off; | |
right(); | |
} else { | |
pixels[x+y*height] = on; | |
left(); | |
move(); | |
left(); | |
} | |
} | |
updatePixels(); | |
} | |
void move() { | |
if (direction == 1){ | |
x--; | |
} | |
if (direction == 2){ | |
y++; | |
} | |
if (direction == 3){ | |
x++; | |
} | |
if (direction == 4){ | |
y--; | |
} | |
if (x < 0) x = height - 1; | |
if (x > width - 1) x = 0; | |
if (y < 0) y = height - 1; | |
if (y > height - 1) y = 0; | |
} | |
void right() { | |
if (direction < 4){ | |
direction++; | |
} else { | |
direction = 1; | |
} | |
} | |
void left() { | |
if (direction > 1){ | |
direction--; | |
} else{ | |
direction = 4; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment