Snowflake
HTML
<div>
<canvas id='canv' width="256" height="256"></canvas>
<div id="seed"></div>
</div>
CSS
canvas{
border: solid 1px black;
}
JavaScript
DoFlake(document.getElementById('canv'));
function DoFlake(canvas){
var width = canvas.width;
var height = canvas.height;
var ctx = canvas.getContext('2d');
var thing = document.createElement('canvas'); thing.width = 128; thing.height = 32;
var thingctx = thing.getContext('2d');
var date = new Date();
document.getElementById('seed').innerHTML = date.getTime();
var noise = new ImprovedPerlin(date.getTime()); //Test Seed: 5588446, Interesting Seed: 1388681756253
var wDiv = 1/64;
var y = 7/32;
var z = 2/11;
for(var x = 0; x < 128; x++){
var h = 32 - (x * 32 / 128);
h += 16 * noise.Noise(4 * x * wDiv, y, z);
h += 8 * noise.Noise(8 * x * wDiv, y, z);
h += 4 * noise.Noise(16 * x * wDiv, y, z);
h += 2 * noise.Noise(32 * x * wDiv, y, z);
h += 1 * noise.Noise(64 * x * wDiv, y, z);
thingctx.fillRect(x, 0, 1, h);
}
ctx.translate(128,128);
var angle = Math.PI / 3;
for(var i = 0; i < 6; i++){
ctx.rotate(angle);
ctx.drawImage(thing, 0, 0);
ctx.scale(1, -1)
ctx.drawImage(thing, 0, 0);
ctx.scale(1, -1);
}
}
function Rand(seed){
this.m_w = seed;
this.m_z = 987654321;
this.mask = 0xffffffff;
this.Next = function (){
this.m_z = (36969 * (this.m_z & 65535) + (this.m_z >> 16)) & this.mask;
this.m_w = (18000 * (this.m_w & 65535) + (this.m_w >> 16)) & this.mask;
var result = ((this.m_z << 16) + this.m_w) & this.mask;
result /= 4294967296;
return result + 0.5;
};
}
function ImprovedPerlin(seed){
this.p = new Array(512);
this.rand = new Rand(seed);
for(var i = 0; i < 256; i++)
this.p[i] = i;
for(var i = 255; i > 0; i--){
var j =...