Skip to content

Instantly share code, notes, and snippets.

@triss
Created February 10, 2014 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save triss/8910371 to your computer and use it in GitHub Desktop.
Save triss/8910371 to your computer and use it in GitHub Desktop.
import processing.pdf.*;
import triss.colourlovers.*;
ArrayList<PVector> points;
ArrayList<Line> lines;
color[] colours;
int c = 0;
int quant = 3;
float n = 0;
float rotations = 4;
void setup() {
//size(7017, 4963, PDF, "file.pdf");
size(720, 720);
//noLoop();
ColourLovers cl = new ColourLovers(this);
ColourLoversPalette pal = cl.getPaletteById(443871);
println(pal.getId());
colours = pal.getColours();
points = new ArrayList<PVector>();
lines = new ArrayList<Line>();
PVector startPoint = new PVector(width / 2, height / 2);
buildFract(rotations, height / 6, 5, startPoint);
}
void draw() {
background(255);
n += 0.01;
float size = height * 0.1;
ellipseMode(CORNERS);
rectMode(CORNERS);
stroke(0, 10);
// for(PVector p : points) {
// int connections = 0;
// int i = int(random(points.size()));
// while(i < points.size() && connections < 10) {
// PVector q = points.get(i);
//
// //if(p.dist(q) < size && p.dist(q) > size * 0.95) {
// stroke(colours[++c % colours.length], 200);
// line(p.x, p.y, q.x, q.y);
// connections++;
// //}
//
// i = i + 1 % points.size();
// }
// }
for(Line l : lines) {
if(l.depth < 3) {
l.draw();
}
}
saveFrame();
}
void buildFract(float rotations, float length, int depth, PVector pos) {
if(depth > 0 && onScreen(pos)) {
PVector p;
float rotationAmt = TWO_PI / rotations;
for(float r = 0; r < TWO_PI; r += rotationAmt) {
p = new PVector(length, length);
p.rotate(r);
p.add(pos);
buildFract(rotations, length * 0.60, depth - 1, p);
points.add(p);
lines.add(new Line(pos, p, depth, colours[++c % colours.length]));
}
}
}
class Line {
PVector start, finish;
float depth = 0;
color colour;
Line(PVector start, PVector finish, float depth, color colour) {
this.start = start;
this.finish = finish;
this.depth = depth;
this.colour = colour;
}
void draw() {
if(start.dist(finish) < 30) {
strokeWeight(depth * 3);
stroke(colour, 230);
float x = sin(norm((start.x + n) % width, 0, width) * TWO_PI);
float y = sin(norm((start.y + n) % height, 0, height) * TWO_PI);
int z = int(noise(x + y + n) * 7);
float q = quant * pow(2, z);
line(
int(start.x/q)*q,
int(start.y/q)*q,
int(finish.x/q)*q,
int(finish.y/q)*q
);
// for(int i = 0; i < 100 / rotations; i+=int(random(1, 2) * 3)) {
// pushMatrix();
// translate(start.x, start.y);
//
// PVector endVect = PVector.sub(start, finish);
// endVect.rotate(radians(i));
// endVect.mult((noise(radians(i)) + 1) * 2);
// //endVect.mult(i / 15.0);
// //endVect.limit(100 / depth);
//
// line(0, 0, endVect.x, endVect.y);
// popMatrix();
// }
}
}
}
boolean onScreen(PVector pos) {
return pos.x < width
&& pos.x >= 0
&& pos.y < height
&& pos.y >= 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment