Add completed pixel array testing
This commit is contained in:
15
CM2030 Graphics Programming/Week 13/13.3.1 Pixels/index.html
Normal file
15
CM2030 Graphics Programming/Week 13/13.3.1 Pixels/index.html
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>graphicsProgramming - Coursera</title>
|
||||
<script src="libraries/p5.min.js" type="text/javascript"></script>
|
||||
<script src="libraries/p5.sound.min.js" type="text/javascript"></script>
|
||||
|
||||
<script src="sketch.js" type="text/javascript"></script>
|
||||
|
||||
<style> body {padding: 0; margin: 0;} canvas {vertical-align: top;} </style>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
BIN
CM2030 Graphics Programming/Week 13/13.3.1 Pixels/libraries/.DS_Store
vendored
Normal file
BIN
CM2030 Graphics Programming/Week 13/13.3.1 Pixels/libraries/.DS_Store
vendored
Normal file
Binary file not shown.
3
CM2030 Graphics Programming/Week 13/13.3.1 Pixels/libraries/p5.min.js
vendored
Normal file
3
CM2030 Graphics Programming/Week 13/13.3.1 Pixels/libraries/p5.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
28
CM2030 Graphics Programming/Week 13/13.3.1 Pixels/libraries/p5.sound.min.js
vendored
Normal file
28
CM2030 Graphics Programming/Week 13/13.3.1 Pixels/libraries/p5.sound.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
CM2030 Graphics Programming/Week 13/13.3.1 Pixels/rockets.png
Normal file
BIN
CM2030 Graphics Programming/Week 13/13.3.1 Pixels/rockets.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 71 KiB |
32
CM2030 Graphics Programming/Week 13/13.3.1 Pixels/sketch.js
Normal file
32
CM2030 Graphics Programming/Week 13/13.3.1 Pixels/sketch.js
Normal file
@ -0,0 +1,32 @@
|
||||
let img;
|
||||
|
||||
function preload() {
|
||||
img = loadImage('rockets.png');
|
||||
}
|
||||
function setup() {
|
||||
createCanvas(640 * 2, 400);
|
||||
pixelDensity(1);
|
||||
}
|
||||
|
||||
function draw() {
|
||||
background(150);
|
||||
image(img, 0, 0);
|
||||
|
||||
// getting pixel information using get()
|
||||
let c = img.get(mouseX, mouseY);
|
||||
fill(c);
|
||||
rect(mouseX, mouseY, 50, 50);
|
||||
|
||||
// getting color values manually
|
||||
img.loadPixels(); // make the pixel array ready to be used with img.pixels[]
|
||||
let index = (img.width * mouseY + mouseX) * 4; //index of first value
|
||||
let channelRed = img.pixels[index + 0];
|
||||
let channelGrn = img.pixels[index + 1];
|
||||
let channelBlu = img.pixels[index + 2];
|
||||
let channelAlp = img.pixels[index + 3];
|
||||
|
||||
fill('rgba(' + channelRed + ',' + channelGrn + ',' + channelBlu + ',' + channelAlp + ')');
|
||||
//fill(channelRed, channelGrn, channelBlu, channelAlp);
|
||||
rect(mouseX + 50, mouseY, 50, 50);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user