
-----------------------------------
fmy
Tue Oct 12, 2004 4:27 pm

URGENT: Turing Paint Program &gt;Stuck on color x/y cords.
-----------------------------------
Hey guys, I'm new to this forum since I started my gr.11 programming class which just sticks to turing :(.  SO our assignment was to create a Pain Program and it's due tommorow! 

The user must change color/brush/size and I'm having trouble on the part where the use has to change the color. If anyone could help me out it would be a great help. I'm having trouble with the cords on where the button is selected. There is soemthing weird about how Turing gets it. But anyways, this is my program currently:



%Author: Rob D.

%GUI
drawbox (0, 0, 639, 50, black)
Draw.Box (00, 00, 639, 40, black)
drawline (213, 0, 213, 40, black)
drawline (410, 0, 410, 40, black)

locate (23, 2)
put "Colours:" ..
locate (23, 29)
put "Brushes:" ..
locate (23, 54)
put "Sizes:" ..

%GUI-Colours. Red, Blue, Green,  Brown, Grey, Black, White.
drawfillbox (03, 03, 30, 27, red)
drawfillbox (34, 03, 60, 27, blue)
drawfillbox (64, 03, 90, 27, green)
drawfillbox (94, 03, 120, 27, brown)
drawfillbox (124, 03, 150, 27, 15)
drawfillbox (154, 03, 180, 27, black)
drawbox (184, 03, 210, 27, black)

%GUI-Brushes. Square, Star, Maple, Circle.
drawfillbox (224, 03, 250, 27, black)
drawfillstar (266, 02, 290, 29, black)
drawfillmapleleaf (306, 02, 335, 29, black)
drawfilloval (370, 17, 15, 15, black)

%GUI - Sizes. Small, Medium, Large.
drawfillbox (440, 8, 458, 23, black)
drawfillbox (490, 6, 518, 30, black)
drawfillbox (550, 4, 588, 35, black)

%Code
setscreen ("graphics:vga")

var x, y, button, bn, bu : int
var guicolor : int := 0


loop

    buttonwait ("down", x, y, bn, bu)
    if x < -5 or x > 644 or y < -5 or y > 54 then
        drawfilloval (x, y, 5, 5, guicolor)
        elsif x < 03 or x > 27 or y < 03 or y > 30 then
            guicolor := guicolor - guicolor + 2

        elsif x < 34 or x > 03 or y < 60 or y > 27 then
            guicolor := guicolor - guicolor + 4

        elsif x < 94 or x > 03 or y < 120 or y > 27 then
            guicolor := guicolor - guicolor + 1


        end if

    end loop


Thank you again.

-----------------------------------
Cervantes
Tue Oct 12, 2004 6:07 pm


-----------------------------------
SO our assignment was to create a Pain Program and it's due tommorow! 
looks like you'll have to go through a lot of pain tonight.  Even if that was a type, that's still true :P

well, hopefully you won't have to go through much pain.
the key here is the use of whatdotcolour(x,y : int):int

try this out:


%Author: Rob D.

%GUI
drawbox (0, 0, 639, 50, black)
Draw.Box (00, 00, 639, 40, black)
drawline (213, 0, 213, 40, black)
drawline (410, 0, 410, 40, black)

locate (23, 2)
put "Colours:" ..
locate (23, 29)
put "Brushes:" ..
locate (23, 54)
put "Sizes:" ..

%GUI-Colours. Red, Blue, Green,  Brown, Grey, Black, White.
drawfillbox (03, 03, 30, 27, red)
drawfillbox (34, 03, 60, 27, blue)
drawfillbox (64, 03, 90, 27, green)
drawfillbox (94, 03, 120, 27, brown)
drawfillbox (124, 03, 150, 27, 15)
drawfillbox (154, 03, 180, 27, black)
drawbox (184, 03, 210, 27, black)

%GUI-Brushes. Square, Star, Maple, Circle.
drawfillbox (224, 03, 250, 27, black)
drawfillstar (266, 02, 290, 29, black)
drawfillmapleleaf (306, 02, 335, 29, black)
drawfilloval (370, 17, 15, 15, black)

%GUI - Sizes. Small, Medium, Large.
drawfillbox (440, 8, 458, 23, black)
drawfillbox (490, 6, 518, 30, black)
drawfillbox (550, 4, 588, 35, black)

%Code
setscreen ("graphics:vga")

var x, y, button, bn, bu : int
var guicolour : int := 0


loop

    buttonwait ("down", x, y, bn, bu)
    if x > 0 and x < maxx and y > 50 and y < maxy then %if x and y are on the drawing board
        drawfilloval (x, y, 5, 5, guicolour)
    elsif x >= 3 and x = 3 and y = 184 and x = 3 and y  0 and x < maxx and y > 55 and y < maxy then
                drawfillbox (x, y, sizex, sizey, guicolour)
            end if
        label 2 :
            if x > 0 and x < maxx and y > 55 and y < maxy then
                drawfillstar (x, y, sizex, sizey, guicolour)
            end if
        label 3 :
            if x > 0 and x < maxx and y > 55 and y < maxy then
                drawfillmapleleaf (x, y, sizex, sizey, guicolour)
            end if
        label 4 :
            if x > 0 and x < maxx and y > 55 and y < maxy then
                drawfilloval (x, y, sizex, sizey, guicolour)
            end if
    end case 

You use "x > 0 and x < maxx and y > 55 and y < maxy" repeatedly.  Instead of repeating it, let's factor it out into a variable, so any changes in that code won't have to be made 4 times.

var inBounds := x > 0 and x < maxx and y > 55 and y < maxy

    case brush of
        label 1 :
            if inBounds then
                drawfillbox (x, y, sizex, sizey, guicolour)
            end if
        label 2 :
            if inBounds then
                drawfillstar (x, y, sizex, sizey, guicolour)
            end if
        label 3 :
            if inBounds then
                drawfillmapleleaf (x, y, sizex, sizey, guicolour)
            end if
        label 4 :
            if inBounds then
                drawfilloval (x, y, sizex, sizey, guicolour)
            end if
    end case 

-----------------------------------
Cervantes
Wed Oct 13, 2004 5:51 pm


-----------------------------------
good job, you got the case construct to work!
The problems with your program aren't with your case construct, they are elsewhere:
1.) the resason you cannot select the circle is because the coordinates of this line are way off:
    elsif x >= 370 and x = 15 and y = 355 and x = 02 and y 