I'm trying to build an engine for cellular automata (for things like Sam Hogan's Cell Machine, falling sand simulators, Conway's GoL, World Gen, etc.), but I keep running into issues with lag. The draw (the grid)::#ffd127 block (sorry for the hideous colour) is at a level I'm happy with in terms of performance, but update (the grid)::#ffd127 is taking way too long to run. According to my FPS block, I'm getting 0.38ish FPS with the update block, and about 50 without. I'm using a lot of nested loops in the logic of update, so it definitely can be optimised, but I have absolutely no idea how to go about with it.
(also, spawn [1 V] at x: (1) y: (1)::#ffd127 can be used to set cells to specific materials, if it helps see what I'm doing. (The new scriptable menu system is so useful!))
Do not repeat the same calculations for every iteration. Calculate the the "pen size" once and the step for the "change X" only once for a row, not for each cell.
I wonder if it would result in a net speedup if you turned the neighborhood into a list of nine squares, instead of a list of three rows of three squares each.
And I wonder if you could gain speed by turning the MAP blocks into compiled
blocks (right click on the MAP block and choose "compile").