xxxxxxxxxx
79
// painting pixels video feed
let vid;
let vidScale = 16;
let slider;
let median;
let myFont;
let particles = [];
function setup() {
createCanvas(640, 480);
pixelDensity(1);
background(217, 151, 98);
vid = createCapture(VIDEO);
vid.size(width / vidScale, height / vidScale);
vid.hide();
for (i=0;i<300;i++){
particles[i] = new Particle();
}
slider = createSlider(0,255,0)
}
function draw() {
vid.loadPixels();
for (i = 0; i < particles.length; i++) {
particles[i].display();
particles[i].move();
}
vid.updatePixels();
}
class Particle {
constructor() {
this.x = random(width);
this.y = random(height);
// this.x = width/2;
// this.y =height/2;
this.r = random(5,20);
this.angle=random(0,HALF_PI)
this.w=random(5,10)
this.h=random(-5,5)
}
display() {
noStroke()
let pixelX=floor(this.x/vidScale)
let pixelY=floor(this.y/vidScale)
let col = vid.get(pixelX,pixelY)
console.log(col)
stroke(col[0],col[1],col[2], slider.value());
strokeWeight(8)
noFill()
// ellipse(this.x, this.y, this.r, this.r);
arc(this.x,this.y,this.w,this.h,PI,0)
}
move() {
this.x += random(-15, 15);
this.y += random(-15,15);
this.x=constrain(this.x,0,width)
this.y=constrain(this.y,0,height)
}
}