Computer Science Canada

Shape Program

Author:  Pinto2 [ Wed Feb 02, 2005 4:36 pm ]
Post subject:  Shape Program

Cool shape program, input in welcome.

%The shape drawing program
%Daniel Simmonds and Martin Lindsy
%January 27 2005
setscreen ("graphics:max;max,nobuttonbar") %makes screen larger and removes the button bar
var shape, nothing, box_col : string %creates variable able to hold both numbers and letters
var box_base, box_height, box_col1, radius : int %creates variables able to hold rounded numbers
var x, triangletype, y, x2, x3, y2 : int %creates variables able to hold rounded number
var triangle_base, triangle_height, para_base, para_height, hex_base : real %creates variables able to hold unrounded number
var font : int %creates variables able to hold rounded number
font := Font.New ("Palatino:24:bold,italic") %assigns the variable 'font' a font style to use
proc drawhexagon (base, hexagonarea : real)
cls %clear screen
x := round ((maxx div 2) - (base div 2) * 20) %places x coordinate at a point to center the hexagon when drawn
x2 := round (x + base * 20) %when line is drawn the space between x and x2 is the base length
y := round ((maxy div 2) - (base div 2) * 20) %y is set to a coordinate to center the hexagon
drawline (x, y, x2, y, brightred) %draws the bottom line of the hexagon
y2 := round (y + (base * 0.66666) * 20) %sets y2 2/3 times the base above the last y variable, for a 60 degree angle
x3 := round (x - (base div 2) * 20) %x3 is half of the base to the left of the x coordinate
drawline (x, y, x3, y2, brightred) %draws the bottom left line
x := round (x2 + (base div 2) * 20) %sets x to half the base to the right of x2 to achieve a 60 degree angle
drawline (x2, y, x, y2, brightred) %draws bottom right line
y := round (y2 + (base * 0.66666) * 20) %sets the y coordinate 2/3 of the base over the last y corrdinate to achieve a 60 degree angle
x2 := round (x3 + (base div 2) * 20) %x2 is now the same as the x corrdinate was first
drawline (x3, y2, x2, y, brightred) %draws top left line
x3 := round (x - (base div 2) * 20) %x3 i now the same as what x2 started as
drawline (x3, y, x, y2, brightred) %draws top right line
drawline (x2, y, x3, y, brightred) %draws top base line
put "base=", base, "cm area=", (round (hexagonarea * 100)) / 100, "cm" .. %outputs base height and area
put chr (170) %squared symbol
end drawhexagon
procedure draw_box (box_height, box_base, box_col1 : int)
cls %clear screen
drawfillbox (200, 200, box_base, box_height, box_col1) %draws box using user given variables variables
end draw_box
proc circle (radius : int)
drawfilloval (400, 300, radius * 20, radius * 20, brightred) %draws circle using user given variables
end circle
proc drawparalellogram (para_base, para_height : real)
cls %clears screen
x := (maxx div 2) - ((para_base * 20) div 2) - 20 %x is put in a spot so that when drawn, the parolellogram is centered
x2 := round (x + para_base * 20) %x2 and x will be as far away from each other as the base
y := (maxy div 2) - ((para_base * 20) div 2) %y will be in the a spot so that when drawn, the parolellogram will be centered
drawline (x, y, x2, y, brightred) %draws the base line
y2 := round (y + para_height * 20) %y2 will be the height higher than the y coordinate
x3 := x + 40 %x3 will be 40 pixels to the right of x
drawline (x, y, x3, y2, brightred) %draws the left line
x := round (x3 + para_base * 20) %x is recycled to the base length to the right of x3
drawline (x, y2, x2, y, brightred) %draws right line
drawline (x, y2, x3, y2, brightred) %draws top line
locate (30, 30)
put "Base=", para_base, " height=", para_height, " area=", para_base * para_height .. %outputs the base height and area
put chr (170) %squared symbol
end drawparalellogram
proc drawtriangle (triangle_base, triangle_height : real)
cls %clear screen
x := round ((maxx div 2) - ((triangle_base * 20) div 2)) %x is at a point so that when draw, the triangle will be centered
x2 := round (x + triangle_base * 20) %x2 is the distance of the base away from the x
y := round ((maxy div 2) - ((triangle_base * 20) div 2)) %y is at a point so that when drawn, the triangle will be centered
drawline (x, y, x2, y, brightred) %draws bottome line
locate (30, 30)
put "base=", triangle_base, "cm height=", triangle_height, "cm" %outputs base height and area
y2 := round (y + triangle_height * 20) %y2 is the height away from the y coordinate
if triangletype = 1 then %if isosceles
x3 := maxx div 2 %x3 is centered
elsif triangletype = 2 then %if right angle
x3 := x2 %then x3 is x2
else
x3 := x + 15 %if scalene, then x3 is 15 right of x
end if
drawline (x, y, x3, y2, brightred) %draws left line
drawline (x2, y, x3, y2, brightred) %draws right line
end drawtriangle
colourback (black) %screen's background will be black
cls %clears screen
Font.Draw ("Welcome to Daniel's and Martin's program!!", 85, 350, font, brightgreen)
Font.Draw ("5", 450, 200, font, brightgreen)
delay (1500)
cls
Font.Draw ("Welcome to Daniel's and Martin's program!!", 85, 350, font, brightgreen)
Font.Draw ("4", 450, 200, font, brightgreen)
delay (1500)
cls
Font.Draw ("Welcome to Daniel's and Martin's program!!", 85, 350, font, brightgreen)
Font.Draw ("3", 450, 200, font, brightgreen)
delay (1500)
cls
Font.Draw ("Welcome to Daniel's and Martin's program!!", 85, 350, font, brightgreen)
Font.Draw ("2", 450, 200, font, brightgreen)
delay (1500)
cls
Font.Draw ("Welcome to Daniel's and Martin's program!!", 85, 350, font, brightgreen)
Font.Draw ("1", 450, 200, font, brightgreen)
delay (1500)
cls
Text.Colour (white) %all writing will be white
%main program begins here.
loop
cls %clears screen
locate (1, 1)
put "type 0 to exit."
locate (5, 5)
put "Please pick one of the following shapes that you would like to see drawn, and explained."
locate (10, 15)
put "1) Triangle"
locate (11, 15)
put "2) Rectangle"
locate (12, 15)
put "3) Circle"
locate (13, 15)
put "4) Paralellogram"
locate (14, 15)
put "5) Hexagon"
locate (15, 15)
put "Which shape would you like to see drawn? " ..
get shape %prompts user for input on their decision
if shape = "triangle" or shape = "Triangle" then
cls
put "Enter the base for the triangle (1-20).. " ..
get triangle_base %prompts user for base
if triangle_base > 20 then %keeps size reasonable
cls
loop
locate (15, 35)
put triangle_base, " is not valid input."
exit
end loop
end if
put "Enter the height for the triangle (1-20).. " ..
get triangle_height %user inputs height
if triangle_height > 20 then %keeps height reasonable
cls
locate (15, 35)
put triangle_height, " is not valid input."
end if
cls
put "Enter the type of triangle you would like drawn.."
put "(1) isoceles"
put "(2) Right-Angle"
put "(3) Scalene"
put "Triangle type.. " ..
get triangletype %asks user what triangle they want drawn
drawtriangle (triangle_base, triangle_height) %calls triangle procedure
elsif shape = "1" then
cls
loop
locate (1, 1)
put "Enter the base for the triangle (1-20).. " ..
get triangle_base %user enters base
if triangle_base > 20 then %keeps base reasonable
cls
locate (15, 35)
put triangle_base, " is not valid input."
exit
end if
put "Enter the height for the triangle (1-20).. " ..
get triangle_height %user enters height
if triangle_height > 20 then %keeps height reasonable
cls
locate (15, 35)
put triangle_height, " is not valid input."
exit
end if
put "Enter the type of triangle you would like drawn.."
put "(1) isoceles"
put "(2) Right-Angle"
put "(3) Scalene"
put "Triangle type.. " ..
get triangletype %asks user what kind of triangle they want drawn
drawtriangle (triangle_base, triangle_height) %calls triangle procedure
exit
end loop
elsif shape = "2" then
cls
locate (12, 25)
put "This is what a rectangle looks like..."
drawfillbox (200, 200, 450, 300, brightred) %gives example of rectangle
locate (25, 25)
put "Are you ready to see more!! " ..
get nothing
cls
drawfillbox (200, 200, 450, 300, brightred) %redraws example box
locate (2, 2)
put "Would You like to try? " ..
locate (30, 25)
put "Height of 5"
locate (30, 40)
put "Base of 8"
locate (2, 25)
get nothing
put "OK, please give me the Base!! (1-30) " ..
get box_base %user enters base
put "Ok, know give me the Height!! (1-20) " ..
get box_height %user enters height
box_col := "red" %sets colour to red
if box_col = "blue" then
box_col1 := 1
elsif box_col = "green" then
box_col1 := 2
elsif box_col = "red" then
box_col1 := 4
elsif box_col = "yellow" then
box_col1 := 14
elsif box_col = "white" then
box_col1 := 31
else
end if
put "invalid input"
%this part multiplys all lengths by 20 for scale ratio
box_height := box_height * 20
box_base := box_base * 20
box_base := box_base + 200
box_height := box_height + 200
draw_box (box_height, box_base, box_col1) %calls the draw box procedure
elsif shape = "rectangle" or shape = "Rectangle" then
cls %clears screen
locate (12, 25)
put "This is what a rectangle looks like..."
drawfillbox (200, 200, 450, 300, brightred) %draws example box
locate (25, 25)
put "Are you ready to see more!! " ..
get nothing
cls %clears screeen
drawfillbox (200, 200, 450, 300, brightred) %redraws example box
locate (2, 2)
put "Would You like to try? " ..
locate (30, 25)
put "Height of 5"
locate (30, 40)
put "Base of 8"
locate (2, 25)
get nothing
put "OK, please give me the Base!! (1-30) " ..
get box_base %user enters base
put "Ok, know give me the Height!! (1-20) " ..
get box_height %user enters height
box_col := "red" %sets colout to red
if box_col = "blue" then
box_col1 := 1
elsif box_col = "green" then
box_col1 := 2
elsif box_col = "red" then
box_col1 := 4
elsif box_col = "yellow" then
box_col1 := 14
elsif box_col = "white" then
box_col1 := 31
else
end if
put "invalid input"
%this code multiplys lengths by 20 to make a scale
box_height := box_height * 20
box_base := box_base * 20
box_base := box_base + 200
box_height := box_height + 200
draw_box (box_height, box_base, box_col1) %calls box procedure
elsif shape = "3" then
cls
put "This is what a circle looks like."
drawfilloval (400, 300, 70, 70, brightred) %draw example circle
locate (30, 2)
put "Would you like to see more? " ..
get nothing
cls %clears screen
drawoval (400, 300, 70, 70, brightred) %redraws example circle
drawline (400, 300, 470, 300, brightred)
locate (17, 50)
put "Radius of 4"
locate (2, 2)
put "Would you like to try? " ..
get nothing
cls %clears screen
locate (2, 2)
put "Please give me the radius! (1-15) " ..
get radius %user enters radius
cls
circle (radius) %calls circle procedure
put "Area=", round ((3.14 * radius ** 2) * 100) / 100 %outputs area
elsif shape = "circle" or shape = "Circle" then
cls
put "This is what a circle looks like."
drawfilloval (400, 300, 70, 70, brightred) %draws example circle
locate (30, 2)
put "Would you like to see more? " ..
get nothing
cls
drawoval (400, 300, 70, 70, brightred) %redraws example circle
drawline (400, 300, 470, 300, brightred)
locate (17, 50)
put "Radius of 4"
locate (2, 2)
put "Would you like to try? " ..
get nothing
cls %clears screen
locate (2, 2)
put "Please give me the radius! (1-15) " ..
get radius %user enters radius
cls %clears screen
circle (radius) %calls circle procedure
elsif shape = "paralellogram" or shape = "Paralellogram" or shape = "4" then
cls %clears screen
put "Enter the base of the shape (1-20).. " ..
get para_base %user enters base
put "Enter the height of the shape (1-20).. " ..
get para_height %user enters height
drawparalellogram (para_base, para_height) %calls procedure for paralellogram
elsif shape = "Hexagon" or shape = "hexagon" or shape = "5" then
cls %clears screen
put "Enter the desired base (1-15).. " ..
get hex_base %user enters base
if hex_base > 15 or hex_base < 1 then %keeps the size reasonable
hex_base := 15
end if
drawhexagon (hex_base, hex_base * (hex_base * 0.66) / 2 * 6) %calls haxagon procedure
elsif shape = "0" then
exit
else %if choice is invalid
cls
locate (12, 20)
put shape, " is an invalid input, please try again." %tells user its invalid
end if
delay (3000) %delays 3 seconds
end loop %goes back to the top of the menu part
cls
put "Thank you."

