Javascript
Canvas
HomeWork
- Create two functions one that accepts 4 arguments that pertain to the css attributes(element, backgroundColor, width, height) and 3 other arguments of your choice. Then append these two the dom.
- try to finish the random Color function.
- http://jsforcats.com/
Summary
Below is a sample HTML page with a canvas element that will draw a rectangle.
<body>
<canvas id='myCanvas' width='400' height='400'></canvas>
<script>
var canvas = document.getElementById('myCanvas');
var ctx = canvas.getContext('2d');
ctx.fillRect(0, 200, 20, 10);
</script>
</body>
</html>
Discussion
When you begin drawing an item, remember that you need to beginPath(x, y);
and then ctx.fill();
finish filling in the drawing. Any code you want to use to draw should go inbetween these functions.
var canvas = document.getElementById('myCanvas');
var ctx = canvas.getContext('2d');
ctx.beginPath(0, 0);
// draw some other paths and such
// then end it
ctx.fill();
Examples
Here is how you draw a circle
//ctx.arc(xposition, yposition, radius, 0, Math.PI*2, true);
//if you don't know what radius means, just know that a bigger
//radius will make a bigger circle, and 50 is a good starting point
ctx.arc(75,75,50,0,Math.PI*2,true);
References
Your references may be placed here. Please place them in an unordered list and add a quick summary of each.