Now to see if I have the right idea here I played with the code a bit, this now has some interesting results.
/*
RGB Cube Mod
Here are some edits to get a framework
for understanding RGB Cube and starting
on the next step.
*/
float xmag, ymag = 0; //starting variables to define X and Y rotation
float newXmag, newYmag = 0; //Same but used to define new variables as the mouse moves
float i = 1;
void setup() {
//Setting up the 'field' at 800X400 with OpenGL (P3D)
size(800, 400, P3D);
// Setting colour values to simplify RGB, 0=0, 1=255
colorMode(RGB, 1);
stroke(1, 1, 1);}
void draw() {
i = i+0.01;
//sets grey value for background
background(0.5, 0.5, 0.45);
//From what I can tell this is a procedure call in a matrix
pushMatrix();
//Moving the draw function to the center of the form
translate(width/2, height/2, -30);
//This bit converts the mouse movement into 3d Rotation.
//Later I plan to freeze and hide the mouse for infinite free movement
//Converting mouse x and y into a value between 0 and PI
newXmag = mouseX/float(width) * TWO_PI;
newYmag = mouseY/float(height) * TWO_PI;
//making x/y mag = the new mouse x and y with a small amount of easing
float diff = xmag-newXmag;
if (abs(diff) > 0.01) {
xmag -= diff/4.0;
}
diff = ymag-newYmag;
if (abs(diff) > 0.01) {
ymag -= diff/4.0;
}
//the actual rotate functions
rotateX(-ymag);
rotateY(-xmag);
rotateZ(i);
//making the vertex (1,1,0) actually = (50,50,0) using scale
scale(50);
//Finally, drawing the shape!
//Note how easy it is to use 1 instead of 50 or 255 here.
noStroke();
beginShape(QUADS);
fill(0, 1, 1);
vertex(-1, 1, 0);
fill(1, 1, 1);
vertex( 1, 1, 0);
fill(1, 0, 1);
vertex( 1, -1, 0);
fill(0, 0, 0);
vertex(-1, -1, 0);
endShape();
fill(1, 1, 0);
sphere(0.5);
stroke(1, 1, 1);
sphere(20);
//Close procedure
popMatrix();
}
This produces a the entire image inside a sphere with the wires visible. The whole edifice is rotating around the center of the screen slowly. The next step here is to either start on the music synthesis code or start with the boids code. I think since the boids react to sound I should start there. IF all else fails the vector position will simply derive straight from the music. That would still look interesting even if boids prove too complex for me to understand =)
Heres the stripped code for me to start playing with boids.
/*
Boids!
*/
float xmag, ymag = 0;
float newXmag, newYmag = 0;
void setup() {
size(800, 400, P3D);
colorMode(RGB, 1);
stroke(1, 1, 1);
}
void draw() {
background(0.5, 0.5, 0.45);
pushMatrix();
translate(width/2, height/2, -30);
newXmag = mouseX/float(width) * TWO_PI;
newYmag = mouseY/float(height) * TWO_PI;
float diff = xmag-newXmag;
if (abs(diff) > 0.01) {
xmag -= diff/4.0;}
diff = ymag-newYmag;
if (abs(diff) > 0.01) {
ymag -= diff/4.0; }
rotateX(-ymag);
rotateY(-xmag);
popMatrix();
}
Labels:
Input Device,
Semester 2
Subscribe to:
Post Comments (Atom)
0 comments: