Last active
October 18, 2015 04:47
-
-
Save koozdra/af2233a7bc372d02a909 to your computer and use it in GitHub Desktop.
Canvas Mandelbrot scratch code
This file contains 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 CANVAS_CTX = canvas.getContext('2d'); | |
var DRAW_PIXEL_ID = CANVAS_CTX.createImageData(1,1); | |
var DRAW_PIXEL_DATA = DRAW_PIXEL_ID.data; | |
function drawPixel(ctx, x, y, r, g, b, a) { | |
DRAW_PIXEL_DATA[0] = r; | |
DRAW_PIXEL_DATA[1] = g; | |
DRAW_PIXEL_DATA[2] = b; | |
DRAW_PIXEL_DATA[3] = a; | |
ctx.putImageData( DRAW_PIXEL_ID, x, y ); | |
} | |
function drawRow(ctx, y) { | |
_(range(0, ctx.width)) | |
.each(function(x) { | |
drawPixel(ctx, x, y, 0 ,0 ,0, 0); | |
}) | |
.value(); | |
} | |
function renderRows(ctx, y) { | |
if ((y || 0) < ctx.height) { | |
drawRow(ctx, y); | |
setTimeout(0, renderRows(ctx, (y || 0) + 1)); | |
} | |
} | |
renderRows(ctx); | |
// would like calls like this | |
draw(red(pixel(10,10))); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment