Computer Science Canada Paint Program Issue. |
Author: | Hasassin [ Mon May 25, 2009 9:44 pm ] |
Post subject: | Paint Program Issue. |
Hello everyone. I'm having an issue with my paint program i'm doing for a class assignment. I'm trying to get the pencil or freedraw tool to work, however, it only draws dots, and if I hold the mouse down, it doesn't draw lines, freely. Can anyone help me out? Thanks And here is the code: %screen size setscreen ("graphics:800;600") %procedure drawbutton down procedure buttonDraw (coordx, coordy, coordx2, coordy2, black : int) drawbox (coordx, coordy, coordx2, coordy2, black) drawfill (coordx + 1, coordy + 1, 8, black) end buttonDraw %procedure colour button procedure colourbutton (coordone, coordtwo, cordx2, cordy2, clr : int) drawbox (coordone, coordtwo, cordx2, cordy2, black) drawfill (coordone + 1, coordtwo + 1, 8, black) end colourbutton % declare variables var colournum, buttonnumber, buttonupdown : int var objectype, mousego : int var button : int var x, y, y2, x2 : int % Draw the main screen drawfillbox (0, 0, maxx, maxy, 100) % grey background drawfillbox (150, 80, maxx, 575, white) % white canvas % drawbox (150, 80, maxx, 50, black) % under the canvas %draw the buttons up, drawing a line function buttonDraw (0, 535, 130, 575, black) drawline (5, 540, 125, 570, black) buttonDraw (0, 490, 130, 530, black) drawoval (65, 510, 15, 15, black) buttonDraw (0, 445, 130, 485, black) drawbox (15, 450, 115, 480, black) buttonDraw (0, 400, 130, 440, black) drawmapleleaf (40, 405, 90, 435, black) buttonDraw (0, 355, 130, 395, black) Draw.Text ("Fill", 45, 360, Font.New ("serif:20:bold"), black) buttonDraw (0, 305, 130, 350, black) Draw.Text ("Pencil", 30, 315, Font.New ("serif:20:bold"), black) buttonDraw (0, 255, 130, 300, black) Draw.Text ("Erase", 30, 259, Font.New ("serif:20:bold"), black) buttonDraw (0, 205, 130, 250, black) Draw.Text ("Close", 30, 215, Font.New ("serif:20:bold"), black) % the colour buttons colourbutton (150, 50, 190, 80, black) drawfill (152, 52, red, black) colourbutton (195, 50, 240, 80, black) drawfill (202, 52, blue, black) colourbutton (245, 50, 285, 80, black) drawfill (257, 52, white, black) colourbutton (290, 50, 340, 80, black) drawfill (292, 52, grey, black) colourbutton (345, 50, 395, 80, black) drawfill (357, 52, purple, black) colourbutton (400, 50, 450, 80, black) drawfill (402, 52, yellow, black) colourbutton (455, 50, 505, 80, black) drawfill (457, 52, green, black) colourbutton (510, 50, 560, 80, black) drawfill (512, 52, 43, black) % LOOP View.Update loop % IF user clicks on one of the drawing tools THEN if Mouse.ButtonMoved ("down") then Mouse.ButtonChoose ("singlebutton") Mouse.ButtonWait ("down", x, y, x2, y2) if (x > 1 and x2 < 574) and (y > 536 and y2 < 574) then drawline (0, 575, 130, 575, black) drawline (0, 535, 0, 575, black) drawline (130, 535, 130, 575, white) drawline (0, 535, 130, 535, white) objectype := 1 elsif (x > 150 and x2 < maxx) and (y > 80 and y2 < 575) then View.ClipSet (150, 80, maxx, 575) mousewhere (x, y, button) Draw.Dot (x, y, black) end if end if end loop |
Author: | DemonWasp [ Mon May 25, 2009 11:57 pm ] |
Post subject: | RE:Paint Program Issue. |
The problem is that your mouse can move multiple pixels before you're able to get its location again. What you should do to fix this is make the simple interpolation that the mouse travelled along a straight line between the current position and the last position. Save the last position and just draw a line to it instead of Draw.Dot(). |