xxxxxxxxxx
98
let easing = 0.05;
let cnv;
let dx;
let dy;
let cap;
function preload() {
}
function setup() {
createCanvas(360, 360);
background(255);
cap=createCapture(VIDEO);
cap.hide();
x = a = width / 2;
y = b = height / 2;
// frameRate(100);
img=image(cap,0,0,width,height);
// dx = 0;
// dy = 0;
}
function changeGraay() {
dx = mouseX - x;
dy = mouseY - y;
}
function draw() {
//笔触跟随鼠标趋势运动
// 方法一为什么失灵?
// if (mouseX > 0 && mouseX < 300 ) {
// // if(mouseY > 300 || mouseY < 0){
// let dx = mouseX - x;
// let dy = mouseY - y;
// // }
// }
// 方法二 dist
// let r2 = dist(mouseX, mouseY, 300, 300);
// if (r2 > 500) {
// let dx = 0;
// let dy = 0;
// }
// 鼠标可以增加周围笔触精准度
// let r = dist(mouseX, mouseY, x, y);
// let value = 1;
// if (r < 50) {
// let value = 0.6
// }else if(r<=50){
// let value = 1
// }
dx = mouseX - x;
dy = mouseY - y;
strokeWeight(2);
noFill();
// line(x, y, newx, newy);
// bezier(x, y, x + random(-10, 10), y + random(-10, 10), newx + random(-10, 10), newy + random(-10, 10), newx, newy);
ix=random(0,width);
iy=random(0,height);
let col = cap.get(floor(ix), floor(iy));
stroke(col[1],100);
line(ix,iy,ix,iy+random(-100,100));
iix=random(0,width);
iiy=random(0,height);
let col1 = cap.get(floor(iix), floor(iiy));
stroke(col1[1],100);
line(iix,iiy,iix,iiy+random(-100,100));
ix1=random(0,width);
iy1=random(0,height);
let col11 = cap.get(floor(ix1), floor(iy1));
stroke(col11[1],100);
line(ix1,iy1,ix1,iy1+random(-100,100));
iix2=random(0,width);
iiy2=random(0,height);
let col12 = cap.get(floor(iix2), floor(iiy2));
stroke(col12[1],100);
line(iix2,iiy2,iix2,iiy2+random(-100,100));
// console.log(col);
// x = newx;
// y = newy;
}