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

Username:   Password: 
 RegisterRegister   
 URGENT: Turing Paint Program >Stuck on color x/y cords.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
fmy




PostPosted: Tue Oct 12, 2004 4:27 pm   Post subject: URGENT: Turing Paint Program >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 Sad. 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:

code:


%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.
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Tue Oct 12, 2004 6:07 pm   Post subject: (No subject)

fmy wrote:
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 Razz

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:

code:

%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 <= 180 and y >= 3 and y <= 27 then %if x and y are somewhere on the colourpalette - not including white square
        if whatdotcolour (x, y) not= 0 then %ignore the white spaces between colours
            guicolour := whatdotcolour (x, y) %make guicolour = the colour of the square that the mouse is over
        end if
    elsif x >= 184 and x <= 210 and y >= 3 and y <= 27 then %if x and y are in the "white" box
        guicolour := white
    end if

end loop
fmy




PostPosted: Wed Oct 13, 2004 1:58 pm   Post subject: On the brush section of the program

Thank you very much Cervantes! [I love that game] yeaaa.. sorry for the typo lol! But my teacher gave our class another week to work on it! Hurray! So I finished the sizes currently on the palette and this is what i've currently come up with.

I just really need help with the brushes. Im not sure how to go about it. Does anyone have any suggestions? Would be totally greatful! Well, here is what I currently have:

code:


%Program's Opening Sequence



colorback (black)
cls

setscreen ("graphics")
var x1, y1 : int := 0
var dx, dy : int := 1
for i : 1 .. 90000
    if whatdotcolor (x1, y1) not= 0 then
    end if
    drawdot (x1, y1, white)
    x1 := x1 + dx
    y1 := y1 + dy
    if x1 = 0 or x1 = maxx then
        dx := -dx
    end if
    if y1 = 0 or y1 = maxy then
        dy := -dy
    end if
end for

colorback (white)
cls

%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)

%GUI - Short Message.


%Code
setscreen ("graphics:vga")

var x, y, button, bn, bu : int
var guicolour, sizex, sizey : int := 0


loop

    buttonwait ("down", x, y, bn, bu)

    if x > 0 and x < maxx and y > 55 and y < maxy then %This line restricts user to paint only in the drawing board and not the colour palette.
        drawfilloval (x, y, sizex, sizey, guicolour)

    elsif x >= 440 and x <= 458 and y >= 8 and y <= 23 then  %This line chooses the colour size: Small.
        sizex := 5
        sizey := 5
    elsif x >= 490 and x <= 518 and y >= 6 and y <= 30 then  %This line chooses the colour size: Medium.
        sizex := 10
        sizey := 10
    elsif x >= 550 and x <= 588 and y >= 4 and y <= 35 then  %This line chooses the colour size: Large.
        sizex := 20
        sizey := 20
    elsif x >= 3 and x <= 180 and y >= 3 and y <= 27 then %This line is used if x and y are somewhere on the colour palette - not including the eraser box.
        if whatdotcolour (x, y) not= 0 then %This line makes the program ignore the white spaces between colours.
            guicolour := whatdotcolour (x, y) %This line makes guicolour = the colour of the square that the mouse has clicked.
        end if
    elsif x >= 184 and x <= 210 and y >= 3 and y <= 27 then %This line is for the eraser, if x and y are in the white eraser box.
        guicolour := 0
    end if

end loop

Cervantes




PostPosted: Wed Oct 13, 2004 2:47 pm   Post subject: (No subject)

do basically the same thing as you did for sizes.
have a variable that changes whn the user clicks on a star or circle or box or maple leaf and then use a case construct in the main loop to draw it.
fmy




PostPosted: Wed Oct 13, 2004 4:25 pm   Post subject: (No subject)

case construct? hey man, can you please help me with the rest of the program please?
fmy




PostPosted: Wed Oct 13, 2004 5:11 pm   Post subject: (No subject)

Alright cervantes, I tried out that case structure but it didn't go as planned but I almost have it!!

Known errors:
-shape sizes can't be modifed
-the circle can't be selected

what am I doing wrong?
what should I change?

code:



%Program's Opening Sequence



colorback (black)
cls

setscreen ("graphics")
var x1, y1 : int := 0
var dx, dy : int := 1
for i : 1 .. 90000
    if whatdotcolor (x1, y1) not= 0 then
    end if
    drawdot (x1, y1, white)
    x1 := x1 + dx
    y1 := y1 + dy
    if x1 = 0 or x1 = maxx then
        dx := -dx
    end if
    if y1 = 0 or y1 = maxy then
        dy := -dy
    end if