Author:  cycro1234 [ Wed Feb 02, 2005 4:41 pm ]
Post subject: 

You could have used code tags. Or at least added it by attachment.

Author:  Bacchus [ Wed Feb 02, 2005 4:41 pm ]
Post subject: 

didnt you already put this and then we told you that it belonged in source code and to use code tags?

Author:  cycro1234 [ Wed Feb 02, 2005 4:43 pm ]
Post subject: 

LMAO

Author:  Pinto2 [ Wed Feb 02, 2005 4:44 pm ]
Post subject: 

Yes i did already put this, but then it went missing. I don't know how. I didn't have a chance to change it yet. Oh, and i tried the attachment, it wouldn't work, mabe my computer is messed?

Author:  cycro1234 [ Wed Feb 02, 2005 4:45 pm ]
Post subject: 

What error does it give you?

Author:  Pinto2 [ Wed Feb 02, 2005 4:47 pm ]
Post subject: 

No error, just didn't show it, i cant figure it out. If it gets anyone mad just copy this program onto your turing and then put that attachment on this thread. I will then deleate the 500 lines of code.

Author:  Bacchus [ Wed Feb 02, 2005 4:53 pm ]
Post subject: 

your post didnt disapear, a mod moved it to the right forum and added the tags to it

Author:  Pinto2 [ Wed Feb 02, 2005 4:56 pm ]
Post subject: 

How was i supposed to know that, i looked in the other places and couldn't find it. And how is this not the correct place for it.

Author:  person [ Wed Feb 02, 2005 4:59 pm ]
Post subject: 

turing source code is the right section

Author:  cycro1234 [ Wed Feb 02, 2005 5:02 pm ]
Post subject: 

It's ok, nobody is angry Very Happy

Author:  Bacchus [ Wed Feb 02, 2005 5:04 pm ]
Post subject: 

dont worry about, everyone makes mistakes. this forum is for completed program exes (blah .exe) the source code forum if for bits like this (the .t one) where u can accually see the code. also the syntax tags help a lot for other people to read it. ([code]code here [/code ] <-but without the last space there)

Author:  cycro1234 [ Wed Feb 02, 2005 5:07 pm ]
Post subject: 

I'm still a noob myself Very Happy

Author:  Pinto2 [ Wed Feb 02, 2005 6:22 pm ]
Post subject: 

K, thanks, i'll make sure my programs go where they are supposed to go. I have the comments b/c it was a school assignment, one of the things you need to have.

Author:  cycro1234 [ Wed Feb 02, 2005 6:31 pm ]
Post subject: 

Yeah, commenting every loop, variable, if structure, error trapping, it becomes quite tiresome. Neccessary, but tiresome.

