creating class variables :P
in
Programming Questions
•
3 years ago
hey everybody :D
I'm a noob in search of some assistance
I have to write a sketch that will do these things -
- The sketch draws a three-dimensional cube in the center of the screen.
- The cube rotates as the mouse is moved. It should rotate in the same direction as the mouse moves, left-right and up-down.
- The cube becomes larger and changes color whenever the user presses a key on the keyboard. A sound effect of your choice (something like a stretching sound) should play whenever the cube gets larger.
- The sketch should play some music in a continuous loop the whole time it's running.
Now, I have made a lot of progress on this assignment
I have made a cube, it does rotate, it does change color with every key pressed, it does play a sound effect, and it does play music in a loop.
The only problem is that I don't know how to assign a class variable to the size of the box, and I don't know how to make the box bigger with each key pressed. Could you guys help me out?
Here's the code for reference purposes. Thanks again
- import ddf.minim.*;
- import ddf.minim.signals.*;
- import ddf.minim.analysis.*;
- import ddf.minim.effects.*;
- Minim loader;
- AudioPlayer player;
- //size of the box
- float aa = 150;
- void setup() {
- size (600, 600, P3D);
- //audio player
- loader = new Minim(this);
- player = loader.loadFile("cali.mp3");
- player.loop();
- }
- void draw() {
- background(51);
- //rotating and placing the cube , map method
- translate(width/2, height/2);
- //rotate about the x axis
- float a = map(-1 * mouseY, 0, (width-1), 0, 2 * PI);
- rotateX(a);
- //rotate about the y axis
- float b = map(-1 * mouseX, 0, (height-1), 0, 2 * PI);
- rotateY(b);
- //cube size and coloring
- box(aa);
- if (keyPressed == true){
- fill (random (255), random (255), random (255));
- //plays the sound effect "bubble pop"
- player = loader.loadFile("bubblepop.mp3");
- player.play();
- box(aa + 34);
- }
- }
- //void mouseClicked() {
- //plays the sound effect "bubble pop"
- // player = loader.loadFile("bubblepop.mp3");
- // player.play();
- //}
1
