Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Paint Program
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
neufelni




PostPosted: Wed Sep 28, 2005 7:38 am   Post subject: Paint Program

Here is a paint program that I made. I hope you all enjoy it.
code:
%Nick Neufeld
%09/26/05
%Paint

%****************   Sets the screen size/options   ****************************
View.Set ("graphics: max; max, nobuttonbar, nocursor")

%****************   Variables and their values    *****************************
var x, y, b, s, c, f, sh : int
c := 0
s := 5
f := Font.New ("Times New Roman:18")
sh := 1

%****************   Draws the colour menu    **********************************
Font.Draw ("Color", 2, 2, f, 7)
Draw.Box (0, 0, 59, 20, 7)
Draw.FillBox (60, 0, 80, 20, 0)
Draw.FillBox (80, 0, 100, 20, 1)
Draw.FillBox (100, 0, 120, 20, 2)
Draw.FillBox (120, 0, 140, 20, 3)
Draw.FillBox (140, 0, 160, 20, 4)
Draw.FillBox (160, 0, 180, 20, 5)
Draw.FillBox (180, 0, 200, 20, 6)
Draw.FillBox (200, 0, 220, 20, 7)
Draw.FillBox (220, 0, 240, 20, 8)
Draw.FillBox (240, 0, 260, 20, 9)
Draw.FillBox (260, 0, 280, 20, 10)
Draw.FillBox (280, 0, 300, 20, 11)
Draw.FillBox (300, 0, 320, 20, 12)
Draw.FillBox (320, 0, 340, 20, 13)
Draw.FillBox (340, 0, 360, 20, 14)
Draw.FillBox (360, 0, 380, 20, 15)
Draw.Box (0, 0, maxx, 20, 7)

%***************   Draws the brush size menu    *******************************
Font.Draw ("Size", 2, 30, f, 7)
Draw.Box (0, 0, maxx, 60, 7)
Draw.Box (0, 20, 59, 60, 7)
Draw.Box (59, 20, 100, 60, 7)
Draw.FillOval (80, 40, 1, 1, 7)
Draw.Box (100, 20, 140, 60, 7)
Draw.FillOval (120, 40, 2, 2, 7)
Draw.Box (140, 20, 180, 60, 7)
Draw.FillOval (160, 40, 3, 3, 7)
Draw.Box (180, 20, 220, 60, 7)
Draw.FillOval (200, 40, 4, 4, 7)
Draw.Box (220, 20, 260, 60, 7)
Draw.FillOval (240, 40, 5, 5, 7)
Draw.Box (260, 20, 300, 60, 7)
Draw.FillOval (280, 40, 6, 6, 7)
Draw.Box (300, 20, 340, 60, 7)
Draw.FillOval (320, 40, 7, 7, 7)
Draw.Box (340, 20, 380, 60, 7)
Draw.FillOval (360, 40, 8, 8, 7)
Draw.Box (380, 20, 420, 60, 7)
Draw.FillOval (400, 40, 9, 9, 7)
Draw.Box (420, 20, 460, 60, 7)
Draw.FillOval (440, 40, 10, 10, 7)
Draw.Box (460, 20, 500, 60, 7)
Draw.FillOval (480, 40, 11, 11, 7)
Draw.Box (500, 20, 540, 60, 7)
Draw.FillOval (520, 40, 12, 12, 7)
Draw.Box (540, 20, 580, 60, 7)
Draw.FillOval (560, 40, 13, 13, 7)
Draw.Box (580, 20, 620, 60, 7)
Draw.FillOval (600, 40, 14, 14, 7)
Draw.Box (620, 20, 660, 60, 7)
Draw.FillOval (640, 40, 15, 15, 7)
Draw.Box (660, 20, 700, 60, 7)
Draw.FillOval (680, 40, 16, 16, 7)
Draw.Box (700, 20, 740, 60, 7)
Draw.FillOval (720, 40, 17, 17, 7)
Draw.Box (740, 20, 780, 60, 7)
Draw.FillOval (760, 40, 18, 18, 7)
Draw.Box (780, 20, 820, 60, 7)
Draw.FillOval (800, 40, 19, 19, 7)
Draw.Box (820, 20, 860, 60, 7)
Draw.FillOval (840, 40, 20, 20, 7)

%****************    Draws the brush shape menu        ************************
Draw.Box (0, 60, maxx, 90, 7)
Draw.Box (0, 60, 59, 90, 7)
Font.Draw ("Shape", 2, 65, f, 7)
Draw.Box (59, 60, 90, 90, 7)
Draw.FillOval (75, 75, 10, 10, 7)
Draw.Box (90, 60, 120, 90, 7)
Draw.FillBox (95, 65, 115, 85, 7)
Draw.Box (120, 60, 150, 90, 7)
Draw.FillStar (125, 65, 145, 85, 7)
Draw.Box (150, 60, 180, 90, 7)
Draw.FillMapleLeaf (155, 65, 175, 85, 7)
Draw.Box (180, 60, 210, 90, 7)
Draw.FillOval (195, 75, 10, round (10 / 3), 7)
Draw.Box (210, 60, 240, 90, 7)
Draw.FillOval (225, 75, round (10 / 3), 10, 7)

%*************   Allows the user to use mouse in program    *******************
loop
    Mouse.Where (x, y, b) 

%***************    Allows user to choose color   *****************************
    if b = 1 and x > 60 and x < 80 and y < 20 then
        c := 0
    end if
    if b = 1 and x > 80 and x < 100 and y < 20 then
        c := 1
    end if
    if b = 1 and x > 100 and x < 120 and y < 20 then   
        c := 2
    end if
    if b = 1 and x > 120 and x < 140 and y < 20 then 
        c := 3
    end if
    if b = 1 and x > 140 and x < 160 and y < 20 then
        c := 4
    end if
    if b = 1 and x > 160 and x < 180 and y < 20 then   
        c := 5
    end if
    if b = 1 and x > 180 and x < 200 and y < 20 then 
        c := 6
    end if
    if b = 1 and x > 200 and x < 220 and y < 20 then
        c := 7
    end if
    if b = 1 and x > 220 and x < 240 and y < 20 then
        c := 8
    end if
    if b = 1 and x > 240 and x < 260 and y < 20 then
        c := 9
    end if
    if b = 1 and x > 260 and x < 280 and y < 20 then
        c := 10
    end if
    if b = 1 and x > 280 and x < 300 and y < 20 then 
        c := 11
    end if
    if b = 1 and x > 300 and x < 320 and y < 20 then
        c := 12
    end if
    if b = 1 and x > 320 and x < 340 and y < 20 then 
        c := 13
    end if
     if b = 1 and x > 340 and x < 360 and y < 20 then   
        c := 14
    end if
    if b = 1 and x > 360 and x < 380 and y < 20 then
        c := 15
    end if
   
%************    Allows the user to choose brush size   ***********************
    if b = 1 and x > 60 and x < 100 and y > 20 and y < 60 then
        s := 1
    end if
    if b = 1 and x > 100 and x < 140 and y > 20 and y < 60 then
        s := 2
    end if
    if b = 1 and x > 140 and x < 180 and y > 20 and y < 60 then
        s := 3
    end if
    if b = 1 and x > 180 and x < 220 and y > 20 and y < 60 then
        s := 4
    end if
    if b = 1 and x > 220 and x < 260 and y > 20 and y < 60 then
        s := 5
    end if
    if b = 1 and x > 260 and x < 300 and y > 20 and y < 60 then
        s := 6
    end if
    if b = 1 and x > 300 and x < 340 and y > 20 and y < 60 then
        s := 7
    end if
    if b = 1 and x > 340 and x < 380 and y > 20 and y < 60 then
        s := 8
    end if
    if b = 1 and x > 380 and x < 420 and y > 20 and y < 60 then
        s := 9
    end if
    if b = 1 and x > 420 and x < 460 and y > 20 and y < 60 then
        s := 10
    end if
    if b = 1 and x > 460 and x < 500 and y > 20 and y < 60 then
        s := 11
    end if 
    if b = 1 and x > 500 and x < 540 and y > 20 and y < 60 then
        s := 12
    end if
    if b = 1 and x > 540 and x < 580 and y > 20 and y < 60 then
        s := 13
    end if
    if b = 1 and x > 580 and x < 620 and y > 20 and y < 60 then
        s := 14
    end if
    if b = 1 and x > 620 and x < 660 and y > 20 and y < 60 then
        s := 15
    end if
    if b = 1 and x > 660 and x < 700 and y > 20 and y < 60 then
        s := 16
    end if
     if b = 1 and x > 700 and x < 740 and y > 20 and y < 60 then
        s := 17
    end if
    if b = 1 and x > 740 and x < 780 and y > 20 and y < 60 then
        s := 18
    end if
    if b = 1 and x > 780 and x < 820 and y > 20 and y < 60 then
        s := 19
    end if
    if b = 1 and x > 820 and x < 860 and y > 20 and y < 60 then
        s := 20
    end if
   
%***************   Allows the user to choose the brush shape    ***************
if b = 1  and x > 60 and x < 90 and y > 60 and y < 90 then
    sh := 1
end if
if b = 1  and x > 90 and x < 120 and y > 60 and y < 90 then
    sh := 2
end if
if b = 1  and x > 120 and x < 150 and y > 60 and y < 90 then
    sh := 3
end if
if b = 1  and x > 150 and x < 180 and y > 60 and y < 90 then
    sh := 4
end if
if b = 1  and x > 180 and x < 210 and y > 60 and y < 90 then
    sh := 5
end if
if b = 1  and x > 210 and x < 240 and y > 60 and y < 90 then
    sh := 6
end if


%**************    Allows the user to paint ***********************************
    if b = 1 and sh = 1 and y - s > 90 then   
        Draw.FillOval (x, y, s, s, c) 
    end if
    if b = 1 and sh = 2 and y - s > 90 then     
        Draw.FillBox (x - s, y - s, x + s, y + s, c) 
    end if
    if b = 1 and sh = 3 and y - s > 90 then   
        Draw.FillStar (x - s, y - s, x + s, y + s, c) 
    end if
    if b = 1 and sh = 4 and y - s > 90 then   
        Draw.FillMapleLeaf (x - s, y - s, x + s, y + s, c) 
    end if
    if b = 1 and sh = 5 and y - s > 90 then   
        Draw.FillOval (x, y, s, round (s / 3), c) 
    end if
    if b = 1 and sh = 6 and y - s > 90 then   
        Draw.FillOval (x, y, round (s / 3), s, c) 
    end if
end loop

Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Wed Sep 28, 2005 11:18 am   Post subject: (No subject)

Thats a good little start to making a paint program. You should search for other paint programs on compsci (using the search tool at the top) to learn different techniques. Good work tho.
wtd




PostPosted: Thu Sep 29, 2005 12:38 pm   Post subject: (No subject)

code:
    if b = 1 and x > 60 and x < 80 and y < 20 then
        c := 0
    end if
    if b = 1 and x > 80 and x < 100 and y < 20 then
        c := 1
    end if
    if b = 1 and x > 100 and x < 120 and y < 20 then   
        c := 2
    end if
    if b = 1 and x > 120 and x < 140 and y < 20 then 
        c := 3
    end if
    if b = 1 and x > 140 and x < 160 and y < 20 then
        c := 4
    end if
    if b = 1 and x > 160 and x < 180 and y < 20 then   
        c := 5
    end if
    if b = 1 and x > 180 and x < 200 and y < 20 then 
        c := 6
    end if
    if b = 1 and x > 200 and x < 220 and y < 20 then
        c := 7
    end if
    if b = 1 and x > 220 and x < 240 and y < 20 then
        c := 8
    end if
    if b = 1 and x > 240 and x < 260 and y < 20 then
        c := 9
    end if
    if b = 1 and x > 260 and x < 280 and y < 20 then
        c := 10
    end if
    if b = 1 and x > 280 and x < 300 and y < 20 then 
        c := 11
    end if
    if b = 1 and x > 300 and x < 320 and y < 20 then
        c := 12
    end if
    if b = 1 and x > 320 and x < 340 and y < 20 then 
        c := 13
    end if
     if b = 1 and x > 340 and x < 360 and y < 20 then   
        c := 14
    end if
    if b = 1 and x > 360 and x < 380 and y < 20 then
        c := 15
    end if


Regular increments in your test against "x" paired with regular increments in "c". This calls for math, not lengthy conditional sttements. Smile

code:
if b = 1 and x > 60 and x < 380 and y < 20 then
   c := (x - 60) div 20
end if


Three lines of code, rather than forty-eight. Wink
wtd




PostPosted: Thu Sep 29, 2005 12:45 pm   Post subject: (No subject)

code:
Draw.FillOval (80, 40, 1, 1, 7)
Draw.Box (100, 20, 140, 60, 7)
Draw.FillOval (120, 40, 2, 2, 7)
Draw.Box (140, 20, 180, 60, 7)
Draw.FillOval (160, 40, 3, 3, 7)
Draw.Box (180, 20, 220, 60, 7)
Draw.FillOval (200, 40, 4, 4, 7)
Draw.Box (220, 20, 260, 60, 7)
Draw.FillOval (240, 40, 5, 5, 7)
Draw.Box (260, 20, 300, 60, 7)
Draw.FillOval (280, 40, 6, 6, 7)
Draw.Box (300, 20, 340, 60, 7)
Draw.FillOval (320, 40, 7, 7, 7)
Draw.Box (340, 20, 380, 60, 7)
Draw.FillOval (360, 40, 8, 8, 7)
Draw.Box (380, 20, 420, 60, 7)
Draw.FillOval (400, 40, 9, 9, 7)
Draw.Box (420, 20, 460, 60, 7)
Draw.FillOval (440, 40, 10, 10, 7)
Draw.Box (460, 20, 500, 60, 7)
Draw.FillOval (480, 40, 11, 11, 7)
Draw.Box (500, 20, 540, 60, 7)
Draw.FillOval (520, 40, 12, 12, 7)
Draw.Box (540, 20, 580, 60, 7)
Draw.FillOval (560, 40, 13, 13, 7)
Draw.Box (580, 20, 620, 60, 7)
Draw.FillOval (600, 40, 14, 14, 7)
Draw.Box (620, 20, 660, 60, 7)
Draw.FillOval (640, 40, 15, 15, 7)
Draw.Box (660, 20, 700, 60, 7)
Draw.FillOval (680, 40, 16, 16, 7)
Draw.Box (700, 20, 740, 60, 7)
Draw.FillOval (720, 40, 17, 17, 7)
Draw.Box (740, 20, 780, 60, 7)
Draw.FillOval (760, 40, 18, 18, 7)
Draw.Box (780, 20, 820, 60, 7)
Draw.FillOval (800, 40, 19, 19, 7)
Draw.Box (820, 20, 860, 60, 7)


vs.

code:
for i : 0 .. 18
   Draw.FillOval (80 + i * 40, 40, i + 1, i + 1, 7)
   Draw.Box (100 + i * 40, 20, 140 + i * 40, 60, 7)
end for


Thirty-eight lines... or four.
neufelni




PostPosted: Sat Oct 01, 2005 3:46 pm   Post subject: (No subject)

Thanks for that wtd.
I have been trying to add a fill tool to my program but I can't seem to figure it out. I can make it fill an area that I draw, but only if it is drawn with one certain color by using this code:
code:
Draw.Fill (x, y, c, 7)

I tried using code like this:
code:

var wdc : int := 0



wdc := whatdotcolor (x, y) %This determines color of x and y when I click.
Draw.Fill (x, y, c, whatdotcolor not = wdc)

This however does not work. Can anyone help me.
Cervantes




PostPosted: Sat Oct 01, 2005 7:28 pm   Post subject: (No subject)

You can make your own Draw.Fill-esque procedure using a little recursion. There's an excellent tutorial on recursion by zylum.

Something like this:
code:

proc fill (x, y, c, boarder_c : int)

    if whatdotcolour (x, y) not= cboarder_c then
          Draw.Dot (x, y, c)
          fill (x + 1, y, c, boarder_c)
          fill (x - 1, y, c, boarder_c)
          fill (x, y + 1, c, boarder_c)
          fill (x, y - 1, c, boarder_c)
    end if

end fill

Now you can modify that to suite your needs.
Lapsus Antepedis




PostPosted: Mon Oct 03, 2005 11:31 am   Post subject: (No subject)

EDIT: I Have noticed that the following problem only occurs when i run this code at school, I re-wrote it at home, and it worked fine. How odd...

I hate to say it Cervantes, but your code doesn't work! Sad (oddly enough, I came up with nearly identical code a few minutes ago, but my variable names were different Shocked )

Your procedure almost does what it is supposed to, but it never seems to call the other three procedures, so it functions as if you had written this:
code:
proc fill (x, y, c, boarder_c : int)

    if whatdotcolour (x, y) not= boarder_c then
        Draw.Dot (x, y, c)
        fill (x + 1, y, c, boarder_c)
    end if

end fill


instead of this:
code:
proc fill (x, y, c, boarder_c : int)

    if whatdotcolour (x, y) not= boarder_c then
        Draw.Dot (x, y, c)
        fill (x + 1, y, c, boarder_c)
        fill (x - 1, y, c, boarder_c)
        fill (x, y + 1, c, boarder_c)
        fill (x, y - 1, c, boarder_c)
    end if

end fill


I have no idea what is causing this, but it is definetly odd behaviour.

PS: I fixed your typo in the code, "cboarder_c" on line 3 Razz
neufelni




PostPosted: Wed Oct 05, 2005 7:29 am   Post subject: (No subject)

I also noticed that this code was not working. Can anyone give me some code that does work? I am also trying to make a line drawing tool that I need help with.
Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Wed Oct 05, 2005 7:59 am   Post subject: (No subject)

Nick wrote:
I am also trying to make a line drawing tool that I need help with.

Look up "drawline" and "Draw.ThickLine" in F10
neufelni




PostPosted: Wed Oct 05, 2005 11:07 am   Post subject: (No subject)

