Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.35 KB | None | 0 0
  1. //Conrad Menchine's pointillism effect generator
  2. //hold down the left mouse button to draw points
  3.  
  4. //shitty enum
  5. static int FUR = 1;
  6. static int SQUARES = 2;
  7. static int BEZ = 3; //bezier
  8. static int CIRCLES = 4;
  9. static int RAND = 5;
  10.  
  11. int mode = BEZ;
  12.  
  13. int dotSize = 16;
  14. int minDotSize = 4; //used for circle effect
  15. float dotSkew = 0.6; //used for circle effect
  16.  
  17. PImage photo;
  18. void setup(){
  19.   photo = loadImage("lake.jpg"); //load your own photo
  20.   size(1400,800);
  21.  
  22.   noStroke();
  23.  
  24. }
  25.  
  26. void genPoints(){
  27.   for(int i = 0; i < 1000; i++) dot(random(width), random(height));
  28. }
  29. void draw(){
  30.   if(mousePressed) genPoints(); //shame on me
  31. }
  32. void dot(float x, float y){
  33.   //Why didn't I use a switch/case? Because I'm a dingus, that's why
  34.   if(mode == FUR){
  35.     color dotCol = photo.get((int)x,(int)y);
  36.     fill(dotCol);
  37.     beginShape();
  38.       curveVertex(x + random(dotSize*2), y);
  39.       curveVertex(x, y + random(dotSize*2));
  40.       curveVertex(x - random(dotSize*2), y);
  41.       curveVertex(x, y - random(dotSize*2));
  42.     endShape();
  43.   }
  44.   if(mode == SQUARES){
  45.     color dotCol = photo.get((int)x,(int)y);
  46.     fill(dotCol);
  47.     beginShape();
  48.       vertex(x + random(dotSize), y);
  49.       vertex(x, y + random(dotSize));
  50.       vertex(x - random(dotSize), y);
  51.       vertex(x, y - random(dotSize));
  52.     endShape();    
  53.   }
  54.   if(mode == BEZ){
  55.     color dotCol = photo.get((int)x,(int)y);
  56.     fill(dotCol);
  57.     float f1 = random(dotSize);
  58.     float f2 = random(dotSize);
  59.     float f3 = random(dotSize);
  60.     float f4 = random(dotSize);
  61.    
  62.     beginShape();
  63.       vertex(x + f1, y);
  64.       //bezierVertex(x + f1, y, x, y + f2, x - f3, y);
  65.       bezierVertex(x, y + f2, x - f3, y, x, y - f4);
  66.       bezierVertex(x - f3, y, x, y - f4, x + f1, y);
  67.       bezierVertex(x, y - f4, x + f1, y, x, y + f2);
  68.     endShape();    
  69.   }
  70.   if(mode == CIRCLES){
  71.     color dotCol = photo.get((int)x,(int)y);
  72.     fill(dotCol);
  73.     ellipse(x,y, random(dotSize, minDotSize), random(minDotSize * dotSkew, dotSize * dotSkew));
  74.   }
  75.   if(mode == RAND){
  76.     //just draws all of them and maybe selects itself sometimes too/ who cares; it works.
  77.     mode = (int) random(RAND); //that's 5 for those of you following along at home
  78.     dot(x,y); //wowie, recursion! I haven't seen that used since my last programming class and literally never anywhere else!
  79.     mode = RAND;
  80.   }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement