Created
October 18, 2015 15:45
-
-
Save koozdra/ad929307d95bd8ccb4ea to your computer and use it in GitHub Desktop.
old mandelbrot 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
<html> | |
<head> | |
<script type="text/javascript" src="../lib/jqueryui/js/jquery-1.7.1.min.js"></script> | |
<script type="text/javascript" src="../lib/drawer.js"></script> | |
</head> | |
<body> | |
<canvas width="336" height="105" id="draw" style="border: 1px solid black; float: left;" tabindex="1"></canvas> | |
<button onclick="draw.save_image();">make an image</button> | |
<button onclick="draw.width(draw.width()*10); draw.height(draw.height()*10); scale /= 10; draw.mouse.click(mouse_pan); render();">larger</button> | |
<div style="float: left;" id="info"></div> | |
<script> | |
// small/large spiral | |
// -0.74935, 0.04144000000000001 (0.0000010000000000000002) | |
// spirals with distorted set | |
// -0.7717823079496, -0.10689838911220001 (1.0000000000000002e-14} | |
// rows | |
// -1.7639227940189999, 0.028134704939000003 (1.0000000000000002e-13} | |
// spirals | |
// {x:0.26919368, y:0.00440581, z:1.0000000000000003e-9} | |
// zoom out here for an interesting chasm | |
// {x:-1.1877101739700002, y:-0.3029609403500001, z:1.0000000000000002e-12} | |
// cool structure | |
// {x:-1.48589857151573, y:-0.037198686342249994, z:1e-15} | |
// hexagon spirals | |
// {x:0.3561462792405099, y:0.6408677999910202, z:1e-15} | |
// extending plumes | |
// {x:-1.3733359580000002, y:0.08466688300000001, z:1.0000000000000003e-10} | |
// complex spirals | |
// {x:-1.408526718265, y:0.13605210074900004, z:1.0000000000000002e-13} | |
// symmetric plumes | |
// {x:-1.406512035, y:-9.999999990648713e-10, z:1.0000000000000003e-10} | |
// rip | |
//{x:-1.9694192445999996, y:6.603999999999934e-7, z:1.0000000000000002e-12} | |
// square chaotic area | |
//{x:0.30690218671392006, y:-0.022192699740670004, z:1e-15} | |
// octal | |
// {x:-1.474509614817456, y:-2.2984695102041912e-7, z:1e-15} | |
var draw = new Draw($('#draw')[0]); | |
draw.width(); | |
var scale = 0.1; | |
var shift = $p(0,0); | |
// var c = $cp(0.1155989,0.7639405); | |
// | |
// var z = $cp(0,0); | |
// | |
// draw.times(100, function(){ | |
// z = z.power(2).add(c); | |
// console.log(z.r,z.i); | |
// }); | |
// var offx = 0; | |
// var offy = 0; | |
var offx = 0; | |
var offy = 0; | |
function score (p, timeout){ | |
var i = 0; | |
var zx = p.x; | |
var zy = p.y; | |
while (zx*zx + zy*zy < 4 && i < timeout){ | |
var tx = zx*zx - zy*zy + p.x + offx; | |
var ty = 2*zx*zy + p.y + offy; | |
zx = tx; | |
zy = ty; | |
i++; | |
} | |
// while (zx*zx + zy*zy < 4 && i < timeout){ | |
// | |
// var tx = zx * zx * zx - 3 * zx * zy * zy + p.x + offx; | |
// var ty = 3 * zx * zx * zy - zy * zy * zy + p.y + offy; | |
// | |
// zx = tx; | |
// zy = ty; | |
// | |
// i++; | |
// } | |
return i; | |
} | |
function render(){ | |
draw.clear_all(); | |
// draw.each_point(function(p){ | |
draw.render.in_rows(function(p){ | |
//draw.render.center_out(function(p){ | |
var timeout = 10000; | |
// var colors = ['red','orange','yellow','green','blue','indigo','violet']; | |
//var colors = ['black','white']; | |
//var colors = [[0,0,0],[255,255,255]]; | |
// var colors = [new Color(0,0,0),new Color(255,255,255)]; | |
// var colors = [draw.named_color('red'), | |
// draw.named_color('orange'), | |
// draw.named_color('yellow'), | |
// draw.named_color('green'), | |
// draw.named_color('blue'), | |
// draw.named_color('indigo'), | |
// draw.named_color('violet') | |
// ]; | |
var colors = [new Color(0,0,0),new Color(255,255,255)]; | |
var s = score(p.scale(scale).shift(shift),timeout); | |
var steps = 23; // really good | |
if (s < timeout){ | |
var i = Math.floor(s / steps) % colors.length; | |
var step = s % steps; | |
draw.color(colors[i].flow(colors[(i+1)%colors.length], step/steps).rgb()); | |
//draw.color(colors[i % colors.length]) | |
//draw.color(colors[s % colors.length]); | |
//draw.color('rgba(0,0,255,' + (s/(timeout)) + ')'); | |
// var d = Math.floor(255 * ((s % 70)/70)); | |
//var d = Math.floor(255 * ((s % 10)/10)); | |
//var d = Math.floor(Math.abs(Math.abs((((255/100) * s)%200)-255)-255)); | |
// draw.color('rgb(' + d + ',' + d + ',' + d + ')'); | |
} | |
else{ | |
draw.color('black'); | |
} | |
draw.point(p); | |
}); | |
} | |
// function render(wtl, wbr){ | |
// | |
// draw.clear_all(); | |
// | |
// var step = draw.scale(); | |
// | |
// var timeout = 100; | |
// | |
// var colors = ['red','orange','yellow','green','blue','indigo','violet']; | |
// //var colors = ['black','white']; | |
// | |
// | |
// draw.points_in_rectangle(wtl, wbr, step, function(x,y){ | |
// | |
// | |
// var s = score(x,y,timeout); | |
// | |
// if (s < timeout){ | |
// draw.color(colors[s % colors.length]); | |
// } | |
// else{ | |
// draw.color('black'); | |
// | |
// } | |
// | |
// draw.point($p(x,y)); | |
// | |
// }); | |
// } | |
/* | |
var mouse_p = $p(0,0); | |
draw.mouse.move(function(p){ | |
draw.clear_all(); | |
var c = $cp(p.x,p.y); | |
var z = c; | |
draw.times(5000, function(){ | |
//draw.point($p(z.r, z.i)); | |
var t = $p(z.r,z.i); | |
z = z.power(2).add(c); | |
draw.line($p(z.r, z.i),t); | |
}); | |
mouse_p = p; | |
}); | |
draw.keyboard.down = function(){ | |
mouse_p.y += 1; | |
console.log('test'); | |
}; | |
*/ | |
draw.mouse.move(function(p){ | |
//$('#info').html(p.x + ", " + p.y + " (" + score(p.x,p.y,1000) + "}"); | |
// offx = p.x; | |
// offy = p.y | |
}); | |
// draw.scale(0.01); | |
// var wtl = $p(-2,2); | |
// var wbr = $p(2,-2); | |
// var wtl = $p(-((draw.width()/2) * draw.scale()),((draw.width()/2) * draw.scale())); | |
// var wbr = $p(((draw.width()/2) * draw.scale()),-((draw.width()/2) * draw.scale())); | |
// var wtl = draw.screen.tl(); | |
// var wbr = draw.screen.br(); | |
// | |
// draw.mouse.click(function(p){ | |
// | |
// draw.color('black'); | |
// draw.screen.shift(p.x,p.y); | |
// | |
// console.log(draw._shift_x); | |
// | |
// render(draw.screen.tl(), draw.screen.br()); | |
// }); | |
//render(wtl, wbr); | |
render(); | |
// | |
// draw.mouse.move(function(p){ | |
// var ww = Math.abs(wbr.x - wtl.x); | |
// var wh = Math.abs(wtl.y - wbr.y); | |
// | |
// console.log((ww/draw.width()) * p.x, (wh/draw.height()) * p.y); | |
// | |
// | |
// | |
// }); | |
// draw.scale(0.10); | |
// | |
// draw.mouse.click(function(p){ | |
// | |
// draw.scale(draw.scale()/2); | |
// | |
// render(); | |
// }); | |
// | |
function mouse_zoom_scale (p){ | |
shift = p.scale(scale).add(shift); | |
scale /= 5; | |
$('#info').html('{x:' + shift.x + ", y:" + shift.y + ", z:" + scale + "}"); | |
render(); | |
} | |
function mouse_pan(p){ | |
shift = p.scale(scale).add(shift); | |
$('#info').html('{x:' + shift.x + ", y:" + shift.y + ", z:" + scale + "}"); | |
render(); | |
} | |
draw.mouse.click(mouse_zoom_scale); | |
</script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment