Mouse Controlled Kaleidoscope

I have added some mouse controls to my kaleidoscope so that the type of motion changes based on the position of the mouse.

The motion is slow if the mouse is in the top-left corner and speeds up as you move in any direction from the top-left, moving in different ways depending on the direction of the mouse.

I have added the ability to be able to control the animation by clicking the mouse as well. This is commented out in the online file and in the source code, but can easily be turned back on by uncommenting it.

It’s available online here.

If the comments are removed, then no animation will occur until the left mouse button is pressed. When it is pressed it will behave the same way as when the mouse button control is commented out. When the mouse button is released, the animation stops.

Note that with the mousePressed() function commented out, nothing will happen until the mouse first moves over the sketch.

The source code is below.

// Create the variables.
Point[]p = new Point[3];
float shift = 2.0;
float spin = 0;

// Setup the sketch.
void setup(){
size(800, 800);

void draw() {
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);

// Centre the spiral
translate(width/2, height/2);
//if (mousePressed && (mouseButton == LEFT)) {
spiral(mouseY, pmouseY, mouseX);

// Create the spiral function with 3 parameters.
void spiral(float shift1, float shift2, float shift3){

// Control the rotation of the spiral.
// Additional rotate()'s can be added for different effects.

// Define the fill colour.
float r = random(100, 255);
float g = random(100, 255);
float b = random(100, 255);
fill(r, g, b, 10);

// Create the triangle
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)));

// Determine the requirements for recursion.

// recursive call
spiral(shift1, shift2, shift3);

Tags: , , ,

2 Responses to “Mouse Controlled Kaleidoscope”

  1. Hiya! I know this is kinda off topic however , I’d figured I’d
    ask. Would you be interested in exchanging links or maybe guest writing a blog article or vice-versa?
    My blog addresses a lot of the same subjects as yours and
    I feel we could greatly benefit from each other. If you might be interested feel free
    to send me an e-mail. I look forward to hearing from you! Wonderful blog by
    the way!

    Feel free to visit my site – pawn shops near me open now

  2. Hi friends, how is the whole thing, and what you would like to say about this post, in my view its truly remarkable in support of me.

Leave a Reply