jamonathin wrote:
Nick wrote:
I am also trying to make a line drawing tool that I need help with.

Look up "drawline" and "Draw.ThickLine" in F10

I understand how to draw a line. What I do not understand is how to allow the user to draw a line using the mouse. This is the code that I have for it so far:
code:
var x, y, b, x2, y2 : int

loop
    Mouse.Where (x, y, b)
    if b = 1 then
        Draw.Line (100, 100, x, y, 7)
        Draw.Line (100, 100, x, y, 0)
    end if
    if b = 1 then
    end if
end loop
jamonathin




PostPosted: Wed Oct 05, 2005 11:37 am   Post subject: (No subject)

Here's a program that'll draw a bunch of line using the mouse.

You'll see 'offscreenonly' and 'View.Update' are used. They're there for smooth animation. Try taking them out and see what it looks like.

Basically what this program does is it saves the data points of where the mouse is clicked, and itdraws them in a procedure.

Turing:

setscreen ("graphics:max;max,nobuttonbar,offscreenonly")
var mx, my, mz : int %mouse vars
var x, y : flexible array 1 .. 0 of int %flexible means we can change how big the array is
proc refresh
    cls
    if upper (x) >= 1 then %only goes when we have at least one coordinate
        drawline (mx, my, x (upper (x)), y (upper (y)), black) %drawing that trailing line
    end if
    if upper (x) > 1 then %only goes when we have at least two coordinates
        for i : 2 .. upper (x) %draws the saved line below
            drawline (x (i - 1), y (i - 1), x (i), y (i), black)
        end for
    end if
    View.Update
end refresh

loop
    mousewhere (mx, my, mz)
    if mz = 1 then %if we click . .
        new x, upper (x) + 1 %make the upper of x larger by 1
        new y, upper (y) + 1 %make the upper of y larger by 1
        x (upper (x)) := mx %make the new upper value equal to the mouse
        y (upper (y)) := my
    end if
    refresh %refer to refresh proc
    delay (10)
    exit when hasch %exit when any keyboard button is pressed
end loop
codemage




PostPosted: Wed Oct 05, 2005 12:41 pm   Post subject: (No subject)

This code draws a line with click, drag, unclick - using a boolean flag.
From your code, it looked like you want to do a click-move-click linedraw; you'll have to edit the code appropriately to accomplish that.


code:

%line drawing - by codemage - example for Nick

var mousex, mousey, b, x1, y1 : int
var linestarted : boolean := false

loop
    Mouse.Where (mousex, mousey, b) %keep track of mouse button status
    if b = 1 and not linestarted then %a click starts a line
        linestarted := true
        x1 := mousex
        y1 := mousey

    elsif b = 0 and linestarted then %letting go of button draws the line
        linestarted := false
        Draw.Line (x1, y1, mousex, mousey, black)
    end if
end loop


neufelni




PostPosted: Fri Oct 07, 2005 7:31 am   Post subject: (No subject)

