xxxxxxxxxx
216
/*
2024 08 24
using get() to essentialy trace type based on black and white readings
array of objects to draw circles
space to scatter and un scatter
b key to expand based on mouse distance
*/
let coX = [];
let coY = [];
let dia = 5;
let points = [];
let go = false;
let txt = "water"
let bloom = true;
let scatter = false;
let home = false;
let avoid = false;
let static = false;
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
textSize(240);
textStyle(BOLD);
textAlign(CENTER, CENTER);
text(txt, width/2, height/2);
for (let x = 0; x < width; x += dia * 2) {
for (let y = 0; y < height; y += dia * 2) {
let c = get(x, y);
let b = brightness(c);
if (b === 0) {
points.push(createPoint(x, y, dia));
}
}
}
console.log(points[0].mode);
}
function draw() {
background(240, 240, 255);
for (let i = 0; i < points.length; i++) {
if (bloom) {
points[i].bloom();
}
if (scatter) {
points[i].scatter();
} /*else if (avoid) {
points[i].avoidMouse();
//for (let j = i + 1; j < points.length; j++) {
// points[i].avoid(points[j]);
// }
} */ else {
points[i].homing();
}
}
//console.log(get(mouseX, mouseY));
}
// point object
function createPoint(x, y, s, m) {
var point = {
size: s,
r: 0,
g: 0,
b: 255,
d: 10,
mode: m,
position: createVector(x, y),
ogPosition: createVector(x, y),
velocity: createVector(random(-2,2), random(-2,2)),
show: function() {
noStroke();
fill(this.r, this.g, this.b);
ellipse(this.position.x, this.position.y, this.size, this.size);
},
scatter: function() {
this.show();
this.position.add(this.velocity);
if (this.position.x >= width || this.position.x <= 0) {
this.velocity.x *= -1;
}
if (this.position.y >= width || this.position.y <= 0) {
this.velocity.y *= -1;
}
},
bloom: function() {
//this.show();
this.mousePos = createVector(mouseX, mouseY);
this.d = this.position.dist(this.mousePos);
noStroke();
fill(this.r, this.g, this.b);
this.size = constrain(map(this.d,50,0,5,50),5,100);
ellipse(this.position.x, this.position.y, this.size, this.size);
},
avoid: function(obj) {
this.show();
this.mousePos = createVector(mouseX, mouseY);
this.d = this.position.dist(this.mousePos);
if ((this.size + obj.size)/2 > this.d) {
this.move();
}
/*
if (obj.size / 2 + this.size / 2 > this.position.dist(obj.position)) {
console.log("collision!")
this.move();
//return true;
}*/
},
/*
avoidMouse: function() {
this.show();
this.mousePos = createVector(mouseX, mouseY);
this.d = this.position.dist(this.mousePos);
if (this.d < this.size * 3) {
this.move(this.d);
}
},
move: function(step) {
this.jump = step * 4
this.show();
this.coin = [0, 1];
if (random(this.coin) === 1) {
this.jump *= -1
}
//this.randoD = createVector(random(-10,10), random(-10,10));
this.position.x = lerp(this.position.x, this.position.x + this.jump, 0.1);
this.position.y = lerp(this.position.y, this.position.y + this.jump, 0.1);
},*/
homing: function() {
this.show();
// lerp(sX[0], mouseX, 0.1);
this.position.x = lerp(this.position.x, this.ogPosition.x, 0.1);
this.position.y = lerp(this.position.y, this.ogPosition.y, 0.1);
}
}
return point;
}
function keyPressed() {
if (key === "b") {
if (bloom === true) {
bloom = false;
} else {
bloom = true;
avoid = false;
}
}
if (key === "s") {
if (static === true) {
static = false;
} else {
static = true;
}
}
/*
if (key === "h") {
if (home === true) {
home = false;
} else {
home = true;
}
}*/
/*
if (key === "a") {
if (avoid === true) {
avoid = false;
} else {
avoid = true;
bloom = false;
}
} */
if (keyCode === 32) {
if (scatter === true) {
scatter = false;
} else {
scatter = true;
}
}
}