Random Spirals

Random SpiralsBased on the Triangle Flower example from the Processing learning basics site, I’ve come up with a rendered image that will generate a random, coloured spiral every time it loads. It’s similar to the appearance of a kaleidoscope. You can have a look at it online here.

At this point, to see a new spiral, you have to re-run the Java, or re-load the page rather than pressing a button, moving the mouse or anything like that. Hopefully I’ll be able to get that to work soon as I think it would look pretty cool if I could get it to change as you move the mouse over it, similar to the way a kaleidoscope changes as you move it around.

I suspect it is to do with the lack of a draw() function, but when I add it in and run the spiral() function from within the draw() function, it completely changes the way the spirals render and I haven’t yet been able to get it to behave correctly.

Point[]p = new Point[3];
float shift = 2.0;
float fade = 0;
float fillCol = 0;
float rot = 0;
float spin = 0;
float value = random(100);
float valuex = random(200);
float valuey = random(300);

void setup(){
size(800, 800);
fade = 255.0/(width/2.0/shift);
spin = 360.0/(width/2.0/shift);
p[0] = new Point(-width/2, height/2);
p[1] = new Point(width/2, height/2);
p[2] = new Point(0, -height/2);
translate(width/2, height/2);
spiral(value, valuex, valuey);

void spiral(float shift1, float shift2, float shift3){
float r = random(100, 255);
float g = random(100, 255);
float b = random(100, 255);
fill(r, g, b, 4);
triangle(p[0].x+=shift, p[0].y-=shift/(random(shift1)), p[1].x-=shift, p[1].y-=shift/(random(shift2)), p[2].x, p[2].y+=shift*(random(shift3)));
// recursive call
spiral(shift1, shift2, shift3);

Tags: , , ,

Leave a Reply