-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcanvas.js
More file actions
36 lines (28 loc) · 1.08 KB
/
canvas.js
File metadata and controls
36 lines (28 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var canvas = document.getElementById("masterpiece");
console.log("What is canvas?", canvas);
var renderingContext = canvas.getContext("2d");
console.log("What is rendering context?", renderingContext);
renderingContext.fillStyle = "orchid";
/* Get RECT */
renderingContext.fillRect(0, 0, 1, 1);
renderingContext.fillRect(1, 1, 1, 1);
renderingContext.fillRect(7, 7, 1, 1);
/* Start of horrific "smiley face" */
renderingContext.fillStyle = "yellow";
renderingContext.fillRect(2,2,1,1);
renderingContext.fillRect(4,2,1,1);
renderingContext.fillStyle = "red";
renderingContext.fillRect(1,4,1,1);
renderingContext.fillRect(2,5,3,1);
renderingContext.fillRect(5,4,1,1);
/* End of horrific "smiley face" */
/* Last item in rgba is alpha */
renderingContext.fillStyle = "rgba(0,255,0,0.5)";
renderingContext.fillRect(1, 1, 1, 1);
var imageBuffer = renderingContext.getImageData(0, 0, 8, 8);
/* 4 will make all the red for 2nd pixel*/
imageBuffer.data[4] = 255;
/* 7 for ALL the opacity for 2nd pixel*/
imageBuffer.data[7] = 255;
/* Draw the stuff */
renderingContext.putImageData(imageBuffer, 0, 0);