Advertisement
Krystman

polka rainbow

Feb 5th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.99 KB | None | 0 0
  1. float lineOffset = 0; // helper variable to offset eery second line
  2. float dotSize=40; // size of our dots
  3. float dotSpacing=90; // the spacing of our dots
  4.  
  5. int fileCounter=0; // a counter for file saving
  6.  
  7. void setup() {
  8.   colorMode(HSB,100);
  9.   size(1920, 1080); //set screen size
  10.   background(100, 0, 100); // draw background
  11.   noStroke(); // remove outlines
  12. }
  13.  
  14. void draw() {  
  15. }
  16.  
  17. void keyPressed() {
  18.   // this is being called when u press a button
  19.   if (key=='d') {
  20.     drawDots();
  21.   }
  22.   if (key=='r') {
  23.     // save the content of the screen to a file
  24.     save("dots" + fileCounter + ".png");
  25.     fileCounter++; //fileCounter = fileCounter + 1
  26.     println("Saved!");
  27.      
  28.     // randomize fill color
  29.     fill(random(255),random(255),random(255));
  30.    
  31.     // randomize background color
  32.     background(random(255),random(255),random(255));
  33.    
  34.     // randomize size
  35.     dotSize=random(10,100);
  36.    
  37.     // randomize spacing
  38.     dotSpacing=random(dotSize + 5, dotSize + 100);
  39.   }
  40. }
  41.  
  42. void drawDots() {
  43.   background(100,0,100);
  44.   dotSpacing = 45;
  45.   float stretch=random(1,16);
  46.   float colorOffset=random(0,100);
  47.   for (int j=-5; j < 150; j=j+1) { // outer loop for lines
  48.     for (int i=-5; i < 200; i=i+1) { // inner loop for individual circles
  49.      
  50.       // first we check if the line we are drawing
  51.       // is odd or even
  52.       if (j%2==0) {
  53.         // if even, we offset the entire line
  54.         lineOffset=dotSpacing/2;
  55.       } else {
  56.         lineOffset=0;
  57.       }
  58.       lineOffset=random(200);
  59.       // actually draw the dot
  60.      
  61.       float dotX=i*dotSpacing+lineOffset;
  62.       float dotY=j*dotSpacing + random(200);
  63.       dotSize = random(30,100);
  64.      
  65.       float myColor=dotX/width * 100;
  66.       myColor = myColor / stretch;
  67.       myColor = myColor + colorOffset;
  68.       myColor = myColor + random(5);
  69.       myColor = myColor % 100;
  70.      
  71.       fill(myColor,100-random(10),100, random(50,100));
  72.       ellipse(dotX, dotY, dotSize, dotSize);
  73.     }
  74.   }  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement