////============================================
//// expo12.js, 05/02/09, by ralph abraham
//// place a blot
//// based upon expo17

//// GLOBAL VARS
	// to setup 2D world coords (u, v) ranges
	// init values determined by canvas size
	var wumax = 1.0; // worldu max
	var wumin = 0; // worldu min
	var wvmax = 1.0; // worldv max
	var wvmin = 0; // worldv min
	// and screen coords (x, y) ranges
	var sxmax = 320; // screenx max, use width of canvas from HTML page
	var sxmin = 0; // screenx min
	var symax = 280; // screeny max, use height of canvas from HTML page
	var symin = 0; // screeny min
	
//// MATH FUNCS
	// map screen to world coords, x --> u
	function worldu(sx) {
		var temp =  ( sx - sxmin ) / ( sxmax - sxmin );
		return wumin + ( wumax - wumin ) * temp;
	};

	// map screen to world coords, y --> v
	function worldv(sy) {
		var temp =  ( sy - symin ) / ( symax - symin );
		return wvmax - ( wvmax - wvmin ) * temp;
	};

	// map world to screen coords, u --> x
	function screenx(wu) {
		var temp =  ( wu - wumin ) / ( wumax - wumin );
		return sxmin + ( sxmax - sxmin ) * temp;
	};

	// map world to screen coords, v --> y
	function screeny(wv) {
		var temp =  ( wv - wvmin ) / ( wvmax - wvmin );
		return symax - symin - ( symax - symin ) * temp;
	};
	
//// SETUP

	// wait for the browser to load
	window.onload = function() {
	// set up background basic template
		base00(); // draw entire canvas
		//drawblot(20, 20, 10);
	};
	
    // 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);
	};


// this is for interaction
	document.onclick = function(ev) { // may need mouseup
	var xnow = ev.clientX; // may need ev.X or ev.layerX, etc
  	var ynow = ev.clientY - 50; // offset from top viewport to top canvas
	//alert ("coords: (" + xnow + ", " + ynow + ")"); // for debug
	drawblot(xnow, ynow, 10); // 10 is size of blot
	};
    
////////// END ///////////