//Interactive drawing //Jesse Baker PROG14998 //Simple drawing program /* Instructions - Use any mouse button to draw on the canvas. - Click a colour of paint on the pallet to change brush colour. - Click one of the dots on the side panel to change brush size. - Click on the sun to clear the canvas. - The lighter tree leaves move with the mouse. */ color currentColour = color(0, 0, 0); //Stores the colour that the brush will use boolean drawLimit = true; //If true, the player cannot draw outside the canvas boolean canDraw = false; //If false, the user cannot draw int brushSize = 2; //Stores the brush size value void setup () { size (800, 800); //Basic Stuff frameRate(60); smooth(); reset(); //Start the reset function, which sets up the background art } void reset () { print("Reset"); rectMode(CENTER); //Center rects for easier placement background (220, 245, 245); //Light blue background fill(#498B23); //Green noStroke(); rect(400, 700, 800, 400);//The ground //The Stand strokeWeight(1); //Make sure the strokeWeight is set to default, as it changes later stroke(#C9B06A); //Light brown outline fill(#FFE6A2); //Light brown for the stand rotate(0.2); //Rotate is used to put the stand legs on an angle rect(350, 430, 100, 500); rotate(-0.4); rect(430, 600, 100, 500); //Make the stand rotate(0.2); rect(400, 630, 500, 50); rect(400, 250, 100, 400); //The Canvas fill(240, 240, 240); //Light grey rect(400, 350, 360, 510, 5); //Make the canvas shadow fill(255, 255, 255); //White noStroke(); rect(400, 350, 350, 500, 5); //Make the canvas //The Pallet noStroke(); fill(#482D09);//Dark Brown ellipse(135, 672, 244, 129);//Make the pallet shadow ellipse(170, 692, 204, 154); fill(#895F25); //brown ellipse(135, 670, 240, 125);//Make the pallet ellipse(170, 690, 200, 150); fill(#498B23); //background colour ellipse(105, 712, 25, 20); //Make the hole in the pallet ellipse(100, 710, 29, 17); fill(240, 0, 0); ellipse(70, 645, 40, 40); //red glob fill(0, 240, 0); ellipse(130, 638, 40, 40); //green glob fill(0, 0, 240); ellipse(190, 650, 40, 40); //blue glob fill(0, 0, 0); ellipse(235, 685, 40, 40); //black glob fill(255, 255, 255); ellipse(200, 730, 40, 40); //white glob //The Brush Size Selector stroke(0, 0, 0); rect(75, 300, 50, 150, 30); fill(0, 0, 0); ellipse(75, 260, 5, 5); //Brush size buttons ellipse(75, 300, 10, 10); ellipse(75, 340, 20, 20); } void draw () { //The Tree noStroke(); fill(#482D09);//Dark Brown quad(670, 600, 790, 600, 760, 400, 700, 380);//The Tree Shadow fill(#895F25); //brown quad(670, 600, 780, 600, 757, 400, 700, 380); //The Tree Trunk fill(#2C5D0E); //Dark Green ellipse(700, 400, 100, 100); fill(#498B23); //Green ellipse(701+mouseX/150, 395+mouseY/150, 90, 80); //The lighter parts of the tree move slightly with the mouse fill(#2C5D0E); //Dark Green ellipse(750, 350, 120, 150); fill(#2C5D0E); //Dark Green //The tree leaves ellipse(670, 340, 110, 100); fill(#498B23); //Green ellipse(751+mouseX/150, 345+mouseY/150, 110, 130); fill(#498B23); //Green ellipse(671+mouseX/150, 335+mouseY/150, 100, 90); fill(#2C5D0E); //Dark Green ellipse(700, 300, 100, 100); fill(#498B23); //Green ellipse(701+mouseX/150, 295+mouseY/150, 90, 80); noStroke(); fill(255, 230 - ((mouseY + mouseX)/40), 0); //Orange-yellow which changes slightly based on mouse position ellipse(30, 30, 100, 100); //Make the sun's outer ring fill(255, 255 - ((mouseY + mouseX)/40), 0);//Yellow which changes slightly based on mouse position ellipse(30, 30, 95, 95); //Make the sun fill(currentColour); //Set the brush colour to the selected colour if (drawLimit = true) { if (mouseX > 220 && mouseX < 580 && mouseY > 105 && mouseY < 605) { //Check to see if mouse is on the canvas canDraw = true; //If on the canvas, the user can draw } else { canDraw = false; } } else { canDraw = true; } //println(mouseX + ", " + mouseY + canDraw); //This debug line is for checking the draw restrictions and mouse position } void mouseDragged() { //When the user clicks and holds down the mouse button stroke(currentColour); //Set the brush colour strokeWeight(brushSize); //Brush thickness if (canDraw == true) { //If the mouse is on the canvas line(pmouseX, pmouseY, mouseX, mouseY); //Draw line } } void mousePressed() { //The following code executes lines based on where the mouse clicks if (mouseX > 50 && mouseX < 90 && mouseY > 625 && mouseY < 665) { //Red button println("R"); currentColour = color(240, 0, 0); //Red } else if (mouseX > 110 && mouseX < 150 && mouseY > 618 && mouseY < 658) {//Green button println("G"); currentColour = color(0, 240, 0);//Green } else if (mouseX > 170 && mouseX < 210 && mouseY > 630 && mouseY < 670) {//Blue button println("B"); currentColour = color(0, 0, 240);//Blue } else if (mouseX > 215 && mouseX < 255 && mouseY > 665 && mouseY < 705) {//Black button println("0"); currentColour = color(0, 0, 0);//Black } else if (mouseX > 180 && mouseX < 220 && mouseY > 710 && mouseY < 750) {//White button println("1"); currentColour = color(255, 255, 255);//White } else if (mouseX > 50 && mouseX < 100 && mouseY > 225 && mouseY < 275) {//Small Brush button println("SMALL"); brushSize = 2;//Set brush size to the smallest setting (Default) } else if (mouseX > 50 && mouseX < 100 && mouseY > 280 && mouseY < 320) {//Medium Brush button println("MID"); brushSize = 6;//Set brush size to the medium setting } else if (mouseX > 50 && mouseX < 100 && mouseY > 320 && mouseY < 370) {//Large Brush button println("BIG"); brushSize = 20;//Set brush size to the largest setting } else if (mouseX > 0 && mouseX < 75 && mouseY > 0 && mouseY < 75) {//Sun Reset button reset();//Clear the canvas } }