Author:  person [ Wed Feb 02, 2005 6:36 pm ]
Post subject: 

from the looks of it, id say Ms. D*** is going easy on us with the % comments%
eh cycro?

anyways...i find it easier to read with the comments
its a real pain in the as* to read coding without comments

Author:  cycro1234 [ Wed Feb 02, 2005 6:39 pm ]
Post subject: 

Eh-heh the comments..sure...

Imagine reading like 10 thousand lines of code without any comment lines.. Neutral

Author:  Pinto2 [ Wed Feb 02, 2005 9:35 pm ]
Post subject: 

Schools can't teach compsci, get this, my final project for grade ten was this shape program. But the only thing you needed to have was to draw a triangle with the base given to you by the user. But i decided to add the other shapes and different types of triangles. Thank god for this site or else i would have to learn at my classes speed, lol, "teacher teacher, whats a put command do?"

Author:  cycro1234 [ Wed Feb 02, 2005 9:38 pm ]
Post subject: 

OMG! Are you for real?

Well teaching yourself might be better than my school's method of blazing through Turing. If you've never done programming at all before, you get lost pretty quickly in my class. Aw well, its kool Smile

Author:  person [ Wed Feb 02, 2005 9:40 pm ]
Post subject: 

i like the way our school teaches it cycro.

all u ever wanted to know about turing in 5 month

Author:  cycro1234 [ Wed Feb 02, 2005 9:41 pm ]
Post subject: 

True, it worked wonders for me.

But not some1 like CHICH.

Author:  statistic-48260137985 [ Sun Feb 06, 2005 12:13 am ]
Post subject:  cool i was looking for this

perfect dan i actually wanted a copy of the program myself, and to any wondering the guy who posted the program was dan this is martin as read in the remarks, which i think dan should've rmoved before posting on a public site -_- but o well. I've bin messing around with some stuff dan i made the chck boxes and stuff work too so yea that all i came to say


: