Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int linesPerCluster = 6;
- int[] lineHues; //hue value for the lines
- ArrayList<LineCluster> lineClusters = new ArrayList<LineCluster>();
- int lineAmount = 10; //amount of line clusters per object
- int clusterLength = 130; //max length of the lines
- float speed = 5;
- int midOffset = 100; //offset from the origin of the circle
- int lineColorIndex = 0; //used as an index to loop through the linecolors
- class LineCluster { // This object holds 6 lines
- private ArrayList<Line> lines = new ArrayList<Line>();
- LineCluster(int clusterLength, float clusterRot, PVector lineOffset, PVector clusterPos, float clusterSize) {
- for(int i = 0; i < linesPerCluster; i++)
- lines.add(new Line(clusterLength, lineHues[i], clusterRot, lineOffset, clusterPos, clusterSize, i));
- }
- }
- class Line { // This object is a line that rotates, has a size, has a length that varies over time, and a position of course
- private float lineLength;
- private float maxLineLength;
- private int lineHue;
- private float lineRot;
- private PVector lineOffset;
- private PVector clusterPos;
- private float clusterSize;
- private boolean shortening = false;
- Line(float clusterLength, int clusterHue, float clusterRot, PVector lineOffset, PVector clusterPos, float clusterSize, int index){
- this.lineLength = clusterLength - index*15;
- this.maxLineLength = clusterLength;
- this.lineHue = clusterHue + index*int(random(-4,4)) % 360;
- this.lineRot = clusterRot + index*0.55;
- this.lineOffset = lineOffset;
- this.clusterPos = clusterPos;
- this.clusterSize = clusterSize;
- }
- void display(){
- stroke(lineHue, 40, 80);
- pushMatrix();
- translate(clusterPos.x, clusterPos.y);
- scale(clusterSize, clusterSize);
- rotate(lineRot);
- line(lineOffset.x-lineLength/2, lineOffset.y, lineOffset.x+lineLength/2, lineOffset.y);
- popMatrix();
- lineRot += 0.01;
- if(lineLength <= 0)
- shortening = false;
- if(lineLength >= maxLineLength)
- shortening = true;
- if(shortening)
- lineLength -= speed;
- else
- lineLength += speed;
- }
- }
- void setup() {
- size(1500, 1000);
- background(20);
- noFill();
- strokeWeight(3);
- colorMode(HSB, 360, 100, 100);
- smooth();
- 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)
- }
- void draw() {
- background(20);
- stroke(255, 0, 0);
- for (LineCluster c : lineClusters) //for each cluster
- for (Line l : c.lines) //for each line in the cluster
- l.display(); //display it
- }
- void mouseReleased(){ //adds a new object with random color values
- for (int i = 0; i < lineHues.length; i++)
- lineHues[i] = int(random(360));
- float clusterSizeMapped = map(random(1, 10), 1, 10, 0.4, 1.5);
- for (int i = 0; i < lineAmount; i++) {
- lineClusters.add(new LineCluster(clusterLength, TWO_PI/lineAmount*i, new PVector(-midOffset, 0), new PVector(mouseX, mouseY), clusterSizeMapped));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement