Friday, June 7, 2013

Placing pixels in the window

Moving onto the first rendering - since we're going to work with and change our coordinates often, let's declare and initialize an x and a y.  Loop through and "put a pixel" (fillRect that is 1x1) in our current x and y locations, then add 1 to y to move down the screen.  Once we've reached the bottom, add a number to the x coordinate to start all over again.  Continue until x is still within the width of the screen.



Replace the following code with the drawShapes(){} method found at my template.



function drawShapes() { var x = 10, y = 0, lineColor = randomColor(); do { c.fillRect(x, y, 1, 1); c.fillStyle = lineColor; y++; if (y > h) { x += 10; y = 0; lineColor=randomColor(); } } while (x < w); }

No comments: