Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int num = 15, min=150, max=300, fc = 100;
- PVector[] loc = new PVector[num];
- PVector[] vel = new PVector[num];
- float[] sz = new float[num];
- void setup() {
- size(1080, 720, P2D);
- blendMode(ADD);
- background(0);
- noFill();
- stroke(8, 4, 2);
- initStuff();
- }
- void draw() {
- drawElement();
- if (frameCount%fc==0) {
- save(fc+".jpg");
- fc += 100;
- }
- }
- void drawElement() {
- float outside = min;
- for (int i=0; i<loc.length; i++) {
- loc[i].add(vel[i]);
- if (loc[i].x > width+outside || loc[i].x<-outside) {
- vel[i].x *= -1;
- }
- if (loc[i].y > height+outside || loc[i].y<-outside) {
- vel[i].y *= -1;
- }
- }
- for (int i=0; i<loc.length; i++) {
- for (int j=0; j<loc.length; j++) {
- float distance=dist(loc[i].x, loc[i].y, loc[j].x, loc[j].y);
- if (distance>min && distance<max) {
- //stroke(8, 4, 2);
- if (i != j) line(loc[i].x, loc[i].y, loc[j].x, loc[j].y);
- }
- }
- }
- }
- void keyPressed() {
- if (key=='s') save(random(23232)+".jpg");
- if (key=='1') stroke(8, 4, 2);
- if (key=='2') stroke(1, 3, 2);
- if (key=='3') stroke(3, 1, 1);
- }
- void mouseReleased() {
- initStuff();
- }
- void initStuff() {
- background(0);
- float r = 4;
- for (int i=0; i<num; i++) {
- float x = random(width);
- float y = random(height);
- loc[i] = new PVector(x, y);
- vel[i] = new PVector(random(-r, r), random(-r, r));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement