Flowers

by path411

JavaScript

// I can't get jsfiddle to let me import an external script (yeah I fail), anyway, this is david bau's drop in seed algorithim for Math.random(). http://davidbau.com/encode/seedrandom.js

(function(a,b,c,d,e,f){function k(a){var b,c=a.length,e=this,f=0,g=e.i=e.j=0,h=e.S=[];for(c||(a=[c++]);d>f;)h[f]=f++;for(f=0;d>f;f++)h[f]=h[g=j&g+a[f%c]+(b=h[f])],h[g]=b;(e.g=function(a){for(var b,c=0,f=e.i,g=e.j,h=e.S;a--;)b=h[f=j&f+1],c=c*d+h[j&(h[f]=h[g=j&g+b])+(h[g]=b)];return e.i=f,e.j=g,c})(d)}function l(a,b){var e,c=[],d=(typeof a)[0];if(b&&"o"==d)for(e in a)if(a.hasOwnProperty(e))try{c.push(l(a[e],b-1))}catch(f){}return c.length?c:"s"==d?a:a+"\0"}function m(a,b){for(var d,c=a+"",e=0;c.length>e;)b[j&e]=j&(d^=19*b[j&e])+c.charCodeAt(e++);return o(b)}function n(c){try{return a.crypto.getRandomValues(c=new Uint8Array(d)),o(c)}catch(e){return[+new Date,a.document,a.history,a.navigator,a.screen,o(b)]}}function o(a){return String.fromCharCode.apply(0,a)}var g=c.pow(d,e),h=c.pow(2,f),i=2*h,j=d-1;c.seedrandom=function(a,f){var j=[],p=m(l(f?[a,o(b)]:0 in arguments?a:n(),3),j),q=new k(j);return m(o(q.S),b),c.random=function(){for(var a=q.g(e),b=g,c=0;h>a;)a=(a+c)*d,b*=d,c=q.g(1);for(;a>=i;)a/=2,b/=2,c>>>=1;return(a+c)/b},p},m(c.random(),b)})(this,[],Math,256,6,52);


    var canvas = document.getElementById('canvas');
	var ctx = canvas.getContext('2d');



	function Random(min, max) {
		return (Math.random() * ((max - min) + 1)) + min | 0;
	}

	function DistanceBetween(a, b) {
        return Math.sqrt(a.X - b.X + a.Y - b.Y);
    }
    
    function IsRectColliding(a, b) {
        return ! ( a.X + a.Width  < b.X || a.X > b.X + b.Width ||
                   a.Y + a.Height < b.Y || a.Y > b.Y + b.Height );
    }

	function DrawRect(x, y, w, h) {
		ctx.strokeRect(x|0, y|0, w|0, h|0);
	}
    function FillRect(x, y, w, h) {
		ctx.fillRect(x, y, w, h);
	}

    function Flower(x, y) {
        this.X = x;
        this.Y = y;
    }

     
    function Field(width, height) {
        this.Width...