Computer Science Canada Drawing Lines (on a cartesian plane-type-thing)? |
Author: | Fazonica [ Tue May 04, 2004 2:04 pm ] |
Post subject: | Drawing Lines (on a cartesian plane-type-thing)? |
Hey!! Ok, for homework, we had to write a program. It's just that I can't figure out where to start!! All I've gotten so far is the user input part, but I can't get past that because I just don't know how to do the rest of the question! Here's the question: "Create a program which will draw a line of "o"'s on a cartesian plane The centre of the screen should be the point (0,0). Allow the user to enter the values for m and b and the beginning and end points for x. Note, all values must be between -10 and +10." I hope someone can help!! Even just a vague idea of what to do is good enough!! Thanks!! |
Author: | Paul [ Tue May 04, 2004 2:10 pm ] |
Post subject: | |
make the screen into a grid of 10 by 10, since the center of the screen is on 0,0 the bottom left corner, then all things drawn would be in the I quadrant wouldn't it? Map the x and y line positions into 2 arrays, then when the user enters say b=(8,4) then u get the x position of the line 8 and y position of line 4, and where they meet would be a point on ur line. The using the slope find 2 other points on ur grid and find coordinates using array, then draw the line. |
Author: | Fazonica [ Tue May 04, 2004 2:14 pm ] |
Post subject: | |
Thanks!! I'll try that. But how would you change the grid size? We haven't really learnt how to do that yet. We just started Loops last week... (I'm doing the Grade 10 course.) |
Author: | Cervantes [ Tue May 04, 2004 2:23 pm ] |
Post subject: | |
uh, paul, you misread the part where the question said, " The centre of the screen should be the point (0,0)." anywho, drawing stuff with text sucks. but if you have to, you have to. To make drawing text more like drawing graphics, use the locatexy command. after that, its just math. |
Author: | Paul [ Tue May 04, 2004 2:23 pm ] |
Post subject: | |
OOOPS! important, i just realized something, when it asks u for 0,0 , its not the pixel position on the screen! it is making 0,0 the center of the screen. 0,0 as in coordinates on grid. That makes things more complicated. Now u need to draw the grid and put the x and y values in the arrays while paying attention to the negative and positive values, it would work the same way though. Do u need a user input for grid size? if not, just set ur own gridsize, like the largest space in between lines allowing for 10 up and 10 across on the screen. If not, just make the user enter gridsize, like the spacing between lines. Then set up ur array according to that. or do u mean how many lines in the grid? [edit] yes I realize cervantes, I was busy doing this big post. |
Author: | Fazonica [ Tue May 04, 2004 2:30 pm ] |
Post subject: | |
locatexy? array? sorry, I'm pretty confused. I know how to do a regular locate command, if that's what you're talking about...? Maybe it would help mentioning that I only started learning this like, 2 or 3 months ago?? I don't know how to draw a grid (well I made my own pathetic attempt). Does Turing have it's own "draw grid" command?? Hmm...maybe I should check that... Ok, this might totally suck, but hey, what can I do? Here's what I've got so far (keep in mind that I only got this yesterday, and my teacher wasn't at school today, so I couldn't really get help): % declare variables var MI, BI, X1I, Y1I, X2I, Y2I:int var NumI:int:=0 [I can't remember why I put this in in the first place...there might not really be a reason, seeing as I don't use it at all...] % input put " ":20, "+ The Graphing Calculator +" put skip put "In order for your line to be graphed, you must enter the following: " put "the slope (m), the y-intercept (b), as well as the beginning, and " put "end points for x. The values must be between -10 and +10." loop put skip, "Slope of line: ".. get MI exit when MI >= -10 and MI <= 10 put "Invalid - Try Again" end loop loop put "Y-intercept: ".. get BI exit when BI >= -10 and BI <= 10 put "Invalid - Try Again" end loop loop put "Beginning point - X coordinate: ".. get X1I exit when X1I >= -10 and X1I <= 10 put "Invalid - Try Again" end loop loop put "Beginning point - Y coordinate: ".. get Y1I exit when Y1I >= -10 and Y1I <= 10 put "Invalid - Try Again" end loop loop put "End point - X coordinate: ".. get X2I exit when X2I >= -10 and X2I <= 10 put "Invalid - Try Again" end loop loop put "End point - Y coordinate: ".. get Y2I exit when Y2I >= -10 and Y2I <= 10 put "Invalid - Try Again" end loop % drawing line on graph delay (1000) cls locate (10, 20) put "(0,0)" I have this horrible feeling I'm doing something really wrong...help? |
Author: | Paul [ Tue May 04, 2004 2:34 pm ] |
Post subject: | |
uh yea... it asks u to draw on a cartesian plane, if u can't use arrays, u could always just run a for loop to determine the line's position on an already drawn grid. and those variables should be real, because most slopes I see in math arn't integers. |
Author: | Fazonica [ Tue May 04, 2004 2:41 pm ] |
Post subject: | |
ookay. As far as I can find, there is no grid thing on Turing..so do I just have to make a bunch of lines on my own? ok, thanks!! |
Author: | Paul [ Tue May 04, 2004 2:57 pm ] | ||
Post subject: | |||
lol I just whipped this up in a jiffy, check it out, tell me if u don't understand. an array is just a bunch of variables under the same name, differentiated by the number after it.
|
Author: | Cervantes [ Tue May 04, 2004 3:09 pm ] |
Post subject: | |
paul paul paul, you need to get better reading skills. the question wants you to graph it with text. make an ASCII graphi, if you will. non of this fancy drawthinkline stuff. |
Author: | Fazonica [ Tue May 04, 2004 3:10 pm ] |
Post subject: | |
wow...it works!! thanks!! i'm not sure i understand ALL of it, but most of it seems to make some kind of sense. (it could just be that i don't know enough about Turing) after reading it over: - could you just explain what the first few loops are doing? like, the purpose of them? so far, i understand the second half of it. thanks!! (don't worry, i won't copy it, i'll use it as my example in case i get lost) |
Author: | Paul [ Tue May 04, 2004 3:11 pm ] |
Post subject: | |
I did draw o's they're just so densly packed, it looks like a line Im just kidding, damn it! I hate ASCII graphics. Well who cares, don't use that program I gave u, the first few loops is just to determine the coordinates of the points on the graph, for example, the point (5,5), it would ask for the value in x(5) and the value in y(5) and they would give u the x and y coordinates for the point (5,5). Bah, I don't like this assignment ... its a stupid one. Especially given to people who learned loops a week ago. Cervantes help me out here. I'd just draw ovals on the points lol... |
Author: | Fazonica [ Tue May 04, 2004 3:11 pm ] |
Post subject: | |
...graph with text? um....?? so is what i thought was right wrong? |
Author: | Fazonica [ Tue May 04, 2004 3:12 pm ] |
Post subject: | |
oh, ok...wow, you guys post fast!! and i don't think those are densely packed "o"s...!! |
Author: | Fazonica [ Tue May 04, 2004 3:18 pm ] |
Post subject: | |
i agree. it is sooo stupid....and incredibly pointless, IMO. and i get what you're saying about the (5,5) thing. thanks (to both paul and cervantes)!! |
Author: | Paul [ Tue May 04, 2004 3:20 pm ] |
Post subject: | |
um... just reduce the slope to lowest fractional form then draw a line of circles (o's) in between the 2 circles already drawn (I edited my code). |
Author: | Fazonica [ Tue May 04, 2004 3:23 pm ] |
Post subject: | |
got it! thanks again! |
Author: | Cervantes [ Tue May 04, 2004 3:27 pm ] | ||
Post subject: | |||
Fazonica wrote: and i don't think those are densely packed "o"s...!! they aren't. pauls an idiot. i haven't added in that bit with minx and maxx, you can do that
EDIT: paul your code seems to be excessively long and it seems to only draw 3 circles. they're at: (0 - run, 0 - rise + b) (0, 0 + b) (0 + run, 0 + rise + b) anywho.... |
Author: | Fazonica [ Tue May 04, 2004 3:34 pm ] |
Post subject: | |
wow. and that works too!! i feel like such a beginner. and just when i think i know a lot. meh. thanks! |
Author: | Paul [ Tue May 04, 2004 3:36 pm ] |
Post subject: | |
mine looks better and has more practical use. Stupid assignment. Im changing it back to draw.thickline. and keeping it for further use. |
Author: | Fazonica [ Tue May 04, 2004 3:38 pm ] |
Post subject: | |
LOL!! *thumbs up* good idea. you never know when you're going to have to draw graphs. i blame math. |