made with Processing
by Flik
2017-10-26
Please let me know, if you are interested!
Source Code
object[] OB = new object[100];
void setup() {
size(1000, 750);
background(20);
noStroke();
for (int i =0; i < OB.length; i++) {
OB[i] = new object();
}
}
void draw() {
//background(20);
fill(0, 30);
rect(0, 0, width, height);
for (int i =0; i < OB.length; i++) {
OB[i].update();
OB[i].drawObj();
}
}
void mouseDragged() {
for (int i =0; i < OB.length; i++) {
OB[i].attraction(mouseX, mouseY);
}
}
void mousePressed() {
for (int i =0; i < OB.length; i++) {
OB[i].pushPosition();
OB[i].attraction(mouseX, mouseY);
}
}
void mouseReleased() {
for (int i =0; i < OB.length; i++) {
OB[i].popPosition();
//OB[i].attraction(mouseX, mouseY);
}
}
class object {
float rate = 0.1;
float size = 10;
float destinationX = width/2;
float destinationY = height/2;
float previousX;
float previousY;
float positionX = width/2;
float positionY = height/2;
color fillcolor;
int grid= 5;
object() {
destinationX = random(0, width);
destinationY = random(0, height);
rate = random(0.05, 0.2);
size = grid*0.5 + grid * random(0, 1) * 1.5;
fillcolor = color(255, 40);
}
void drawObj() {
positionX = grid + 2*grid* int(lerp(positionX, destinationX, rate)/(2*grid));
positionY = grid + 2*grid* int(lerp(positionY, destinationY, rate)/(2*grid));
fill(fillcolor);
ellipse(positionX, positionY, size, size);
}
void update() {
destinationX += random(-grid, grid);
destinationY += random(-grid, grid);
destinationX = constrain(destinationX, 0, width);
destinationY = constrain(destinationY, 0, height);
}
void pushPosition() {
previousX = positionX;
previousY = positionY;
}
void popPosition() {
destinationX = previousX;
destinationY = previousY;
}
void attraction(float pointX, float pointY) {
destinationX = pointX;
destinationY = pointY;
}
}
댓글
댓글 쓰기