Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int fc, num = 80, edge = 200;
- ArrayList ballCollection;
- boolean save = false;
- void setup() {
- size(500, 500);
- background(0);
- ballCollection = new ArrayList();
- createStuff();
- }
- void draw() {
- background(0);
- for (int i=0; i<ballCollection.size(); i++) {
- Ball mb = (Ball) ballCollection.get(i);
- mb.run();
- }
- if (save) {
- if (frameCount%2==0 && frameCount < fc + (121)) saveFrame("image-####.tif");
- }
- }
- void keyPressed() {
- fc = frameCount;
- save = true;
- }
- void mouseReleased() {
- background(0);
- createStuff();
- }
- void createStuff() {
- ballCollection.clear();
- for (int i=0; i<num; i++) {
- float radius = random(50, 100);
- float angle = TWO_PI/num*i;
- println(angle);
- float offSet = random(TWO_PI);
- Ball myBall = new Ball(radius, angle, offSet);
- ballCollection.add(myBall);
- }
- }
- class Ball {
- PVector loc = new PVector(0, 0);
- float sz = 5;
- float theta, angle, radius, offSet, scal, x2, y2;
- int s, c, dir, d = 40;
- Ball(float _radius, float _angle, float _offSet) {
- angle = _angle;
- radius = _radius;
- offSet = _offSet;
- }
- void run() {
- move();
- display();
- lineBetween();
- }
- void move() {
- scal = map(sin(theta+offSet), -1, 1, .50, 2.1);
- loc.x = width/2 + sin(angle)*radius*scal;
- loc.y = height/2 + cos(angle)*radius*scal;
- theta += 0.0523;
- }
- void lineBetween() {
- for (int i=0; i<ballCollection.size(); i++) {
- Ball other = (Ball) ballCollection.get(i);
- float distance = loc.dist(other.loc);
- if (distance >0 && distance < d) {
- c = (int) map(loc.x, 100, width-100, 0, 360);
- colorMode(HSB, 360, 100, 100);
- //stroke(#ffffff,150);
- stroke(c, 90, 90, 200);
- line(loc.x, loc.y, other.loc.x, other.loc.y);
- colorMode(RGB);
- }
- }
- }
- void display() {
- noStroke();
- fill(255);
- ellipse(loc.x, loc.y, sz, sz);
- stroke(255);
- x2 = width/2 + sin(angle)*220;
- y2 = height/2 + cos(angle)*220;
- line(loc.x, loc.y, x2, y2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment