Ugh... I'm not even sure if what I wrote above makes sense...
I am currently trying to use this code that I programmed procedurally (which creates a randomly colored rectangle when the mouse is clicked or pressed down and ends when a keyboard button is pressed), into code that uses classes.
I am having some trouble though. I am tinkering away and am almost there I think, which is a special thing because I am actually proud of how much I have done here. Anyway...
Here's the code for the procedural:
AND...
Here's the code for the class version:
Please be kind and know that I am extremely new to this.
2 questions:
1st: ANY POINTERS?
2nd: Hot or cold?
I am currently trying to use this code that I programmed procedurally (which creates a randomly colored rectangle when the mouse is clicked or pressed down and ends when a keyboard button is pressed), into code that uses classes.
I am having some trouble though. I am tinkering away and am almost there I think, which is a special thing because I am actually proud of how much I have done here. Anyway...
Here's the code for the procedural:
- //CODE STARTS HERE.
- void setup(){
- size (800,800);
- smooth();
- background(0);
- }
- void draw() {
- if (mousePressed==true) {
- //if mouse is pressed in
- fill(random (0,255),random (0,255),random (0,255));
- //multiple changing colours rectangle/square
- rect(mouseX, mouseY, 300, 300);
- //draw a rectangle/square at mouseX and mouseY position
- }
- if (keyPressed == true) {
- //if key is pressed
- background(0);
- //background redrawn and the rectangle/square is drawn over with black
- noLoop();
- //draw loop stops.
- }
- }
- //CODE ENDS HERE.
AND...
Here's the code for the class version:
- //CODE STARTS HERE.
- Rectangle rectangle1;
- void setup() {
- size (900,700);
- smooth();
- background(0);
- rectangle1 = new Rectangle();
- }
- void draw(){
- background(0);
- rectangle1.update();
- rectangle1.drawme();
- }
- //void mouseClicked() {
- //}
- class Rectangle{
- float xpos, ypos, coloration;
- Rectangle () {
- xpos = mouseX;
- ypos = mouseY;
- coloration = (random (0,255), random (0,255), random (0,255));
- }
- void update() {
- }
- void drawMe (){
- if (mousePressed==true) {
- //if mouse is pressed in
- fill(coloration);
- //multiple changing colours rectangle/square
- rect(xpos, ypos, 300, 300);
- //draw a rectangle/square at mouseX and mouseY position
- }
- if (keyPressed == true) {
- //if key is pressed
- background(0);
- //background redrawn and the rectangle/square is drawn over with black
- noLoop();
- }
- }
- //CODE ENDS HERE.
Please be kind and know that I am extremely new to this.
2 questions:
1st: ANY POINTERS?
2nd: Hot or cold?
1