end for

colorback (white)
cls

%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)

%GUI - Short Message.


%Code
setscreen ("graphics:vga")

var x, y, button, bn, bu : int
var guicolour, sizex, sizey : int := 0
var brush : int := 1

loop

    buttonwait ("down", x, y, bn, bu)

    if x >= 440 and x <= 458 and y >= 8 and y <= 23 then     %This line chooses the colour size: Small.
        sizex := 5
        sizey := 5
    elsif x >= 490 and x <= 518 and y >= 6 and y <= 30 then     %This line chooses the colour size: Medium.
        sizex := 10
        sizey := 10
    elsif x >= 550 and x <= 588 and y >= 4 and y <= 35 then     %This line chooses the colour size: Large.
        sizex := 20
        sizey := 20

    elsif x >= 224 and x <= 250 and y >= 03 and y <= 27 then
        brush := 1     %Square brush.
    elsif x >= 226 and x <= 290 and y >= 02 and y <= 29 then
        brush := 2     %Star brush.
    elsif x >= 306 and x <= 335 and y >= 02 and y <= 29 then
        brush := 3     %Maple Leaf brush.
    elsif x >= 370 and x <= 17 and y >= 15 and y <= 15 then
        brush := 4     %Circle brush.

    elsif x >= 3 and x <= 180 and y >= 3 and y <= 27 then     %This line is used if x and y are somewhere on the colour palette - not including the eraser box.
        if whatdotcolour (x, y) not= 0 then     %This line makes the program ignore the white spaces between colours.
            guicolour := whatdotcolour (x, y)     %This line makes guicolour = the colour of the square that the mouse has clicked.
        end if
    elsif x >= 184 and x <= 210 and y >= 3 and y <= 27 then     %This line is for the eraser, if x and y are in the white eraser box.
        guicolour := 0
    end if

    case brush of
        label 1 :
            if x > 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

end loop

wtd




PostPosted: Wed Oct 13, 2004 5:37 pm   Post subject: (No subject)

I apologize that I can't help more, but I can suggest one refactoring:

code:
    case brush of
        label 1 :
            if x > 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.

code:
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




PostPosted: Wed Oct 13, 2004 5:51 pm   Post subject: (No subject)

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:
code:
    elsif x >= 370 and x <= 17 and y >= 15 and y <= 15 then

line 91.
I think you are using the syntax of drawfillbox and drawfillstar and drawfillmaple leaf interchangably with drawfilloval.

the line should be this:
code:
elsif x >= 355 and x <= 395 and y >= 02 and y <= 29 then


also, you need to fix up you drawfillbox, drawfillstar, and drawfillmapleleaf lines in your case construct. You used them like you use drawfilloval: the first three don't use radii, they use x1, y1, x2, and y2.

The case construct should look like this:
code:

    if x > 0 and x < maxx and y > 55 and y < maxy then
        case brush of
            label 1 :
                drawfillbox (x - sizex div 2, y - sizey div 2, x + sizex div 2, y + sizey div 2, guicolour)
            label 2 :
                drawfillstar (x - sizex div 2, y - sizey div 2, x + sizex div 2, y + sizey div 2, guicolour)
            label 3 :
                drawfillmapleleaf (x - sizex div 2, y - sizey div 2, x + sizex div 2, y + sizey div 2, guicolour)
            label 4 :
                drawfilloval (x, y, sizex, sizey, guicolour)
        end case
    end if


notice how you were repeating the same if statement inside each label? To save lines, that can be moved outside of the case construct.

I hope that helps Smile
-Cervantes
Sponsor
Sponsor
Sponsor
sponsor
fmy




PostPosted: Wed Oct 13, 2004 6:26 pm   Post subject: (No subject)

Thank you guys soooo much! This helps alot! One thing though, I mean, everything works great! but, when I paint I dont want the user to be able to paint over the palette at the bottom of the program. I did that before but only with a small oval it didn't go over, not it will go over with the other sizes. How would I change this to make it so neither paint brush will go over the palette no matter what the size?

Yet again, my final code! Thank you so much again! I learned alot about those case structures Razz

code:




%Program's Opening Sequence



colorback (black)
cls


setscreen ("graphics")
var x1, y1 : int := 0
var dx, dy : int := 1
for i : 1 .. 90000
    if whatdotcolor (x1, y1) not= 0 then
    end if
    drawdot (x1, y1, white)
    x1 := x1 + dx
    y1 := y1 + dy
    if x1 = 0 or x1 = maxx then
        dx := -dx
    end if
    if y1 = 0 or y1 = maxy then
        dy := -dy
    end if
end for

colorback (white)
cls

%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)

%GUI - Short Message.


%Code
setscreen ("graphics:vga")

var x, y, button, bn, bu : int
var guicolour, sizex, sizey : int := 0
var brush : int := 1

loop

    buttonwait ("down", x, y, bn, bu)

    if x >= 440 and x <= 458 and y >= 8 and y <= 23 then     %This line chooses the colour size: Small.
        sizex := sizex - sizex + 15
        sizey := sizey - sizey + 15
    elsif x >= 490 and x <= 518 and y >= 6 and y <= 30 then     %This line chooses the colour size: Medium.
        sizex := sizex - sizex + 30
        sizey := sizey - sizey + 30
    elsif x >= 550 and x <= 588 and y >= 4 and y <= 35 then     %This line chooses the colour size: Large.
        sizex := sizex - sizex + 55
        sizey := sizey - sizey + 55

    elsif x >= 224 and x <= 250 and y >= 03 and y <= 27 then
        brush := 1     %Square brush.
    elsif x >= 226 and x <= 290 and y >= 02 and y <= 29 then
        brush := 2     %Star brush.
    elsif x >= 306 and x <= 335 and y >= 02 and y <= 29 then
        brush := 3     %Maple Leaf brush.
    elsif x >= 355 and x <= 395 and y >= 02 and y <= 29 then
        brush := 4     %Circle brush.

    elsif x >= 3 and x <= 180 and y >= 3 and y <= 27 then     %This line is used if x and y are somewhere on the colour palette - not including the eraser box.
        if whatdotcolour (x, y) not= 0 then     %This line makes the program ignore the white spaces between colours.
            guicolour := whatdotcolour (x, y)     %This line makes guicolour = the colour of the square that the mouse has clicked.
        end if
    elsif x >= 184 and x <= 210 and y >= 3 and y <= 27 then     %This line is for the eraser, if x and y are in the white eraser box.
        guicolour := 0
    end if


    if x > 0 and x < maxx and y > 55 and y < maxy then
        case brush of
            label 1 :
                drawfillbox (x - sizex div 2, y - sizey div 2, x + sizex div 2, y + sizey div 2, guicolour)
            label 2 :
                drawfillstar (x - sizex div 2, y - sizey div 2, x + sizex div 2, y + sizey div 2, guicolour)
            label 3 :
                drawfillmapleleaf (x - sizex div 2, y - sizey div 2, x + sizex div 2, y + sizey div 2, guicolour)
            label 4 :
                drawfilloval (x, y, sizex, sizey, guicolour)
        end case
    end if

end loop

fmy




PostPosted: Wed Oct 13, 2004 6:34 pm   Post subject: (No subject)

hey cervantes, how do you get such the right cordinates for that circle? do you just guess or is there a way of doing it?
Cervantes




PostPosted: Wed Oct 13, 2004 7:21 pm   Post subject: (No subject)

this line:
code:
drawfilloval (370, 17, 15, 15, black)

in the GUI brushes part at the beginning of the program told me the size of the circle, so i used that.

You should incorporate your sizey variable in the following ifstatement:
code:
if x > 0 and x < maxx and y > 55 and y < maxy then

I notice that you used 55, which is actually 5 pixels above the line that seperates your tools placce with your drawing board dealie. You can put it back to 50 and incorporate sizey.

code:
if x > 0 and x < maxx and y > 50 + sizey and y < maxy then

that does it, but ifyou want to be really good and fix a little thing that isn't quite right:
This was my fault; what you should do is take out all the div 2's in the case construct for where to draw the boxes, maple leaves, and stars. Because, when they are in there, the box has a side length of sizex (or sizey, they're the same). But, take it out, and the box has a side length of 2*sizex. The oval has a radius of sizex, so it has a diameter of 2*sizex. If you want to have your boxes and circles in the right proportions to each other, take that line out. It also serves to allow the box to be stamped all the way up to the dividing line between your tool pallette and your drawing board.

hope you understood that gibberish Confused
-Cervantes
fmy




PostPosted: Wed Oct 13, 2004 8:21 pm   Post subject: (No subject)

I did! thank you very much man! youve been a great help!

glad to see you live in the same neighbourhood too hehe.

this program is definatly ready for presentation! class mates gonna be shocked!

and Taylor, if your reading this, YOU BETTER NOT STEAL THIS! Razz
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: