Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Barnsley's Fern

Name: Anonymous 2009-06-13 17:31

Minimal Barnsley's Fern (lolwikipedia) in html and javascript:

<html><script>n=u=v=0
function i(){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>


Works on modern browsers (well, ok, works on Firefox and probably Chrome). It's also 348 bytes. Can anyone do better?

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2011-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()}

var x3 = 123456789, y3 = 362436069, z3 = 521288629, w3 = 88675123,t3=0;
function rxor(){
  t3 = x3 ^ (x3 << 11);
  x3 = y3; y3 = z3; z3 = w3;
  w3 = w3 ^ (w3 >> 19) ^ (t3 ^ (t3 >> 8));
return w3-(RW*((w3/RW)|0))
}

var arrn=Uint32Array(w*h)
while(iter100--){
n=iterations;
while(n--){
x=u;
y=v
t3 = x3 ^ (x3 << 11);
x3 = y3;
y3 = z3;
z3 = w3;
w3 = w3 ^ (w3 >> 19) ^ (t3 ^ (t3 >> 8));
r=(w3&255)>>2


if(r>13){
u=x*xyred+y*a25;
v=y*xyred-x*a25+zoom;
}else{
if(r>6){u=y*a3-x*a7;
v=(x+y)*a4+Hzoom;}else{
if(r>0){
u=x*a5-y*a4;
v=(x+y)*a4+Wzoom+Hzoom;}else{
u=0;v=y*a6}}}

arrn[(((mult*u+L))|0)+((H-mult*v)|0)*w]=green

}};

context.putImageData({width:w,height:h,data:Uint8ClampedArray(arrn.buffer)},0,0);
document.title+=Date.now()-starttime+" ms"



</script></body></html>

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List