>>8
348 bytes - 13 bytes (<html> and </html>) - 1 byte (removing i and moving onload= == 334 bytes
r<14?r<1?(u=0,v=y/6):(v=x/4+y/4+(r<7?(u=x/5-y/4,1.7):(u=y/3-x/7,.4))):(u=x*.85+y/25,v=y*.85-x/25+1.6)
that is exactly the same length, but it's more efficient, so it is an improvement.
Name:
Anonymous2009-06-14 2:30
>>9
Wow, that's a hell of a conditional statement. Nice catch on moving the onload, too.
You can actually save another 8 bytes by using a conditional in place of the last if-else, too: [code]<html><script>n=u=v=0
onload=function i(){t=document.body.lastChild.getContext('2d')
t.fillStyle='green'
r=Math.random()*99
x=u,y=v
r<14?r<1?(u=0,v=y/6):(v=x/4+y/4+(r<7?(u=x/5-y/4,1.7):(u=y/3-x/7,.4))):u=x*.85+y/25,v=y*.85-x/25+1.6
t.fillRect(50*u+140,525-50*v,1,1)
if(n<2e5)n++%99?i():setTimeout(i,1)}</script><canvas height=550></html>[code]
Name:
Anonymous2009-06-14 2:38
>>10
And a further byte by doing the same for the other end-of-function if, actually, for a total of 325 or 338, depending on whether you leave the <html> tags in.
I tested in Firefox 3.5 and Chrome, IE doesn't think body.lastChild exists in the calling context and firebug keeps crashing firefox whenever I try and figure out why.
>>19
Because the IE8 script debugger also crashes, and firebug is the best in the business.
Name:
Anonymous2009-06-14 11:50
>>18
The problem with using r for your check to do the timeout is that it's, well, random. You'll probably run in to the "too much recursion" eventually, which is what the timeout is there to prevent.
Also, given that your code uses the timeout in 99 out of 100 cases, you may as well just use n++<2e5?setTimeout(i,1):1, which does always work, just very, very slowly. Your code probably meant r>1 instead of r<1, although that does have a much higher chance of running into "too much recursion".
Name:
Anonymous2009-06-14 11:54
>>22
Would setTimeout(i,0) not work better, it will behave the same except for not actually recursing but starting a new thread every time.
Name:
Anonymous2009-06-14 12:10
>>23
The speed increase by waiting 0 milliseconds instead of 1 is minimal. Given that you're only calling setTimeout every 99th time, and that you have only 2e5 calls to i, you only save 2.02 seconds. Most of the wait is from the fact that setTimeout(i,0) takes a lot more time to get called than i().
Name:
Anonymous2009-06-14 13:03
Another two bytes can be saved by rephrasing (x=u,u=x*.85+v/25,v=v*.85-x/25+1.6) to u=u*.85+v/25+0*(v=v*.85-u/25+1.6), which doesn't need the parentheses. It's now 323 bytes, and I doubt it's going to get much smaller.
type into address bar:
javascript:window.open(['data:text/html,<html><body onload="',"n=u=v=0;t=document.body.lastChild.getContext('2d');t.fillStyle='#C40';while(n++<2e5){r=Math.random()*99;r<14?r<1?(u=0,v/=6):v=u/4+v/4+(r<7?(u=u/5-v/4,1.7):(u=v/3-u/7,.4)):u=u*.85+v/25+0*(v=v*.85-u/25+1.6);t.fillRect(50*u+140,525-50*v,1,1)}",'"><canvas height=550></html>'].join(""),'a');
>>30
I think the point originally was that we could watch it being drawn and understand the chaos game, not to butcher the process with some ugly iterative crap.
Name:
Anonymous2009-06-14 14:55
>>28
The contents of the while loop can be re-written as a single comma-deliminated statement, making the brackets on the loop unnecessary.
285 bytes.
and a data:uri
data:text/html;charset=utf-8;base64,PGh0bWw+PGJvZHkgb25sb2FkPSJuPXU9dj0wO3Q9ZG9jdW1lbnQuYm9keS5sYXN0Q2hpbGQuZ2V0Q29udGV4dCgnMmQnKTt0LmZpbGxTdHlsZT0nIzA3MCc7d2hpbGUobisrPDJlNSlyPU1hdGgucmFuZG9tKCkqOTkscjwxND9yPDE/KHU9MCx2Lz02KTp2PXUvNCt2LzQrKHI8Nz8odT11LzUtdi80LDEuNyk6KHU9di8zLXUvNywuNCkpOnU9dSouODUrdi8yNSswKih2PXYqLjg1LXUvMjUrMS42KSx0LmZpbGxSZWN0KDUwKnUrMTQwLDUyNS01MCp2LDEsMSkiPjxjYW52YXMgaGVpZ2h0PTU1MD48L2h0bWw+
But it's strayed pretty far from the original, now.
Name:
FrozenVoid2009-06-14 16:32
If for example you run a site with 150kb javascript file,
you could consider to compress it manually,if server gzip isn't enough.
There even programs which would reduce size by automatically compressing redundant text: http://en.wikipedia.org/wiki/Minification_%28programming%29
This isn't the case for it, however, since the program is already very small, smaller then minimum 576 IP packet.
_________________________________________________ http://xs135.xs.to/xs135/09042/av922.jpg
orbis terrarum delenda est
Name:
FrozenVoid2009-06-14 16:41
>>38 Okay, i'm removing the html then:
249 bytes.
<body onload="n=u=v=0;while(n++<2e5)r=Math.random()*99,r<14?r<1?(u=0,v/=6):v=u/4+v/4+(r<7?(u=u/5-v/4,1.7):(u=v/3-u/7,.4)):u=u*.85+v/25+0*(v=v*.85-u/25+1.6),document.body.lastChild.getContext('2d').fillRect(50*u+140,525-50*v,1,1)"><canvas height=550>
and the data: uri
data:text/html;charset=utf-8;base64,PGJvZHkgb25sb2FkPW49dT12PTA7d2hpbGUobisrPDJlNSlyPU1hdGgucmFuZG9tKCkqOTkscjwxND9yPDE/KHU9MCx2Lz02KTp2PXUvNCt2LzQrKHI8Nz8odT11LzUtdi80LDEuNyk6KHU9di8zLXUvNywuNCkpOnU9dSouODUrdi8yNSswKih2PXYqLjg1LXUvMjUrMS42KSxkb2N1bWVudC5ib2R5Lmxhc3RDaGlsZC5nZXRDb250ZXh0KCcyZCcpLmZpbGxSZWN0KDUwKnUrMTQwLDUyNS01MCp2LDEsMSk+PGNhbnZhcyBoZWlnaHQ9NTUwPg==
242 bytes, only canvas, but you have to click on it to show the fern.
<canvas height=550 onclick=n=u=v=0;while(n++<2e5)r=Math.random()*99,r<14?r<1?(u=0,v/=6):v=u/4+v/4+(r<7?(u=u/5-v/4,1.7):(u=v/3-u/7,.4)):u=u*.85+v/25+0*(v=v*.85-u/25+1.6),document.body.lastChild.getContext('2d').fillRect(50*u+140,525-50*v,1,1)>
You should use double quotes instead of single quotes. Although they may look like they weigh more, in fact the ASCII value is less, and has fewer bits set.
Name:
Anonymous2009-06-14 18:04
>>50
That runs about 3 times as fast in Chrome than it does on Firefox trunk nightlies. Goddamn, they should just use V8. Fireshit is starting to hold the web back.
Name:
Anonymous2009-06-14 18:17
>>53
Firefox has never been a fast browser, what did you expect?
Name:
Anonymous2009-06-14 18:40
>>54
They claimed their "new" Tracemonkey JS engine was as fast or faster as V8. I have yet to see a single instance of that being true (it might be for some microbenchmark with some very tight invariant loop, but for any real program of reasonable size, it's a fucking failure)
Name:
Anonymous2009-06-14 19:30
>>55
it is faster for some microbenchmarks, but it fails horribly on anything that doesn't look like it was written by a FIOCfag.
Name:
Anonymous2009-06-14 19:45
>>56
What's the FIOCfag code writing craracteristic you're talking about? I don't think indentation can affect execution speed much
>>59
Oddly enough, sans no functional programming functional programmers seem to foot this bill better than python programmers. Hey guys, why would anyone use a conditional when they can simulate the effect by continuation passing curried $ applied arguments to a catamorphic functor who evaluates the given idempotent unary function parameter and folds it based on an independent data type with accompanying functor to ensure catamorphic conformance.
Name:
Anonymous2009-06-14 21:57
>>60
i don't think you understand the "only doing one thing per line" part...
n=0
u=0
v=0
n2e5 = n < 2e5
while(n){
n = n + 1
r = Math.random()
r = r * 99
r14 = r < 14
if(r14){
r1 = r < 1
if(r1){
u = 0
v = v / 6} // Dammit braces are so ugly and redundant.
else{
v = v / 4
u4 = u / 4
v = v + u4
r7 = r < 7
if(r7){
u = u / 5
v4 = v / 4
u = u + v4
x = 1.7} // I really hate braces.
else{
u = u / 7
v3 = v / 3
u = u + v3
x = 0.4 }
v = v + x}} // Don't you hate braces too?
else{
u = u * 0.85
v25 = v / 25
u = u + v25
v = v * 0.85
u25 = u / 25
v = v + u25
v = v + 1.6} // Ok that's it if I have to type one more closing brace, I'm going to throw a huge tantrum until someone adds support for Python scripting to Firefox.
u = u * 50
u = u + 140
v = v * 50
v = 525 - v
c = this.getContext('2d')
c.fillRect(u, v, 1, 1)
except an FIOCfag split up into about 20 smaller functions so there's no more than two levels of loop/conditional nesting in each function instead of the four levels here.
Name:
Anonymous2009-06-15 13:26
How do you pronounce``FIOCfag''?
1) Fy-ock fag
2) Fee-ock fag
3) Eff Eye Oh See fag (faggot)
4) My other car is a cudder.
Name:
Anonymous2009-06-15 13:37
>>25
can be reduced by one byte to 322 by using a different way of defining functions
Also, both "good" versions can be improved with no loss of quality by distributing the factors. Hence, a black-and-white non-animated 209 byte version:
>>73 Some hacker artists create art by writing computer code, and others, by developing hardware. Some create with existing software tools such as Adobe Photoshop or GIMP.1
____________ http://en.wikipedia.org/wiki/Hacker_artist
I will paste it into my URL bar and then it will draw a fern.
Name:
FrozenVoid2009-06-23 8:33
>>78
create "test.html" write the <canvas stuff in and open with Firefox. Not rocket science
Base64 is actually b]larger[/b] then normal text,so you don't save space by it.
Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?
If you answered "Yes" to all of the above questions, then GNAA(GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!
Name:
Anonymous2011-12-04 13:18
Bump for ancient autism
Name:
Anonymous2011-12-04 14:00
>>83
javascript: and data: URIs typed or pasted in the address bar are disabled to prevent social engineering attacks.
Name:
Anonymous2011-12-04 16:25
If Frozen spent as much time optimizing the fern code as he did with quasicrystals we would have fractals at x100 speed and all IFS code would be made obsolete.
Name:
Anonymous2011-12-04 16:37
>>92
I don't get it, how optimizing ten lines of this fern==speeds up fractals?
It doesn't look that optimizable anyway.
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-05 6:24
Initial refactoring 485ms(this is fullscreen fern)
<html><head><style>html,body{width:100%;height:100%;margin:0px;}
</style></head><body><canvas width=550 id='frozenfern'><script>
const w=window.innerWidth
const h =window.innerHeight
var canv=document.getElementById('frozenfern');
var context=canv.getContext("2d");
canv.width=w ;
canv.height=h ;
const green=0xff00ff00
context.fillStyle='green'
const iterations=100
var iter100=4000
const H=h//525;
const L=w/2;//140
const mult=50;//
const xyred=0.85
const a25=1/25;
const a4=1/4;
const a3=1/3;
const a5=1/5;
const a7=1/7;
const a6=1/6
const a20=1/20
const zoom=2.8//1.6
const Hzoom=0.4
const Wzoom=1.3
var n=u=v=r=m=c=x=y=0;
var starttime=Date.now();
//longer syntax to run on old browser
function r99(){return Math.random()*99;}
function rord(){return Math.random()>0.5?1:0;}
function addtm(str){document.title+=Date.now()-starttime+str;starttime=Date.now()}
rn=Array(iterations);rn[0]=0;var elm
for(i=1;i<7;i++)rn[i]=1;
for(i=7;i<14;i++)rn[i]=2;
for(i=14;i<(iterations+1);i++)rn[i]=3;
rn.sort(rord);
var arrn=Uint32Array(w*h)
onload=function(){
while(iter100--){
rn.sort(rord)
n=iterations;
while(n--){
x=u;
y=v
switch(rn[n]){
case 3:;
u=x*xyred+y*a25;
v=y*xyred-x*a25+zoom;
break;
case 2:;
u=y*a3-x*a7;
v=(x+y)*a4+Hzoom;break;
case 1:;
u=x*a5-y*a4;
v=(x+y)*a4+Hzoom+Wzoom;break;
case 0:;u=0;
v=y*a6;break;
default:;;break;
}
arrn[(((mult*u+L))|0)+((H-mult*v)|0)*w]=green
//context.fillRect(mult*u+L,H-mult*v,1,1)
}};
co={width:w,height:h,data:Uint8ClampedArray(arrn.buffer)};
context.putImageData(co,0,0);
addtm(" ms h:"+h+" w:"+w);
};
</script></body></html>
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-05 6:34
for comparison the 14443ms original 1/4 size fern
<html><script>n=u=v=0;start=Date.now()
function i(){if(n>=2e5)document.title+=Date.now()-start+" ms"
t=document.body.lastChild.getContext('2d')
t.fillStyle='green'
r=Math.random()*99
x=u,y=v
u=x*.85+y/25,v=y*.85-x/25+1.6
if(r<14)u=y/3-x/7,v=x/4+y/4+.4
if(r<7)u=x/5-y/4,v+=1.3
if(r<1)u=0,v=y/6
t.fillRect(50*u+140,525-50*v,1,1)
if(n<2e5)if(n++%99)i()
else setTimeout(i,1)}onload=i
</script><canvas height=550></html>
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-05 6:54
150ms not using sort
<html><head><style>html,body{width:100%;height:100%;margin:0px;}
</style></head><body><canvas width=550 id='frozenfern'><script>
const w=window.innerWidth
const h =window.innerHeight
var canv=document.getElementById('frozenfern');
var context=canv.getContext("2d");
canv.width=w ;
canv.height=h ;
const green=0xff00ff00
context.fillStyle='green'
const iterations=100
var iter100=4000
const H=h//525;
const L=w/2;//140
const mult=50;//
const xyred=0.85
const a25=1/25;
const a4=1/4;
const a3=1/3;
const a5=1/5;
const a7=1/7;
const a6=1/6
const a20=1/20
const zoom=2.8//1.6
const Hzoom=0.4
const Wzoom=1.3
var n=u=v=r=m=c=x=y=0;
var starttime=Date.now();
//longer syntax to run on old browser
function r99(){return Math.random()*99;}
function rord(){return Math.random()>0.5?1:0;}
function addtm(str){document.title+=Date.now()-starttime+str;starttime=Date.now()}
rn=Array(iterations);rn[0]=0;var elm
for(i=1;i<7;i++)rn[i]=1;
for(i=7;i<14;i++)rn[i]=2;
for(i=14;i<(iterations+1);i++)rn[i]=3;
rn.sort(rord);
var arrn=Uint32Array(w*h)
onload=function(){
while(iter100--){
n=iterations;
while(n--){
x=u;
y=v
switch(rn[(Math.random()*99)|0]){
case 3:;
u=x*xyred+y*a25;
v=y*xyred-x*a25+zoom;
break;
case 2:;
u=y*a3-x*a7;
v=(x+y)*a4+Hzoom;break;
case 1:;
u=x*a5-y*a4;
v=(x+y)*a4+Hzoom+Wzoom;break;
case 0:;u=0;
v=y*a6;break;
default:;;break;
}
arrn[(((mult*u+L))|0)+((H-mult*v)|0)*w]=green
//context.fillRect(mult*u+L,H-mult*v,1,1)
}};
co={width:w,height:h,data:Uint8ClampedArray(arrn.buffer)};
context.putImageData(co,0,0);
addtm(" ms h:"+h+" w:"+w);
};
</script></body></html>
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-05 7:55
134ms faster Random()
<html><head><style>html,body{width:100%;height:100%;margin:0px;}
</style></head><body><canvas width=550 id='frozenfern'><script>
const w=window.innerWidth
const h =window.innerHeight
var canv=document.getElementById('frozenfern');
var context=canv.getContext("2d");
canv.width=w ;
canv.height=h ;
const green=0xff00ff00
context.fillStyle='green'
const rnd=Math.random
const iterations=100
var iter100=4000//2000 too low quality
const H=h//525;
const L=w/2;//140
const mult=50;//
const xyred=0.85
const a25=1/25;
const a4=1/4;
const a3=1/3;
const a5=1/5;
const a7=1/7;
const a6=1/6
const a20=1/20
const zoom=2.8//1.6
const Hzoom=0.4
const Wzoom=1.3
const WHZoom=Wzoom+Hzoom
var n=u=v=r=m=c=x=y=0;
var starttime=Date.now();
//longer syntax to run on old browser
function r99(){return Math.random()*99;}
function rord(){return Math.random()>0.5?1:0;}
function addtm(str){document.title+=Date.now()-starttime+str;starttime=Date.now()}
}};
var co={width:w,height:h,data:Uint8ClampedArray(arrn.buffer)};
context.putImageData(co,0,0);
addtm(" ms h:"+h+" w:"+w);
};
</script></body></html>
Name:
Anonymous2011-12-05 8:09
Two years and no one has done it in Asm?
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-05 8:14
91ms slightly different fern style(tree-like): >>104 the fern code is from early 90's when IFS algorithms was invented
<html><head><style>html,body{width:100%;height:100%;margin:0px;}
</style></head><body><canvas width=550 id='frozenfern'><script>
const w=window.innerWidth
const h =window.innerHeight
var canv=document.getElementById('frozenfern');
var context=canv.getContext("2d");
canv.width=w ;
canv.height=h ;
const green=0xff00ff00
context.fillStyle='green'
const rnd=Math.random
const iterations=100
const RW=50//Random walk range
var iter100=2000//2000 too low quality
const H=h//525;
const L=w/2;//140
const mult=50;//
const xyred=0.85
const a25=1/25;
const a4=1/4;
const a3=1/3;
const a5=1/5;
const a7=1/7;
const a6=1/6
const a20=1/20
const zoom=2.8//1.6
const Hzoom=0.4
const Wzoom=1.3
const WHZoom=Wzoom+Hzoom
var n=u=v=r=m=c=x=y=0;
var starttime=Date.now();
//longer syntax to run on old browser
function r99(){return Math.random()*99;}
function rord(){return Math.random()>0.5?1:0;}
function addtm(str){document.title+=Date.now()-starttime+str;starttime=Date.now()}
}};
var co={width:w,height:h,data:Uint8ClampedArray(arrn.buffer)};
context.putImageData(co,0,0);
addtm(" ms h:"+h+" w:"+w);
};
</script></body></html>
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-05 9:13
87ms minor fix to display
<html><head><style>html,body{width:100%;height:100%;margin:0px;}
</style></head><body><canvas id='frozenfern'><script>
const w=window.innerWidth
const h =window.innerHeight
var canv=document.getElementById('frozenfern');
var context=canv.getContext("2d");
canv.width=w ;
canv.height=h ;
const green=0xff00ff00
context.fillStyle='green'
const iterations=100
const RW=50//Random walk range
var iter100=2000//Fill Quality(optimal ~4k)
const H=h//525;
const L=w/2;//140
const mult=50;//
const xyred=0.85
const a25=1/25;
const a4=1/4;
const a3=1/3;
const a5=1/5;
const a7=1/7;
const a6=1/6
const a20=1/20
const zoom=2.8//1.6
const Hzoom=0.4
const Wzoom=1.3
const WHZoom=Wzoom+Hzoom
var n=u=v=r=m=c=x=y=0;
var starttime=Date.now();
function addtm(str){document.title+=Date.now()-starttime+str;starttime=Date.now()}
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-05 9:52
83ms divide in random removed.
<html><head><style>html,body{width:100%;height:100%;margin:0px;}
</style></head><body><canvas id='frozenfern'><script>
const w=window.innerWidth
const h =window.innerHeight
var canv=document.getElementById('frozenfern');
var context=canv.getContext("2d");
canv.width=w ;
canv.height=h ;
const green=0xff00ff00
const iterations=100
const RW=50//Random walk range
var iter100=2000//Fill Quality(optimal ~4k)
const H=h//525;
const L=w/2;//140
const mult=50;//
const xyred=0.85
const a25=1/25;
const a4=1/4;
const a3=1/3;
const a5=1/5;
const a7=1/7;
const a6=1/6
const a20=1/20
const zoom=2.8//1.6
const Hzoom=0.4
const Wzoom=1.3
const WHZoom=Wzoom+Hzoom
var n=u=v=r=m=c=x=y=0;
var starttime=Date.now();
function addtm(str){document.title+=Date.now()-starttime+str;starttime=Date.now()}
>>112
So javascript random is nondeterministic? OMG THEY DID IT
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-06 5:46
>>113
For all purposes Math.random()
1.won't get any predictable sequence
2.its way slower than using xorshift PRNG
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-06 5:55
The >>1 fern is non-deterministic : it create different fern each time its loaded
the recent bunch of fern are using xorshift and are deterministic:its the same fern all time
Name:
Anonymous2011-12-06 5:56
>>113 So javascript random is nondeterministic? OMG THEY DID IT
Soooo can we use javascript to emulate Nondeterministic Touring Machines and solve NP-complete problems in polynomial time? Infinite compression, here I come!
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-06 5:58
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-06 6:31
90ms version with new leaf functions: makes the code simpler.
<html><head><style>html,body{width:100%;height:100%;margin:0px;}
</style></head><body><canvas id='frozenfern'><script>
const w=window.innerWidth
const h =window.innerHeight
const M=w>h?w:h
var canv=document.getElementById('frozenfern');
var context=canv.getContext("2d");
canv.width=w ;
canv.height=h ;
var DEBUG=1;
function d(x){if(!DEBUG)return;if(typeof(x)==Array){document.body.innerHTML+=(x.join(","))}else{document.body.innerHTML+=(x.toString())}}
const green=0xff00ff00
const blue=0xffff0000
const red=0xff0000ff
//const iterations=100
const RW=100//Random walk range
var iter100=2000//00//Fill Quality(optimal ~4k)
const H=h//525;
const L=w/2;//140
const mult=50;//
const xyred=0.85
const a25=1/25;
const a4=1/4;
const a3=1/3;
const a5=1/5;
const a7=1/7;
const a6=1/6
const a20=1/20
const zoom=2.8//1.6
const Hzoom=0.4
const Wzoom=1.3
const WHzoom=Wzoom+Hzoom
var starttime=Date.now();
function addtm(str){document.title+=Date.now()-starttime+str;starttime=Date.now()}
var rands=Uint32Array(5);
var x3 =rands[0]= 123456789, y3 = rands[1]= 362436069, z3 =rands[2]= 521288629, w3 =rands[3]= 88675123,t3=rands[4];
var n=u=v=r=m=c=x=y=0;
var j=[]
//Stem 1/100
function stem(){
x=u;y=v;u=0;v=y*a6;
arrn[L+( ((mult*u))|0 )+(H-(mult*v)|0)*w]=green;}
//xorshift rnd
function r63(){
t3 = x3 ^ (x3 << 11);
x3 = y3;
y3 = z3;
z3 = w3;
w3 = w3 ^ (w3 >> 19) ^ (t3 ^ (t3 >> 8));
return w3&63}
//LeafSet
function setleafD(){x=u;y=v;
u=x*xyred+y*a25;v=y*xyred-x*a25+zoom;
arrn[L+( ((mult*u))|0 )+(H-(mult*v)|0)*w]=green;}
function setleafW(){x=u;y=v;
u=x*a5-y*a4,v=(x+y)*a4+WHzoom;
arrn[L+( ((mult*u))|0 )+(H-(mult*v)|0)*w]=blue;}
function setleafH(){x=u;y=v;
u=y*a3-x*a7,v=(x+y)*a4+Hzoom;
arrn[L+( ((mult*u))|0 )+(H-(mult*v)|0)*w]=red;}
//Leaf
function leaf(){
var t;stem();
for(t=0;t<RW;t++){r=r63();
if((r&1)|(r&3)){setleafD();}else{if(r&7){setleafW()}else{setleafH()}}}}
//Main
var arrn=Uint32Array(w*h)
var co={width:w,height:h,data:Uint8ClampedArray(arrn.buffer)}
while(iter100--){leaf();};context.putImageData(co,0,0);
document.title+=Date.now()-starttime+" ms"
</script></body></html>
>>117 An algorithm that solves a problem in nondeterministic polynomial time can run in polynomial time or exponential time depending on the choices it makes during execution.
So if it makes the right choices, it can solve NP-complete problems in polynomial time! Just like infinite compression can compress data infinitely if it happens to be representable in a right way! Javascript is the most awesome language ever, I bet LISP can't be used for solving NP-complete problems!
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-06 8:23
>NP-complete problems
Fractal compression already exists, just its lossy. I think if IFS(non-determinstic) algorithm can be replaced by deterministic algorithm, this would simplify the problem into optimizations like preacaching/parameter reductions/simplified formulas/etc, which would make anything which uses IFS algorithms much more efficient(and compression would be deterministic too)
>>124
Hes hot. I wouldnt mind having my as pounded by her.
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-06 13:22
Unoptimized 678ms but now the fractal serves as its own PRNG(i.e. there is no external randomness or PRNG calls anymore)
<html><head><style>html,body{width:100%;height:100%;margin:0px;}
</style></head><body><canvas id='frozenfern'><script>
const w=window.innerWidth
const h =window.innerHeight
const M=w>h?w:h
var canv=document.getElementById('frozenfern');
var context=canv.getContext("2d");
canv.width=w ;
canv.height=h ;
var DEBUG=1;
function d(x){if(!DEBUG)return;if(typeof(x)==Array){document.body.innerHTML+=(x.join(","))}else{document.body.innerHTML+=(x.toString())}}
var green=0xff00ff00
var blue=0xffff0000
var red=0xff0000ff
//const iterations=100
const RW=30000//Random walk range
var iter100=100//00//Fill Quality(optimal ~4k)
const H=h//525;
const L=w/2;//140
const mult=50;//
const xyred=0.85
const a25=1/25;
const a4=1/4;
const a3=1/3;
const a5=1/5;
const a7=1/7;
const a6=1/6
const a20=1/20
const zoom=2.8//14//1.6
const Hzoom=0.4
const Wzoom=1.3
const WHzoom=Wzoom+Hzoom
var starttime=Date.now();
function addtm(str){document.title+=Date.now()-starttime+str;starttime=Date.now()}
var rands=Uint32Array(5);
var x3 =rands[0]= 123456789, y3 = rands[1]= 362436069, z3 =rands[2]= 521288629, w3 =rands[3]= 88675123,t3=rands[4];
var n=u=v=r=m=c=x=y=0;
var j=[]
//Stem 1/100
function stem(){
x=u;y=v;u=0;v=y*a6;
arrn[wtable[(mult*v)|0]]=green;}
//LeafSet
function leafD(){
u=x*xyred+y*a25;v=y*xyred-x*a25+zoom;
arrn[((mult*u)|0)+wtable[(mult*v)|0]]=green;}
function leafW(){
u=x*a5-y*a4,v=(x+y)*a4+WHzoom;
arrn[((mult*u)|0)+wtable[(mult*v)|0]]=blue;}
function leafH(){
u=y*a3-x*a7,v=(x+y)*a4+Hzoom;
arrn[((mult*u)|0)+wtable[(mult*v)|0]]=red;}
//Leaf
function leaf(){;var t;stem()
for(t=0;t<RW;t++){
x=u;y=v;//r=r63();
r=(((u*v)*0xff)&63);
(r&1)|(r&3)?leafD():r&7?leafW():leafH();
};
}
//Main
var arrn=Uint32Array(w*h)
var co={width:w,height:h,data:Uint8ClampedArray(arrn.buffer)}
while(iter100--){
/* inlined version 3ms faster:
;stem();var t;
for(t=0;t<RW;t++){
x=u;y=v;r=r63();
((r&1)|(r&3))?(u=x*xyred+y*a25,v=y*xyred-x*a25+zoom):((r&7)?(u=x*a5-y*a4,v=(x+y)*a4+WHzoom):(u=y*a3-x*a7,v=(x+y)*a4+Hzoom));
arrn[L+( ((mult*u))|0 )+(H-(mult*v)|0)*w]=green;}
*/
leaf();};//47ms
context.putImageData(co,0,0);//42ms
document.title+=Date.now()-starttime+" ms"
</script></body></html>
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-06 13:55
*should be r=(((v+u*v)*0xff)&63); to avoid u=0
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-06 13:56
this version also messes up the stem, but doesn't detract quality.
Name:
Anonymous2011-12-06 13:57
USE CODE TAG, CODE FAG
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-06 14:09
//Stem 1/100
function stem(){
x=u;y=v;u=0;v=y*a6;
arrn[wtable[(mult*v)|0]]=green;}
//LeafSet
function leafD(){
u=x*xyred+y*a25;v=y*xyred-x*a25+zoom;
arrn[((mult*u)|0)+wtable[(mult*v)|0]]=green;}
function leafW(){
u=x*a5-y*a4,v=(x+y)*a4+WHzoom;
arrn[((mult*u)|0)+wtable[(mult*v)|0]]=blue;}
function leafH(){
u=y*a3-x*a7,v=(x+y)*a4+Hzoom;
arrn[((mult*u)|0)+wtable[(mult*v)|0]]=red;}
//Leaf
function leaf(){;var t;stem()
for(t=0;t<RW;t++){
x=u;y=v;//r=r63();
r=(((v+u*v)*0xff)&63);
if(r==0)stem();
(r&1)|(r&3)?leafD():(r&7?leafW():(leafH()));
};
}
//Main
var arrn=Uint32Array(w*h)
var co={width:w,height:h,data:Uint8ClampedArray(arrn.buffer)}
while(iter100--){
/* inlined version 3ms faster:
;stem();var t;
for(t=0;t<RW;t++){
x=u;y=v;r=r63();
((r&1)|(r&3))?(u=x*xyred+y*a25,v=y*xyred-x*a25+zoom):((r&7)?(u=x*a5-y*a4,v=(x+y)*a4+WHzoom):(u=y*a3-x*a7,v=(x+y)*a4+Hzoom));
arrn[L+( ((mult*u))|0 )+(H-(mult*v)|0)*w]=green;}
*/
leaf();};//47ms
context.putImageData(co,0,0);//42ms
document.title+=Date.now()-starttime+" ms"
</script></body></html>
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-07 3:26
91ms randomizer reduced to union float:int
<html><head><style>html,body{width:100%;height:100%;margin:0px;}
</style></head><body><canvas id='frozenfern'><script>
const w=window.innerWidth
const h =window.innerHeight
const M=w>h?w:h
var canv=document.getElementById('frozenfern');
var context=canv.getContext("2d");
canv.width=w ;
canv.height=h ;
var DEBUG=1;
function d(x){if(!DEBUG)return;if(typeof(x)==Array){document.body.innerHTML+=(x.join(","))}else{document.body.innerHTML+=(x.toString())}}
const green=0xff00ff00
const blue=0xffff0000
const red=0xff0000ff
const purple=0xffff00ff
const yellow=0xff00ffff
var quality=200000
const H=h//525;
const L=w/2;//140
const mult=50;//
const xyred=0.85
const a25=1/25;
const a4=1/4;
const a3=1/3;
const a5=1/5;
const a7=1/7;
const a6=1/6
const a20=1/20
const zoom=2.8//14//1.6
const Hzoom=0.4
const Wzoom=1.3
const WHzoom=Wzoom+Hzoom
var starttime=Date.now();
function addtm(str){document.title+=Date.now()-starttime+str;starttime=Date.now()}
var x=y=0;
var farr=Float64Array(4)
var vars=Uint32Array(farr.buffer)
var wtable=Uint32Array(w);
for(var i=0;i<w;i++)wtable[i]=((H-i)*w)+L;
//Main
var color=green;
var arrn=Uint32Array(w*h)
var co={width:w,height:h,data:Uint8ClampedArray(arrn.buffer)}
while(quality--){
//u=farr[1],v=farr[0]
x=farr[1],y=farr[0];
(vars[1]&3)?(color=yellow,farr[1]=x*xyred+y*a25,farr[0]=y*xyred-x*a25+zoom):((vars[1]&7)?(color=red,farr[1]=x*a5-y*a4,farr[0]=(x+y)*a4+WHzoom):(color=blue,farr[1]=y*a3-x*a7,farr[0]=(x+y)*a4+Hzoom));
if((vars[0]&0xff)==0)farr[1]=0,farr[0]=y*a6,color=green;
arrn[ ( ((mult*farr[1]))|0)+wtable[(mult*farr[0])|0]]=color};
context.putImageData(co,0,0);//42ms
document.title+=Date.now()-starttime+" ms"
</script></body></html>
Name:
Anonymous2011-12-07 10:02
To the OP: Because most browsers clamp the minimum setTimeout/setInterval delay value to 10ms, even if you use a lower value, the upper bound is 100 timer-based function calls per second, which directly translates to a maximum of 100 pixels per second. If you were to fill multiple pixels in one call of i(), you could increase runtime speed.