Drag the inner circles and eyes around. Press space to toggle whether you can drag the eyes around. (This is useful to stop you accidentally dragging them around.)
A fork of Googlies by Michael Lowe
xxxxxxxxxx
const noOfEyes = 9; //The number of eyes
var draggable = true; //Whether the eyes can be dragged around -- This can be toggled with the spacebar.
var eyes = [];
function setup() {
createCanvas(windowWidth, windowHeight);
noStroke();
for(let eye = 0; eye < noOfEyes; eye++){
let bigSize = random(100, 350); //The size of the outer circle
let position; //The [starting] position of the inner circle
//minimise overlap
let esc = false;
for(let i = 0; i < 300 && esc == false; i ++){
esc = true;
position = createVector(random(bigSize/2, width-bigSize/2), random(bigSize/2, height-bigSize/2));
for(let eye = 0; eye < eyes.length; eye++){
if(p5.Vector.dist(eyes[eye].outerPosition, position) < bigSize/2 + eyes[eye].outerSize/2){
esc = false;
}
}
}
let smallSize = random(50, bigSize*0.7); //The size of the inner circle
let weight = createVector(0, 0); //The gravity. Negative gravity makes the inner circle "fall" up.
let magnitude = constrain(randomGaussian(1.2), 0, 2)*0.6;
let angle = randomGaussian() * 0.9 + TAU/4;
weight.x = magnitude * cos(angle);
weight.y = magnitude * sin(angle);
let airResistance = random(0.99, 1); //The air resitance. 1: No air restistance, <1: things slow down, >1: things speed up
let damping = random(0.97, 1); //The amount the speed decreases when the inner circle hits the side. 1: Stays the same, <1: Decreases, 0: Stops, >1: Speed increases
let speedBoost = 1.2; //The amount the speed is enhanced when you drag the inner circle and then let it go. 1: No enchancement, >1: New speed is greater than the speed you moved your cursor, <1: New speed is less, <0: Inner circle moves in the opposite direction
//Try putting gravity's magnitude at 2 and dampening at 1.03.
append(eyes, new Eye(position, bigSize, smallSize, weight, airResistance, damping, speedBoost));
}
}
function draw() {
background(50.5);
for(let eye = 0; eye < eyes.length; eye++){
eyes[eye].update();
eyes[eye].display();
}
}
function mousePressed(){
let eye = eyes.length-1;
while(eye >= 0){
if(eyes[eye].checkDragging()){
eye = -1;
}else{
eye--;
}
}
}
function mouseReleased(){
for(let eye = 0; eye < eyes.length; eye++){
eyes[eye].dragging = false;
eyes[eye].outerDragging = false;
}
}
function keyPressed(){
if(key == ' '){
draggable = !draggable;
}
}