////============================================
//// expo14.js, 05/02/09, by ralph abraham
//// dorband map, hardwired (with two JS files)
//// based upon expo13

//// GLOBAL VARS for dorband map, hard wired
	var c = 0.64; // control parameeter
	// init point, world coords
	// upper left corner of unit square of the u-v plane
	var u0 = 0.3; // init u
	var v0 = 0.8; // init v 
	// hardwired init point, screen coords
	var x0 = screenx(u0);
	var y0 = screeny(v0);


//// MATH FUNCS world (u, v) --> screen (x, y)

	function screenx(wu) {
		return 320 * wu;
	};
	
	function screeny(wv) {
		return 280 - 280 * wv;
	};

//// SETUP

	// wait for the browser to load
	window.onload = function() {
	// set up background basic template
		base00(); // draw entire canvas
		drawblot(x0, y0, 10); // 10 is size of blot
	};
	
    // setup single white canvas
	function base00()  {
		var canvas = document.getElementById("canvas"); // only one canvas
		var ctx = canvas.getContext("2d");
		// setup whole rectangle (x0, y0, width, height)
		ctx.clearRect(0, 0, 320, 280);
 		ctx.fillStyle = "black"; //  bg color
 		ctx.fillRect (0, 0, 320, 280);
	};
	
	// draw a blot
	function drawblot(x, y, w) {
		var canvas = document.getElementById("canvas"); // only one canvas
		var ctx = canvas.getContext("2d");
		//ctx.clearRect(x, y, w, w);
 		ctx.fillStyle = "yellow"; //  colored rect
 		ctx.fillRect (x, y, w, w);
	};

//// here is the dorband map
	function dorbandu(u, v) {
		return (1 - c) * u + 4 * c * v * (1 - v);
	};

	function dorbandv(u, v) {
		return (1 - c) * v + 4 * c * u * (1 - u);
	};

//// declare and init vars for iteration
  	var unow = u0;
  	var vnow = v0;
  	var unext = (1 - c) * unow; // temp version of dorband map
  	var vnext = (1 - c) * vnow;
  	var xnext = screenx(unext);
  	var ynext = screeny(vnext);
  	
// this is for interaction
	document.onclick = function(ev) { // to step the map
  		unext = dorbandu(unow, vnow); // apply the dorband map
  		vnext = dorbandv(unow, vnow);
  		xnext = screenx(unext); // get screen coords
  		ynext = screeny(vnext);
		drawblot(xnext, ynext, 2); // draw next point
		unow = unext; // now step the map
		vnow = vnext;
	};
    
////////// END ///////////