Posted: Sat Jan 10, 2009 2:48 pm Post subject: Making A linear graph- I NEED HELP
I have a turing project where you have to make a program (basically a menu page).
From that menu the program has to be able to execute atleast 3 other prgrams, but all the programs have to be school related.
So one of my programs was where i ask the user for y,m,and x and it will solve for b.
my teacher thought it was good (anything fascinates him)
but then hes like maybe you could graph it, and im having trouble with that
can anyone please tell me the code that will make a graph, and then let me input my own points?
Sponsor Sponsor
syntax_error
Posted: Sat Jan 10, 2009 3:16 pm Post subject: RE:Making A linear graph- I NEED HELP
In short no.
Tony
Posted: Sat Jan 10, 2009 3:38 pm Post subject: RE:Making A linear graph- I NEED HELP
I can tell you that you need to use Draw.Line().
Now having just a line on a screen looking kind of lame, so you can draw a background with more Draw.Line commands or load an image. The tricky part will be scaling, in events when 1-to-1 line is drawn outside of the visible screen.
Posted: Sat Jan 10, 2009 3:52 pm Post subject: Making A linear graph- I NEED HELP
see i was thinking that maybe i could use drawline too, but since the values have to be inputted by the user, i put variables instead of numbers, and that doesnt work.
I also tried changing the programming of the parabola program in my textbook, but that just messed it up
The_Bean
Posted: Sat Jan 10, 2009 4:02 pm Post subject: Re: Making A linear graph- I NEED HELP
Decide where on the screen you want the center of the graph to be
Decide the scale of your graph, and the upper and lower x and y values
have the user input the m and b
sub your lower x value in the equation to get the starting point of the line
and the upper x value for the ending of the line
use Draw.Line with those coordinates making sure to add the center of the graph x,y to those points as well.
you can make the background of the graph with Draw.DashedLine
illzidaneyou
Posted: Sat Jan 10, 2009 4:27 pm Post subject: Re: Making A linear graph- I NEED HELP
k ill try,
your idea makes alot of sense though
thnx
illzidaneyou
Posted: Sat Jan 10, 2009 4:52 pm Post subject: Re: Making A linear graph- I NEED HELP
K im really confused now
illzidaneyou
Posted: Sat Jan 10, 2009 4:58 pm Post subject: Re: Making A linear graph- I NEED HELP
Turing:
var m:real var b:real get m
get b
const ymax:real:=m*maxx+b
const ymin:real:=m*0+b
drawline(maxx,ymax,0,ymin,4)
that is my program so far, but the problem is it wont run, it highlights ymax in the last line and says that the argument is the wrong type. Why wont drawline let there be variables?
Mod Edit: Remember to use syntax tags! Thanks
code:
[syntax="turing"]Code Here[/syntax]
Sponsor Sponsor
TheGuardian001
Posted: Sat Jan 10, 2009 5:56 pm Post subject: Re: Making A linear graph- I NEED HELP
drawline allows variables. the problem is drawline is looking for an int, and you gave it a real.
either round the number off or use an int to begin with.
also
code:
const ymin:real:=m*0+b
there is no point in m*0. it will always be 0. setting it to b would make more sense. it does the same thing, but that bothered me.
illzidaneyou
Posted: Sat Jan 10, 2009 6:48 pm Post subject: Re: Making A linear graph- I NEED HELP
Turing:
var m:int var b:int get m
get b
var ymax:int:=m*maxx+b
var ymin:int:=b
drawline(maxx,ymax,0,ymin,3)
k i did what you said theguardian001 and it works. Thanks!
Now all i have to do is figure out how to make the gridlines. im going to try the_bean's method for the grd.
illzidaneyou
Posted: Sat Jan 10, 2009 7:00 pm Post subject: Re: Making A linear graph- I NEED HELP
Turing:
var y :int var m :int var x :int var b :int
put"Please enter the following values y, m and x (WHOLE NUMBERS ONLY)" put"y= "..
get y
put"m= "..
get m
put"x= "..
get x
b := y - (m*x) put"The value of b is: ", b
var ymax:int:=m*maxx+b
var ymin:int:=b
drawline(maxx,ymax,340,200,4)
K its almost perfect, now when i type in m and x, i will get the line now the only problem is that the line dont exactly fit with the numbers on the graph because pixels are too small and you cant number a pixel. If someone could maybe figure out the exact pixel number where the number 2 is, then i could just replace all the other numbers.
The_Bean
Posted: Sat Jan 10, 2009 8:07 pm Post subject: Re: Making A linear graph- I NEED HELP
Your graph isn't correct.
The b value is the y-intercept but yet your graph always passes through the origin. Really easy to fix.
(If you input an x,y coordinate the graph should pass through that point)
To align the numbers better you should use Font.Draw, this will also remove the missing sections in your line.
illzidaneyou wrote:
If someone could maybe figure out the exact pixel number where the number 2 is, then i could just replace all the other numbers.
NO! Do it yourself.
illzidaneyou_graph.jpg
Description:
Filesize:
31.97 KB
Viewed:
52 Time(s)
illzidaneyou
Posted: Sat Jan 10, 2009 8:17 pm Post subject: RE:Making A linear graph- I NEED HELP
yeah i realized that
i fixed it
heres the program if you guys want it. The only problem is that the axis dont have numbers
the problem was that the second y value was wrong, i put 200, when it should have been b+200 so i made a variable called y intercept and it works now.
Turing:
var y :int var m :int var x :int var b :int
put"Please enter the following values y, m and x (WHOLE NUMBERS ONLY)" put"y= "..
get y
put"m= "..
get m
put"x= "..
get x
b := y - (m*x) put"The value of b is: ", b
Posted: Sat Jan 10, 2009 8:26 pm Post subject: Re: Making A linear graph- I NEED HELP
To make numbers on it use Font.Draw() and 'for' loops this will put numbers exactly where you want them.
Your graph shows quadrants 1,2,3,4 yet the line only appears in quadrants 1,4.
You might also want to scale up your graph because you normally want numbers -10..10 not -200..200 which makes it really hard to see detail.
illzidaneyou
Posted: Sat Jan 10, 2009 8:31 pm Post subject: Re: Making A linear graph- I NEED HELP
oh im not gonna worry about the other 3 quadrants. my teacher will just think its okay. He thinks simple stuff is hard.
(i think were almost as good as him , maybe even better...)
but how do u scale something up? is there like a code that will zoom in or something?
ive changed the program again, now theres only one quadrant ill post it up in 5 min, just gotta tweek it.