Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int spaceBetween = 20;
- int numX, numY, counter;
- float theta=0, maxDist=40;
- int frames = 240, num=20;
- ArrayList<Node> nodes = new ArrayList<Node>();
- ArrayList<Orb> orbs = new ArrayList<Orb>();
- void setup() {
- size(1080, 720, P2D);
- blendMode(ADD);
- background(0);
- stroke(8, 4, 2);
- numX = width/spaceBetween;
- numY = height/spaceBetween;
- initObjects();
- }
- void draw() {
- for (Orb o : orbs) {
- o.display();
- }
- theta += TWO_PI/frames;
- }
- void keyPressed() {
- save(random(1212)+".jpg");
- }
- void initObjects() {
- nodes.clear();
- for (int x=0; x<numX; x++) {
- for (int y=0; y<numY; y++) {
- Node n = new Node((x+.5)*spaceBetween, (y+.5)*spaceBetween);
- nodes.add(n);
- }
- }
- for (int i=0; i<num; i++) {
- float radius = map(i, 0, num-1, height*.1, height*.4);
- int dir = i%2==0 ? 1: -1;
- Orb o = new Orb(radius, dir);
- orbs.add(o);
- }
- }
- class Node {
- PVector loc;
- Node(float x, float y) {
- loc = new PVector(x, y);
- }
- }
- class Orb {
- float radius, r, sz = 40;
- int dir;
- Orb(float _radius, int _dir) {
- radius = _radius;
- r = random(TWO_PI);
- dir = _dir;
- counter++;
- }
- void display() {
- float x = width/2 + sin(theta*dir+r)*radius;
- float y = height/2 + cos(theta*dir+r)*radius;
- noFill();
- stroke(8, 4, 2);
- for (Node n : nodes) {
- float d = dist(x, y, n.loc.x, n.loc.y);
- if (d<maxDist) {
- stroke(8, 4, 2);
- line(x, y, n.loc.x, n.loc.y);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement