how to draw 3 brush on mouse dragged
in
Programming Questions
•
2 years ago
Hi i am this assignment where i have to draw 3 brushes on mouse dragged and they should alter between 1 2 and third brush as i am dragging my mouse. I know it sounds simple but i racking my brain to sort this out but i am having difficulty doing this part. Here is my code. I need help asap.
- //Global var
- int brushSize = 50; //brushSize
- //------------------------------------------------------------------------------------------------
- //Initialising the functions
- //Defining the dimension of the display,
- //background and color settings
- //------------------------------------------------------------------------------------------------
- void setup() {
- smooth();
- size(500, 500);
- background(255);
- }
- //------------------------------------------------------------------------------------------------
- // Function Brush from 3.1
- //------------------------------------------------------------------------------------------------
- void brush(int xPos, int yPos) {
- fill(0, 0, 219);
- ellipse(xPos, yPos, brushSize, brushSize);
- }
- //------------------------------------------------------------------------------------------------
- // Function for drawing brush from 3.1
- //------------------------------------------------------------------------------------------------
- void brush2(int xPos, int yPos) {
- fill(0, 249, 219);
- rect(xPos, yPos, brushSize, brushSize);
- }
- //------------------------------------------------------------------------------------------------
- // Function for drawing third brush
- //------------------------------------------------------------------------------------------------
- void brush3(int xPos, int yPos) {
- fill(0, 249, 219);
- triangle(xPos, yPos, xPos, yPos, brushSize, brushSize);
- }
- //------------------------------------------------------
- // Function for drawing 2nd brush on mouse released
- //------------------------------------------------------
- void mousePressed () {
- brushRec(mouseX, mouseY);
- }
- //--------------------------------------------------
- // Function for drawing brush on mouse released
- //--------------------------------------------------
- void mouseReleased () {
- brush(mouseX, mouseY);
- }
- //--------------------------------------------
- // check if the space bar is pressed
- //if yes, clear the screen
- //--------------------------------------------
- void draw() {
- if (keyPressed)
- if (key == ' ')
- background(255);
- }
1