//
// uses mouseX - stores the current x location of the mouse
// uses pmouseX - stores the previous x location of mouse
// calc difference and rotate a rectangle according to this value
//
// NOTE using transformations
// to update a transformation
// 1. reset the matrix each time
// resetMatrix(); loads unity matrix
// 2. position the origin screen center
// translate(width/2, height/2);
// 3. apply rotation in radians
// rotate(radians(tot_ang));
//
// april 2013
//
int tot_ang = 0; // set up global variables
int r = 255; // 3 RGB colours
int g = 0;
int b = 0;
int r_inc = -5; // colour increments
int g_inc = 5;
int b_inc = 5;
void setup()
{
size(500, 500);
colorMode(RGB, 1.0);
stroke(256 , 0 , 0); // red outline
rectMode(CENTER); // draw rect about its center
background(255, 255, 0); // yellow - clears screen each time
fill(r,g,b); // rect fill col 255,0,0 (red)
rect(0,0,50,50); // draw rect
smooth();
}
void draw()
{
int val;
val = mouseX - pmouseX; // current mouse - previous mouse x movement
if (val!=0)
{
rotate_rect(val);
}
}
void rotate_rect(int v)
{
background(255, 255, 0); // yellow - clears screen each time
tot_ang += v;
resetMatrix();
translate(width/2, height/2); // position origin in screen center
rotate(radians(tot_ang)); // set rotation
r -= 2;
if (r<0) r = 0;
fill(r,g,b); // fill rect
rect(0,0,50,50); // draw rect
}