import controlP5.*; ControlP5 cp5; boolean isPaused = false; int simulationSpeed = 10;…
- User
import controlP5.*;
ControlP5 cp5; boolean isPaused = false; int simulationSpeed = 10;
ArrayList shaders = new ArrayList(); int currentShaderIndex = 0;
int cols, rows; int cellSize = 10; boolean[][] grid; boolean[][] nextGrid;
float camAngleX = PI / 4; float camAngleY = PI / 4; float camDistance = 500; PVector lastMouse;
void settings() { size(800, 800, P3D); }
void setup() { ortho();
cp5 = new ControlP5(this);
cp5.addToggle("isPaused") .setPosition(20, 20) .setSize(50, 20) .setLabel("Pause") .setValue(false);
cp5.addSlider("simulationSpeed") .setPosition(20, 50) .setSize(200, 20) .setRange(1, 60) .setValue(10) .setLabel("Simulation Speed");
cp5.addButton("resetGrid") .setPosition(20, 80) .setSize(80, 30) .setLabel("Reset Grid");
cp5.addButton("nextShader") .setPosition(20, 120) .setSize(80, 30) .setLabel("Next Shader");
// Load shaders PShader shaderOriginal = loadShader("cell_shader.frag", "cell_shader.vert"); PShader shaderWave = loadShader("shader_wave.frag", "cell_shader.vert"); PShader shaderNoise = loadShader("shader_noise.frag", "cell_shader.vert");
shaders.add(shaderOriginal); shaders.add(shaderWave); shaders.add(shaderNoise);
colorMode(HSB, 255);
cols = width / cellSize; rows = height / cellSize;
grid = new boolean[cols][rows]; nextGrid = new boolean[cols][rows];
resetGrid();
lastMouse = new PVector(mouseX, mouseY); }
void draw() { background(0);
// Update simulation based on speed and pause state if (!isPaused && frameCount % int(60 / simulationSpeed) == 0) { computeNextGeneration(); }
PShader currentShader = shaders.get(currentShaderIndex); currentShader.set("u_time", millis() / 1000.0); shader(currentShader);
noStroke();
pushMatrix(); translate(width / 2, height / 2, -camDistance); rotateX(camAngleX); rotateY(camAngleY); translate(-cols * cellSize / 2, -rows * cellSize / 2);
for (int x = 0; x < cols; x++) { for (int y = 0; y < rows; y++) { if (grid[x][y]) { pushMatrix(); translate(x * cellSize, y * cellSize, 0);
codefloat hue = map(y, 0, rows, 0, 255); fill(hue, 255, 255); box(cellSize); popMatrix(); } }} popMatrix();
resetShader(); }
void computeNextGeneration() { for (int x = 0; x < cols; x++) { for (int y = 0; y < rows; y++) { int neighbors = countAliveNeighbors(x, y); boolean alive = grid[x][y];
code - Assistant