So I have been doing some veeery simple stuff lately
- I adapted the “Game of Life” that is in the examples of Processing.org
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Size of cells
int cellSize = 13;
// How likely for a cell to be alive at start (in percentage)
float probabilityOfAliveAtStart = 5.5;
// Variables for timer
float interval = 1;
float lastRecordedTime = 0;
// Colors for active/inactive cells
float R = 10;
float G = 100;
float B = 20;
float A = 1;
color alive = color(R, G, B, A);
color dead = color(0);
//Function y + F_lashing
float F = 1;
float Y = 0;
// Array of cells
int[][] cells;
// Buffer to record the state of the cells and use this while changing the others in the interactions
int[][] cellsBuffer;
// Pause
boolean pause = false;
void setup() {
size (1670, 880);
// Instantiate arrays
cells = new int[width/cellSize][height/cellSize];
cellsBuffer = new int[width/cellSize][height/cellSize];
// This stroke will draw the background grid
// stroke(48);
// Initialization of cells
for (int x=0; x<width/cellSize; x++) {
for (int y=0; y<height/cellSize; y++) {
float state = random (100);
if (state > probabilityOfAliveAtStart) {
state = 0;
}
else {
state = 1;
}
cells[x][y] = int(state); // Save state of each cell
}
}
background(0,0,0); // Fill in black in case cells don’t cover all the windows
}
void draw() {
R = R + 2.5;
G = G + 5;
B = B + 3.5;
Y += 1;
A = 45pow(2,(-Y+100)Y/1000);
F = YYY/250-Y*Y/20;
alive = color(R, G, B, A);
dead = color(Y/1.1,Y/1.1,Y/1.1);
background(Y/1.01,Y/1.01,Y/1.01,1/1000000000000000000L);
//Draw grid
int alivecells = 0; //contador
for (int x=1; x< (width/cellSize) -1 ; x++) {
for (int y=1; y< (height/cellSize) -1; y++) {
if ((cells[x][y]==1) && ((cells[x+1][y]==1 && cells[x-1][y]==1)||(cells[x][y+1]==1 && cells[x][y-1]==1)) /if they are in a verticall or horizontall line/ && (random(0,F)>=1)) {
fill(alive); // If alive
alivecells += 1 ;
}
else {
fill(dead); // If dead
}
rect (xcellSize, ycellSize, cellSize, cellSize);
}
}
//DRAW 2
println("cells: "+alivecells);
println("millis: "+millis());
println("A: "+A);
// Iterate if timer ticks
if (millis()-lastRecordedTime>interval) {
if (!pause) {
iteration();
lastRecordedTime = millis();
}
}
// Create new cells manually on pause
if (pause && mousePressed) {
// Map and avoid out of bound errors
int xCellOver = int(map(mouseX, 0, width, 0, width/cellSize));
xCellOver = constrain(xCellOver, 0, width/cellSize-1);
int yCellOver = int(map(mouseY, 0, height, 0, height/cellSize));
yCellOver = constrain(yCellOver, 0, height/cellSize-1);
// Check against cells in buffer
if (cellsBuffer[xCellOver][yCellOver]==1) { // Cell is alive
cells[xCellOver][yCellOver]=0; // Kill
fill(dead); // Fill with kill color
}
else { // Cell is dead
cells[xCellOver][yCellOver]=1; // Make alive
fill(alive); // Fill alive color
}
}
else if (pause && !mousePressed) { // And then save to buffer once mouse goes up
// Save cells to buffer (so we opeate with one array keeping the other intact)
for (int x=0; x<width/cellSize; x++) {
for (int y=0; y<height/cellSize; y++) {
cellsBuffer[x][y] = cells[x][y];
}
}
}
}
void iteration() { // When the clock ticks
// Save cells to buffer (so we opeate with one array keeping the other intact)
for (int x=0; x<width/cellSize; x++) {
for (int y=0; y<height/cellSize; y++) {
cellsBuffer[x][y] = cells[x][y];
}
}
// Visit each cell:
for (int x=0; x<width/cellSize; x++) {
for (int y=0; y<height/cellSize; y++) {
// And visit all the neighbours of each cell
int neighbours = 0; // We’ll count the neighbours
for (int xx=x-1; xx<=x+1;xx++) {
for (int yy=y-1; yy<=y+1;yy++) {
if (((xx>=0)&&(xx<width/cellSize))&&((yy>=0)&&(yy<height/cellSize))) { // Make sure you are not out of bounds
if (!((xx==x)&&(yy==y))) { // Make sure to to check against self
if (cellsBuffer[xx][yy]==1){
neighbours ++; // Check alive neighbours and count them
}
} // End of if
} // End of if
} // End of yy loop
} //End of xx loop
// We’ve checked the neigbours: apply rules!
if (cellsBuffer[x][y]==1) { // The cell is alive: kill it if necessary
if (!(neighbours == 1 || neighbours == 2 || neighbours == 3 || neighbours == 4 || neighbours == 5)) {
cells[x][y] = 0; // survive bla bla bla
}
}
else { // The cell is dead: make it live if necessary
if (neighbours == 3) {
cells[x][y] = 1; // birth if bla bla bla
}
} // End of if
} // End of y loop
} // End of x loop
} // End of function
void keyPressed() {
if (key==‘r’ || key == ‘R’) {
R = 10;
G = 100;
B = 20;
A = 1;
F = 1;
Y = 0;
// Restart: reinitialization of cells
for (int x=0; x<width/cellSize; x++) {
for (int y=0; y<height/cellSize; y++) {
float state = random (100);
if (state > probabilityOfAliveAtStart) {
state = 0;
}
else {
state = 1;
}
cells[x][y] = int(state); // Save state of each cell
}
}
}
if (key==’ ') { // On/off of pause
pause = !pause;
}
if (key==‘c’ || key == ‘C’) { // Clear all
for (int x=0; x<width/cellSize; x++) {
for (int y=0; y<height/cellSize; y++) {
cells[x][y] = 0; // Save all to zero
}
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////The aim was to imitate a little the style of Ghost In The Shell (1995), more precisely the intro. With all those green paterns emergeing of the BIOS and solidifying the OS, to finally turn into the wite color screen that is more alike of the already booted computers.
Basically, a few color equations that change the RGB values and the alfa following polynomic curves. And I added a little of random flashing, just for fun.