Skip to content

Instantly share code, notes, and snippets.

@christianmeichtry
Created November 23, 2010 10:09
Show Gist options
  • Save christianmeichtry/711556 to your computer and use it in GitHub Desktop.
Save christianmeichtry/711556 to your computer and use it in GitHub Desktop.
Mandelbrot Worker
function doYLine(screenX, xMax, yMax)
{
computedLine = new String ;
computedLine = screenX ;
xZoom = xMax/1000.0/.5 ;
yZoom = yMax/1000.0/.5 ;
xThingy = screenX/xMax ;
xOffset = xZoom/4 ;
yOffset = yZoom/4 ;
for (screenY=0 ; screenY < yMax ; screenY++) {
x0 = xZoom*xThingy-1 - xOffset ;
y0 = yZoom*screenY/yMax-1 - yOffset ;
x = 0
y = 0
iteration = 0
max_iteration = 50
while ( (x*x + y*y <= (2*2)) && (iteration < max_iteration) )
{
xtemp = x*x - y*y + x0
y = 2*x*y + y0
x = xtemp
iteration = iteration + 1
}
if (iteration == max_iteration) {
computedLine += " rgb(0,0,0)"
}
else {
computedLine += " rgb(" + parseInt((iteration/max_iteration)*255+30) + ",10,10)" ;
}
}
return computedLine;
}
onmessage = function(event) {
m = event.data.split(" ") ;
line = doYLine(parseInt(m[0]), parseInt(m[1]), parseInt(m[2])) ;
postMessage(line) ;
} ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment