xxxxxxxxxx
let a,b,c;
let skalar = 1.2;
let flock;
let video;
function setup() {
createCanvas(555, 555,WEBGL);
background(100);
video = createCapture(VIDEO);
video.hide();
video.size(480,360);
flock = new Flock();
// Add an initial set of boids into the system
for (var i = 0; i < 222; i++) {
var b = new Ring();
b.start(random(width*skalar), random(height*skalar));
flock.addBoid(b);
}
}
function draw() {
ambientLight(200, 200, 200);
let dirX = (mouseX / width - 0.5) * 2;
let dirY = (mouseY / height - 0.5) * 2;
directionalLight(160, 140, 140, -dirX, -dirY, -1);
rotateY(65);
rotateX(90);
translate(-width/2,-height/2);
flock.run();
}
function Ring() {
let x;
let y; // X-coordinate, y-coordinate
let diameter; // Diameter of the ring
let on = false; // Turns the display on and off
this.start = function(xpos, ypos) {
x = xpos;
y = ypos;
on = true;
diameter = width;
}
this.grow = function() {
if (on == true) {
diameter -= random(4,6);
if (diameter < 20 ) {
//diameter = width;
on = false;
}
}
}
this.display = function() {
if (on == true) {
fill(random(77),random(122,199),random(22),random(122,255));
strokeWeight(random(0.3,1.1));
stroke(22,random(122,255));
stroke('black');
fill('white');
//noStroke();
push();
translate(x,y);
texture(video);
box(diameter);
pop();
//circle(x, y, diameter);
}
}
}
function Flock() {
// An array for all the boids
this.boids = []; // Initialize the array
this.run = function() {
for (var i = 0; i < this.boids.length; i++) {
this.boids[i].grow();
this.boids[i].display();
}
}
this.addBoid = function(b) {
this.boids.push(b);
}
}
function mousePressed(){
save('LewisMumford.png');
}
function keyPressed(){
save('LewisMumford.png');
}