Thanks codemage. Your code was better for my program. I changed it a bit to also make a box and oval tool. Here is an update of my program.
[code%Nick Neufeld
%09/26/05
%Paint

%**************** Variables and their values *****************************
var x, y, b, s, c, f, sh, t, x2, y2, paintwin, helpwin : int
var lstart, bstart, ostart : boolean
lstart := false
bstart := false
ostart := false
c := 0
s := 5
f := Font.New ("Times New Roman:18")
sh := 1
t := 1

%**************** Sets the screen size/options ****************************
paintwin := Window.Open ("graphics: max; max, nobuttonbar, nocursor")

%**************** Draws the colour menu **********************************
Font.Draw ("Color", 2, 2, f, 7)
Draw.Box (0, 0, 59, 20, 7)
Draw.FillBox (60, 0, 80, 20, 0)
Draw.FillBox (80, 0, 100, 20, 1)
Draw.FillBox (100, 0, 120, 20, 2)
Draw.FillBox (120, 0, 140, 20, 3)
Draw.FillBox (140, 0, 160, 20, 4)
Draw.FillBox (160, 0, 180, 20, 5)
Draw.FillBox (180, 0, 200, 20, 6)
Draw.FillBox (200, 0, 220, 20, 7)
Draw.FillBox (220, 0, 240, 20, 8)
Draw.FillBox (240, 0, 260, 20, 9)
Draw.FillBox (260, 0, 280, 20, 10)
Draw.FillBox (280, 0, 300, 20, 11)
Draw.FillBox (300, 0, 320, 20, 12)
Draw.FillBox (320, 0, 340, 20, 13)
Draw.FillBox (340, 0, 360, 20, 14)
Draw.FillBox (360, 0, 380, 20, 15)
Draw.Box (0, 0, maxx, 20, 7)

%*************** Draws the brush size menu *******************************
Font.Draw ("Size", 2, 30, f, 7)
Draw.Box (0, 0, maxx, 60, 7)
Draw.Box (0, 20, 59, 60, 7)
Draw.Box (59, 20, 100, 60, 7)
Draw.FillOval (80, 40, 1, 1, 7)
Draw.Box (100, 20, 140, 60, 7)
Draw.FillOval (120, 40, 2, 2, 7)
Draw.Box (140, 20, 180, 60, 7)
Draw.FillOval (160, 40, 3, 3, 7)
Draw.Box (180, 20, 220, 60, 7)
Draw.FillOval (200, 40, 4, 4, 7)
Draw.Box (220, 20, 260, 60, 7)
Draw.FillOval (240, 40, 5, 5, 7)
Draw.Box (260, 20, 300, 60, 7)
Draw.FillOval (280, 40, 6, 6, 7)
Draw.Box (300, 20, 340, 60, 7)
Draw.FillOval (320, 40, 7, 7, 7)
Draw.Box (340, 20, 380, 60, 7)
Draw.FillOval (360, 40, 8, 8, 7)
Draw.Box (380, 20, 420, 60, 7)
Draw.FillOval (400, 40, 9, 9, 7)
Draw.Box (420, 20, 460, 60, 7)
Draw.FillOval (440, 40, 10, 10, 7)
Draw.Box (460, 20, 500, 60, 7)
Draw.FillOval (480, 40, 11, 11, 7)
Draw.Box (500, 20, 540, 60, 7)
Draw.FillOval (520, 40, 12, 12, 7)
Draw.Box (540, 20, 580, 60, 7)
Draw.FillOval (560, 40, 13, 13, 7)
Draw.Box (580, 20, 620, 60, 7)
Draw.FillOval (600, 40, 14, 14, 7)
Draw.Box (620, 20, 660, 60, 7)
Draw.FillOval (640, 40, 15, 15, 7)
Draw.Box (660, 20, 700, 60, 7)
Draw.FillOval (680, 40, 16, 16, 7)
Draw.Box (700, 20, 740, 60, 7)
Draw.FillOval (720, 40, 17, 17, 7)
Draw.Box (740, 20, 780, 60, 7)
Draw.FillOval (760, 40, 18, 18, 7)
Draw.Box (780, 20, 820, 60, 7)
Draw.FillOval (800, 40, 19, 19, 7)
Draw.Box (820, 20, 860, 60, 7)
Draw.FillOval (840, 40, 20, 20, 7)

%**************** Draws the brush shape menu ************************
Draw.Box (0, 60, maxx, 90, 7)
Draw.Box (0, 60, 59, 90, 7)
Font.Draw ("Shape", 2, 65, f, 7)
Draw.Box (59, 60, 90, 90, 7)
Draw.FillOval (75, 75, 10, 10, 7)
Draw.Box (90, 60, 120, 90, 7)
Draw.FillBox (95, 65, 115, 85, 7)
Draw.Box (120, 60, 150, 90, 7)
Draw.FillStar (125, 65, 145, 85, 7)
Draw.Box (150, 60, 180, 90, 7)
Draw.FillMapleLeaf (155, 65, 175, 85, 7)
Draw.Box (180, 60, 210, 90, 7)
Draw.FillOval (195, 75, 10, round (10 / 3), 7)
Draw.Box (210, 60, 240, 90, 7)
Draw.FillOval (225, 75, round (10 / 3), 10, 7)

%**************** Draws the tool menu ************************************
Font.Draw ("Tool", 2, 92, f, 7)
Draw.Box (0, 90, maxx, 115, 7)
Draw.Box (0, 90, 59, 115, 7)
Font.Draw ("Brush", 62, 92, f, 7)
Draw.Box (59, 90, 120, 115, 7)
Font.Draw ("Fill", 125, 92, f, 7)
Draw.Box (120, 90, 165, 115, 7)
Font.Draw ("Spray", 170, 92, f, 7)
Draw.Box (165, 90, 230, 115, 7)
Font.Draw ("Line", 235, 92, f, 7)
Draw.Box (230, 90, 290, 115, 7)
Font.Draw ("Box", 295, 92, f, 7)
Draw.Box (290, 90, 350, 115, 7)
Font.Draw ("Oval", 355, 92, f, 7)
Draw.Box (350, 90, 410, 115, 7)

%******************** Draws the help option ******************************
Font.Draw ("Help", 755, 92, f, 7)
Draw.Box (750, 90, 800, 115, 7)

%************* Allows the user to use mouse in program *******************
loop
Mouse.Where (x, y, b)

%*************** Allows user to choose color *****************************
if b = 1 and x > 60 and x < 80 and y < 20 then
c := 0
end if
if b = 1 and x > 80 and x < 100 and y < 20 then
c := 1
end if
if b = 1 and x > 100 and x < 120 and y < 20 then
c := 2
end if
if b = 1 and x > 120 and x < 140 and y < 20 then
c := 3
end if
if b = 1 and x > 140 and x < 160 and y < 20 then
c := 4
end if
if b = 1 and x > 160 and x < 180 and y < 20 then
c := 5
end if
if b = 1 and x > 180 and x < 200 and y < 20 then
c := 6
end if
if b = 1 and x > 200 and x < 220 and y < 20 then
c := 7
end if
if b = 1 and x > 220 and x < 240 and y < 20 then
c := 8
end if
if b = 1 and x > 240 and x < 260 and y < 20 then
c := 9
end if
if b = 1 and x > 260 and x < 280 and y < 20 then
c := 10
end if
if b = 1 and x > 280 and x < 300 and y < 20 then
c := 11
end if
if b = 1 and x > 300 and x < 320 and y < 20 then
c := 12
end if
if b = 1 and x > 320 and x < 340 and y < 20 then
c := 13
end if
if b = 1 and x > 340 and x < 360 and y < 20 then
c := 14
end if
if b = 1 and x > 360 and x < 380 and y < 20 then
c := 15
end if

%************ Allows the user to choose brush size ***********************
if b = 1 and x > 60 and x < 100 and y > 20 and y < 60 then
s := 1
end if
if b = 1 and x > 100 and x < 140 and y > 20 and y < 60 then
s := 2
end if
if b = 1 and x > 140 and x < 180 and y > 20 and y < 60 then
s := 3
end if
if b = 1 and x > 180 and x < 220 and y > 20 and y < 60 then
s := 4
end if
if b = 1 and x > 220 and x < 260 and y > 20 and y < 60 then
s := 5
end if
if b = 1 and x > 260 and x < 300 and y > 20 and y < 60 then
s := 6
end if
if b = 1 and x > 300 and x < 340 and y > 20 and y < 60 then
s := 7
end if
if b = 1 and x > 340 and x < 380 and y > 20 and y < 60 then
s := 8
end if
if b = 1 and x > 380 and x < 420 and y > 20 and y < 60 then
s := 9
end if
if b = 1 and x > 420 and x < 460 and y > 20 and y < 60 then
s := 10
end if
if b = 1 and x > 460 and x < 500 and y > 20 and y < 60 then
s := 11
end if
if b = 1 and x > 500 and x < 540 and y > 20 and y < 60 then
s := 12
end if
if b = 1 and x > 540 and x < 580 and y > 20 and y < 60 then
s := 13
end if
if b = 1 and x > 580 and x < 620 and y > 20 and y < 60 then
s := 14
end if
if b = 1 and x > 620 and x < 660 and y > 20 and y < 60 then
s := 15
end if
if b = 1 and x > 660 and x < 700 and y > 20 and y < 60 then
s := 16
end if
if b = 1 and x > 700 and x < 740 and y > 20 and y < 60 then
s := 17
end if
if b = 1 and x > 740 and x < 780 and y > 20 and y < 60 then
s := 18
end if
if b = 1 and x > 780 and x < 820 and y > 20 and y < 60 then
s := 19
end if
if b = 1 and x > 820 and x < 860 and y > 20 and y < 60 then
s := 20
end if

%*************** Allows the user to choose the brush shape ***************
if b = 1 and x > 60 and x < 90 and y > 60 and y < 90 then
sh := 1
end if
if b = 1 and x > 90 and x < 120 and y > 60 and y < 90 then
sh := 2
end if
if b = 1 and x > 120 and x < 150 and y > 60 and y < 90 then
sh := 3
end if
if b = 1 and x > 150 and x < 180 and y > 60 and y < 90 then
sh := 4
end if
if b = 1 and x > 180 and x < 210 and y > 60 and y < 90 then
sh := 5
end if
if b = 1 and x > 210 and x < 240 and y > 60 and y < 90 then
sh := 6
end if

%***************** Allows the user to choose tool *************************
if b = 1 and x > 60 and x < 120 and y > 90 and y < 115 then
t := 1
end if
if b = 1 and x > 120 and x < 165 and y > 90 and y < 115 then
t := 2
end if
if b = 1 and x > 165 and x < 230 and y > 90 and y < 115 then
t := 3
end if
if b = 1 and x > 230 and x < 290 and y > 90 and y < 115 then
t := 4
end if
if b = 1 and x > 290 and x < 350 and y > 90 and y < 115 then
t := 5
end if
if b = 1 and x > 350 and x < 410 and y > 90 and y < 115 then
t := 6
end if

%************** Allows the user to paint ***********************************
if b = 1 and sh = 1 and t = 1 and y - s > 115 then
Draw.FillOval (x, y, s, s, c)
end if
if b = 1 and sh = 2 and t = 1 and y - s > 115 then
Draw.FillBox (x - s, y - s, x + s, y + s, c)
end if
if b = 1 and sh = 3 and t = 1 and y - s > 115 then
Draw.FillStar (x - s, y - s, x + s, y + s, c)
end if
if b = 1 and sh = 4 and t = 1 and y - s > 115 then
Draw.FillMapleLeaf (x - s, y - s, x + s, y + s, c)
end if
if b = 1 and sh = 5 and t = 1 and y - s > 115 then
Draw.FillOval (x, y, s, round (s / 3), c)
end if
if b = 1 and sh = 6 and t = 1 and y - s > 115 then
Draw.FillOval (x, y, round (s / 3), s, c)
end if

%************* Allows the user to fill ******************************
if b = 1 and t = 2 and y - s > 115 then
Draw.Fill (x, y, c, 7)
end if

%*************** Allows the user to use spray paint **********************
if b = 1 and t = 3 and y - s > 115 then
loop
Draw.Dot (Rand.Int (x - s, x + s), Rand.Int (y - s, y + s), c)
b := 0
exit when b = 0
end loop
end if

%************* Allows the user to draw a line ***********************
if b = 1 and t = 4 and y > 115 and not lstart then
lstart := true
x2 := x
y2 := y
elsif b = 0 and y > 115 and lstart then
lstart := false
Draw.ThickLine (x2, y2, x, y, s, c)
end if

%********** Allows the user to draw a box ***************************
if b = 1 and t = 5 and y > 115 and not bstart then
bstart := true
x2 := x
y2 := y
elsif b = 0 and y > 115 and bstart then
bstart := false
Draw.Box (x2, y2, x, y, c)
end if

%********** Allows the user to draw an oval ***************************
if b = 1 and t = 6 and y > 115 and not ostart then
ostart := true
x2 := x
y2 := y
elsif b = 0 and y > 115 and ostart then
ostart := false
if y - y2 < y2 - 115 then
Draw.Oval (x2, y2, x2 - x, y2 - y, c)
end if
end if

%**************** Allows the user to choose help *********************
if b = 1 and y > 90 and y < 115 and x > 750 and x < 800 then
helpwin := Window.Open ("graphics: 500; 500, nobuttonbar")
put "This is help. Instructions for my paint program will soon appear."
end if
end loop


[/code]
Cervantes




PostPosted: Fri Oct 07, 2005 7:07 pm   Post subject: (No subject)

Lapsus Antepedis wrote:
I hate to say it Cervantes, but your code doesn't work! Sad (oddly enough, I came up with nearly identical code a few minutes ago, but my variable names were different Shocked )

Your procedure almost does what it is supposed to, but it never seems to call the other three procedures, so it functions as if you had written this:
code:
proc fill (x, y, c, boarder_c : int)

    if whatdotcolour (x, y) not= boarder_c then
        Draw.Dot (x, y, c)
        fill (x + 1, y, c, boarder_c)
    end if

end fill



Thanks for catching that. I thought I'd traced the logic, but apparently not.
I believe the problem is thus: the code moves right, drawing a line of dots until it reaches the boarder, at which point it goes back a step and moves left. Now, it redraws a dot of colour c there and then moves right. It will go infinately side to side.

Seems easy to fix. Add another condition to the if statement to make sure we're not going to re-draw a dot that has already been drawn. Though this is again untested.
code:

proc fill (x, y, c, boarder_c : int)

    if whatdotcolour (x, y) not= boarder_c & whatdotcolour (x, y) not= c then
          Draw.Dot (x, y, c)
          fill (x + 1, y, c, boarder_c)
          fill (x - 1, y, c, boarder_c)
          fill (x, y + 1, c, boarder_c)
          fill (x, y - 1, c, boarder_c)
    end if

end fill
goboenomo




PostPosted: Thu Oct 13, 2005 11:30 am   Post subject: nb

Your paint program is not bad for a basic one...
more painting options and colors would make it a bit better..
Also you should remove that last palette option because it is cut off the screen.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 15 Posts ]
Jump to:   


Style:  
Search: