Advertisement
xeromino

galaxies

May 21st, 2015
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. int outer=20, circles=15, frames=1800, d=20, fc;
  2. float theta;
  3. long rs;
  4. boolean save=false;
  5.  
  6. void setup() {
  7.   size(540, 540);
  8.   noStroke();
  9.   rs = (long)random(123);
  10. }
  11.  
  12. void draw() {
  13.   randomSeed(rs);
  14.   background(20);
  15.   createGalaxy(.8, .3, -1, 170);
  16.   createGalaxy(.25, .6, 1, 250);
  17.   theta += TWO_PI/frames;
  18.   if (save && frameCount<=fc+(frames/outer)) saveFrame("images-###.gif");
  19. }  
  20.  
  21. void createGalaxy(float _x, float _y, int dir, int max) {
  22.   for (int j=0; j<circles; j++) {
  23.     float angle=0;
  24.     pushMatrix();
  25.     translate(width*_x+random(-d, d), height*_y+random(-d, d));
  26.     rotate(theta*(j+1)*dir);
  27.     float d = random(60, max);
  28.     float sz = random(1, 6);
  29.     float offSet = random(TWO_PI);
  30.     for (int i=0; i<outer; i++) {
  31.       angle=TWO_PI/outer*i;
  32.       float x = cos(angle+offSet)*d;
  33.       float y = sin(angle+offSet)*d;
  34.       for (int k=0; k<5; k++) {
  35.         strokeWeight((k*2));
  36.         stroke(255, 10);
  37.         noFill();
  38.         ellipse(x, y, sz, sz);
  39.       }
  40.       fill(255);
  41.       noStroke();
  42.       ellipse(x, y, sz, sz);
  43.     }
  44.     popMatrix();
  45.   }
  46. }
  47.  
  48. void mouseReleased() {
  49.   rs = (long)random(123);
  50.   randomSeed(rs);
  51.   background(20);
  52.   createGalaxy(.7, .3, -1, 150);
  53.   createGalaxy(.25, .6, 1, 250);
  54. }
  55.  
  56. void keyPressed() {
  57.   fc = frameCount;
  58.   save = true;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement