Add completed webcam
This commit is contained in:
@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script src="p5.min.js"></script>
|
||||
<script src="sketch.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
3
CM2030 Graphics Programming/Week 13/13.2.13 Webcam/p5.min.js
vendored
Normal file
3
CM2030 Graphics Programming/Week 13/13.2.13 Webcam/p5.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
33
CM2030 Graphics Programming/Week 13/13.2.13 Webcam/sketch.js
Normal file
33
CM2030 Graphics Programming/Week 13/13.2.13 Webcam/sketch.js
Normal file
@ -0,0 +1,33 @@
|
||||
let video;
|
||||
let canvas2;
|
||||
let canvas1;
|
||||
let c;
|
||||
function setup() {
|
||||
canvas1 = createCanvas(640, 480);
|
||||
pixelDensity(1);
|
||||
video = createCapture(VIDEO);
|
||||
video.hide();
|
||||
canvas2 = createDiv(); canvas2.style('width', '100px'); canvas2.style('height', '100px'); canvas2.style('background-color', 'green');
|
||||
canvas2.parent(canvas1.parent());
|
||||
}
|
||||
|
||||
function draw() {
|
||||
background(150);
|
||||
|
||||
imageMode(CENTER);
|
||||
translate(width/2, height/2);
|
||||
scale(-1, 1, 1);
|
||||
image(video, 0, 0);
|
||||
|
||||
//smaller video at mouse position
|
||||
imageMode(CENTER);
|
||||
scale(1, 1, 1);
|
||||
//image(video, -mouseX + width/2, mouseY - height/2, video.width/3, video.height/3);
|
||||
|
||||
// capture pixel color at mouse position
|
||||
imageMode(CORNER);
|
||||
c = video.get(video.width - mouseX, mouseY); // need to tweak the x axis because it's been scaled with a -1 before
|
||||
canvas2.style('background-color', 'rgb(' + c[0] + ',' + c[1] + ',' + c[2] + ')');
|
||||
console.log(mouseX);
|
||||
console.log(mouseY);
|
||||
}
|
||||
Reference in New Issue
Block a user