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

Username:   Password: 
 RegisterRegister   
 Drawing Lines (on a cartesian plane-type-thing)?
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Fazonica




PostPosted: 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!!
Sponsor
Sponsor
Sponsor
sponsor
Paul




PostPosted: Tue May 04, 2004 2:10 pm   Post subject: (No 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.
Fazonica




PostPosted: Tue May 04, 2004 2:14 pm   Post subject: (No subject)

Thanks!! I'll try that. But how would you change the grid size? We haven't really learnt how to do that yet. Confused We just started Loops last week... (I'm doing the Grade 10 course.)
Cervantes




PostPosted: Tue May 04, 2004 2:23 pm   Post subject: (No 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.
Paul




PostPosted: Tue May 04, 2004 2:23 pm   Post subject: (No 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.
Fazonica




PostPosted: Tue May 04, 2004 2:30 pm   Post subject: (No subject)

locatexy? array? Confused 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?
Paul




PostPosted: Tue May 04, 2004 2:34 pm   Post subject: (No 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.
Fazonica




PostPosted: Tue May 04, 2004 2:41 pm   Post subject: (No 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!! Smile
Sponsor
Sponsor
Sponsor
sponsor
Paul




PostPosted: Tue May 04, 2004 2:57 pm   Post subject: (No 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.
code:

var x: array 1..21 of int
var y: array 1..21 of int
var counter:=11
for decreasing a: maxx div 2..0 by 15
x(counter):=a
counter-=1
exit when counter = 0
end for
counter:= 11
for a: maxx div 2..maxx by 15
x(counter):=a
counter+=1
exit when counter= 22
end for
counter:=11
for a: maxy div 2..maxy by 15
y(counter):=a
counter+=1
exit when counter=22
end for
counter:= 11
for decreasing a: maxy div 2 .. 0 by 15
y(counter):= a
counter-=1
exit when counter=0
end for


var b, intercept: int
var mx, my: int
put "enter b: "..
get b
intercept:= b+11
put "enter rise of slope: "
get my
put "enter run of slope: "
get mx
cls
for a: 1..21

drawline (x(a), 0, x(a), maxy, black)
drawline (0, y(a), maxx, y(a), black)
end for
Draw.ThickLine (x(11), 0, x(11), maxy, 5, black)
Draw.ThickLine (0, y(11), maxx, y(11), 5, black)
drawfilloval (x(11), y(intercept), 5, 5, black)
drawfilloval (x(11+mx), y(intercept+my), 5,5,black)
Draw.ThickLine (x(11), y(intercept), x(11+mx), y(intercept+my), 5, black)
drawfilloval (x(11-mx), y(intercept-my), 5,5,black)
Draw.ThickLine (x(11), y(intercept), x(11-mx), y(intercept-my), 5, black)
Draw.ThickLine (x(1), y(1), x(21), y(1), 5, black)
Draw.ThickLine (x(1), y(1), x(1), y(21), 5, black)
Draw.ThickLine (x(1), y(21), x(21), y(21), 5, black)
Draw.ThickLine (x(21), y(21), x(21), y(1), 5, black)
Cervantes




PostPosted: Tue May 04, 2004 3:09 pm   Post subject: (No 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. Naughty
Fazonica




PostPosted: Tue May 04, 2004 3:10 pm   Post subject: (No 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!! Smile (don't worry, i won't copy it, i'll use it as my example in case i get lost)
Paul




PostPosted: Tue May 04, 2004 3:11 pm   Post subject: (No subject)

I did draw o's they're just so densly packed, it looks like a line Wink
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 Sad ... 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...
Fazonica




PostPosted: Tue May 04, 2004 3:11 pm   Post subject: (No subject)

...graph with text? um....?? Confused so is what i thought was right wrong?
Fazonica




PostPosted: Tue May 04, 2004 3:12 pm   Post subject: (No subject)

oh, ok...wow, you guys post fast!! and i don't think those are densely packed "o"s...!!
Fazonica




PostPosted: Tue May 04, 2004 3:18 pm   Post subject: (No subject)

i agree. it is sooo stupid....and incredibly pointless, IMO. Rolling Eyes and i get what you're saying about the (5,5) thing. thanks (to both paul and cervantes)!! Smile
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 2  [ 21 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: