mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Minor changes to examples, more code color tweaks for 2b8
This commit is contained in:
@@ -15,8 +15,7 @@ int sx, sy;
|
||||
float density = 0.5;
|
||||
int[][][] world;
|
||||
|
||||
void setup()
|
||||
{
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
frameRate(12);
|
||||
sx = width;
|
||||
@@ -31,8 +30,7 @@ void setup()
|
||||
}
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
void draw() {
|
||||
background(0);
|
||||
|
||||
// Drawing and update cycle
|
||||
@@ -40,13 +38,11 @@ void draw()
|
||||
for (int y = 0; y < sy; y=y+1) {
|
||||
//if (world[x][y][1] == 1)
|
||||
// Change recommended by The.Lucky.Mutt
|
||||
if ((world[x][y][1] == 1) || (world[x][y][1] == 0 && world[x][y][0] == 1))
|
||||
{
|
||||
if ((world[x][y][1] == 1) || (world[x][y][1] == 0 && world[x][y][0] == 1)) {
|
||||
world[x][y][0] = 1;
|
||||
set(x, y, #FFFFFF);
|
||||
}
|
||||
if (world[x][y][1] == -1)
|
||||
{
|
||||
if (world[x][y][1] == -1) {
|
||||
world[x][y][0] = 0;
|
||||
}
|
||||
world[x][y][1] = 0;
|
||||
@@ -56,12 +52,10 @@ void draw()
|
||||
for (int x = 0; x < sx; x=x+1) {
|
||||
for (int y = 0; y < sy; y=y+1) {
|
||||
int count = neighbors(x, y);
|
||||
if (count == 3 && world[x][y][0] == 0)
|
||||
{
|
||||
if (count == 3 && world[x][y][0] == 0) {
|
||||
world[x][y][1] = 1;
|
||||
}
|
||||
if ((count < 2 || count > 3) && world[x][y][0] == 1)
|
||||
{
|
||||
if ((count < 2 || count > 3) && world[x][y][0] == 1) {
|
||||
world[x][y][1] = -1;
|
||||
}
|
||||
}
|
||||
@@ -69,8 +63,7 @@ void draw()
|
||||
}
|
||||
|
||||
// Count the number of adjacent cells 'on'
|
||||
int neighbors(int x, int y)
|
||||
{
|
||||
int neighbors(int x, int y) {
|
||||
return world[(x + 1) % sx][y][0] +
|
||||
world[x][(y + 1) % sy][0] +
|
||||
world[(x + sx - 1) % sx][y][0] +
|
||||
|
||||
@@ -18,25 +18,26 @@ color spore_color;
|
||||
int runs_per_loop = 10000;
|
||||
color black = color(0, 0, 0);
|
||||
|
||||
void setup()
|
||||
{
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
frameRate(24);
|
||||
clearscr();
|
||||
reset();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
clearScreen();
|
||||
w = new World();
|
||||
spore_color = color(172, 255, 128);
|
||||
seed();
|
||||
}
|
||||
|
||||
void seed()
|
||||
{
|
||||
void seed() {
|
||||
// Add cells at random places
|
||||
for (int i = 0; i < maxcells; i++)
|
||||
{
|
||||
int cX = (int)random(width);
|
||||
int cY = (int)random(height);
|
||||
if (w.getpix(cX, cY) == black)
|
||||
{
|
||||
if (w.getpix(cX, cY) == black) {
|
||||
w.setpix(cX, cY, spore_color);
|
||||
cells[numcells] = new Cell(cX, cY);
|
||||
numcells++;
|
||||
@@ -44,8 +45,7 @@ void seed()
|
||||
}
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
void draw() {
|
||||
// Run cells in random order
|
||||
for (int i = 0; i < runs_per_loop; i++) {
|
||||
int selected = min((int)random(numcells), numcells - 1);
|
||||
@@ -53,23 +53,19 @@ void draw()
|
||||
}
|
||||
}
|
||||
|
||||
void clearscr()
|
||||
{
|
||||
void clearScreen() {
|
||||
background(0);
|
||||
}
|
||||
|
||||
class Cell
|
||||
{
|
||||
class Cell {
|
||||
int x, y;
|
||||
Cell(int xin, int yin)
|
||||
{
|
||||
Cell(int xin, int yin) {
|
||||
x = xin;
|
||||
y = yin;
|
||||
}
|
||||
|
||||
// Perform action based on surroundings
|
||||
void run()
|
||||
{
|
||||
void run() {
|
||||
// Fix cell coordinates
|
||||
while(x < 0) {
|
||||
x+=width;
|
||||
@@ -106,8 +102,8 @@ class Cell
|
||||
// The World class simply provides two functions, get and set, which access the
|
||||
// display in the same way as getPixel and setPixel. The only difference is that
|
||||
// the World class's get and set do screen wraparound ("toroidal coordinates").
|
||||
class World
|
||||
{
|
||||
class World {
|
||||
|
||||
void setpix(int x, int y, int c) {
|
||||
while(x < 0) x+=width;
|
||||
while(x > width - 1) x-=width;
|
||||
@@ -125,9 +121,8 @@ class World
|
||||
}
|
||||
}
|
||||
|
||||
void mousePressed()
|
||||
{
|
||||
void mousePressed() {
|
||||
numcells = 0;
|
||||
setup();
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,11 @@ void setup()
|
||||
{
|
||||
size(640, 360);
|
||||
frameRate(24);
|
||||
clearscr();
|
||||
reset();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
clearScreen();
|
||||
w = new World();
|
||||
spore1 = color(128, 172, 255);
|
||||
spore2 = color(64, 128, 255);
|
||||
@@ -54,8 +58,7 @@ void seed()
|
||||
}
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
void draw() {
|
||||
// Run cells in random order
|
||||
for (int i = 0; i < runs_per_loop; i++) {
|
||||
int selected = min((int)random(numcells), numcells - 1);
|
||||
@@ -63,26 +66,19 @@ void draw()
|
||||
}
|
||||
}
|
||||
|
||||
void clearscr()
|
||||
{
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
set(x, y, color(0));
|
||||
}
|
||||
}
|
||||
void clearScreen() {
|
||||
background(0);
|
||||
}
|
||||
|
||||
class Cell
|
||||
{
|
||||
class Cell {
|
||||
int x, y;
|
||||
Cell(int xin, int yin)
|
||||
{
|
||||
Cell(int xin, int yin) {
|
||||
x = xin;
|
||||
y = yin;
|
||||
}
|
||||
|
||||
// Perform action based on surroundings
|
||||
void run()
|
||||
{
|
||||
void run() {
|
||||
// Fix cell coordinates
|
||||
while(x < 0) {
|
||||
x+=width;
|
||||
@@ -148,8 +144,8 @@ class Cell
|
||||
// The World class simply provides two functions, get and set, which access the
|
||||
// display in the same way as getPixel and setPixel. The only difference is that
|
||||
// the World class's get and set do screen wraparound ("toroidal coordinates").
|
||||
class World
|
||||
{
|
||||
class World {
|
||||
|
||||
void setpix(int x, int y, int c) {
|
||||
while(x < 0) x+=width;
|
||||
while(x > width - 1) x-=width;
|
||||
@@ -167,8 +163,7 @@ class World
|
||||
}
|
||||
}
|
||||
|
||||
void mousePressed()
|
||||
{
|
||||
setup();
|
||||
void mousePressed() {
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user