class HexBase {
float x,
y,
r,
an;
boolean left;
color c;
int t;
float vy = 0.0;
boolean falldown;
HexBase(float X, float Y) {
x = X;
y = Y;
r = random(5, 40);
an = random(360);
if (random(1) < .5) {
left = false;
} else {
left = true;
}
colorMode(HSB);
c = color(random(255), 255, 255);
t = 0;
if(random(1)<.001){
falldown = false;
}else{
falldown=true;
}
}
}
ArrayList < HexBase > effect = new ArrayList < HexBase > ();
PVector agent = new PVector(random(800), random(800));
float vx,
vy;
void drawHex(float x, float y, float r, float an) {
float angle = TWO_PI / 6;
translate(x, y);
rotate(radians(an));
beginShape();
strokeWeight(3);
for (float a = 0; a < TWO_PI; a += angle) {
float sx = cos(a) * r;
float sy = sin(a) * r;
vertex(sx, sy);
}
endShape(CLOSE);
resetMatrix();
}
boolean grafiti = false;
void setup() {
size(800, 800);
float r = random(0, 360);
vx = sin(r) * 7;
vy = cos(r) * 7;
background(0);
}
void draw() {
if (!grafiti) {
background(0);
}
if (frameCount % 3 == 0) {
for (int i = 0; i < random(1, 2); i++) {
effect.add(new HexBase(mouseX + random( - 50, 50), mouseY + random( - 50, 50)));
}
}
ArrayList < HexBase > remove = new ArrayList < HexBase > ();
for (HexBase h: effect) {
fill(h.c, 100 - h.t);
stroke(h.c, 200 - (h.t * 3));
drawHex(h.x, h.y, h.r, h.an);
if (h.t > 110) {
remove.add(h);
}
if (h.left) {
h.an += random(1, 4);
} else {
h.an -= random(1, 4);
}
h.x += sin(radians(h.an)) * 2;
h.y += cos(radians(h.an)) * 2;
h.y += h.vy;
if(h.falldown){
h.vy += 0.1;
}else{
h.vy -=0.1;
}
h.t++;
effect.removeAll(remove);
}
agent.x += vx;
agent.y += vy;
if (agent.x < 0 || agent.x > width) {
agent.x -= vx;
vx = -vx;
// vy *= random(.6, 1.5);
}
if (agent.y < 0 || agent.y > height) {
agent.y -= vy;
vy = -vy;
// vx *= random(.6, 1.5);
}
}
void keyPressed() {
grafiti = !grafiti;
}