Advertisement
Guest User

Untitled

a guest
Oct 11th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.04 KB | None | 0 0
  1. int linesPerCluster = 6;
  2. int[] lineHues; //hue value for the lines
  3. ArrayList<LineCluster> lineClusters = new ArrayList<LineCluster>();
  4. int lineAmount = 10; //amount of line clusters per object
  5. int clusterLength = 130; //max length of the lines
  6. float speed = 5;
  7. int midOffset = 100; //offset from the origin of the circle
  8. int lineColorIndex = 0; //used as an index to loop through the linecolors
  9.  
  10. class LineCluster { // This object holds 6 lines
  11.   private ArrayList<Line> lines = new ArrayList<Line>();
  12.  
  13.   LineCluster(int clusterLength, float clusterRot, PVector lineOffset, PVector clusterPos, float clusterSize) {
  14.     for(int i = 0; i < linesPerCluster; i++)
  15.       lines.add(new Line(clusterLength, lineHues[i], clusterRot, lineOffset, clusterPos, clusterSize, i));
  16.   }
  17. }
  18.  
  19. class Line { // This object is a line that rotates, has a size, has a length that varies over time, and a position of course
  20.   private float lineLength;
  21.   private float maxLineLength;
  22.   private int lineHue;
  23.   private float lineRot;
  24.   private PVector lineOffset;
  25.   private PVector clusterPos;
  26.   private float clusterSize;
  27.   private boolean shortening = false;
  28.  
  29.   Line(float clusterLength, int clusterHue, float clusterRot, PVector lineOffset, PVector clusterPos, float clusterSize, int index){
  30.     this.lineLength = clusterLength - index*15;
  31.     this.maxLineLength = clusterLength;
  32.     this.lineHue = clusterHue + index*int(random(-4,4)) % 360;
  33.     this.lineRot = clusterRot + index*0.55;
  34.     this.lineOffset = lineOffset;
  35.     this.clusterPos = clusterPos;
  36.     this.clusterSize = clusterSize;
  37.   }
  38.  
  39.   void display(){    
  40.     stroke(lineHue, 40, 80);
  41.     pushMatrix();
  42.     translate(clusterPos.x, clusterPos.y);
  43.     scale(clusterSize, clusterSize);
  44.     rotate(lineRot);
  45.     line(lineOffset.x-lineLength/2, lineOffset.y, lineOffset.x+lineLength/2, lineOffset.y);
  46.     popMatrix();  
  47.     lineRot += 0.01;
  48.    
  49.     if(lineLength <= 0)
  50.       shortening = false;
  51.     if(lineLength >= maxLineLength)
  52.       shortening = true;
  53.  
  54.     if(shortening)
  55.       lineLength -= speed;
  56.     else
  57.       lineLength += speed;
  58.   }
  59. }
  60.  
  61. void setup() {
  62.   size(1500, 1000);
  63.   background(20);
  64.   noFill();
  65.   strokeWeight(3);
  66.   colorMode(HSB, 360, 100, 100);
  67.   smooth();
  68.   lineHues = new int[linesPerCluster]; //amount of different colors we need (every cluster, which I define as 6 lines next to each other, should look the same)
  69. }
  70.  
  71. void draw() {
  72.   background(20);
  73.   stroke(255, 0, 0);
  74.   for (LineCluster c : lineClusters) //for each cluster
  75.     for (Line l : c.lines)           //for each line in the cluster
  76.       l.display();                   //display it
  77. }
  78.  
  79. void mouseReleased(){ //adds a new object with random color values
  80.   for (int i = 0; i < lineHues.length; i++)
  81.     lineHues[i] = int(random(360));
  82.  
  83.   float clusterSizeMapped = map(random(1, 10), 1, 10, 0.4, 1.5);
  84.   for (int i = 0; i < lineAmount; i++) {  
  85.     lineClusters.add(new LineCluster(clusterLength, TWO_PI/lineAmount*i, new PVector(-midOffset, 0), new PVector(mouseX, mouseY), clusterSizeMapped));
  86.   }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement