Last active
May 4, 2025 14:01
-
-
Save johnfredcee/81b09011a88c99b84e3a5f870ae46d5a to your computer and use it in GitHub Desktop.
Cell grid in p5.js
This file contains hidden or 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
var app = (function () { | |
var a2 = { | |
'make' : (x,y) => { return { 'w' : x, 'v' : Array.from({length:x*y}, () => Math.random() * 255) } }, | |
'get' : (a, x, y) => { return a.v[x+y*a.w] }, | |
'set' : (a, x, y, v) => { a.v[x+y*a.w] = v } | |
}; | |
var a; | |
return { | |
'setup' : () => { | |
createCanvas(400, 400); | |
a = a2.make(20,20) | |
}, | |
'draw' : () => { | |
background(220); | |
var x = 400.0 / 20.0; | |
var y = 400.0 / 20.0; | |
for(var i = 0; i < 20; i++) { | |
for(var j = 0; j < 20; j++) { | |
fill(a2.get(a, i, j)) | |
a2.set(a, 10,10, Math.random() * 255) | |
square(i * x, j * y, 20) | |
} | |
} | |
} | |
} | |
})(); | |
function setup() { | |
app.setup() | |
} | |
function draw() { | |
app.draw() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment