Computer Science Canada Making A linear graph- I NEED HELP |
Author: | illzidaneyou [ 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? |
Author: | syntax_error [ Sat Jan 10, 2009 3:16 pm ] |
Post subject: | RE:Making A linear graph- I NEED HELP |
In short no. |
Author: | Tony [ 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. |
Author: | illzidaneyou [ 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 |
Author: | The_Bean [ 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 |
Author: | illzidaneyou [ 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 |
Author: | illzidaneyou [ Sat Jan 10, 2009 4:52 pm ] |
Post subject: | Re: Making A linear graph- I NEED HELP |
K im really confused now ![]() ![]() ![]() |
Author: | illzidaneyou [ Sat Jan 10, 2009 4:58 pm ] | ||||
Post subject: | Re: Making A linear graph- I NEED HELP | ||||
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 ![]()
|
Author: | TheGuardian001 [ 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
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. |
Author: | illzidaneyou [ Sat Jan 10, 2009 6:48 pm ] | ||
Post subject: | Re: Making A linear graph- I NEED HELP | ||
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. |
Author: | illzidaneyou [ Sat Jan 10, 2009 7:00 pm ] | ||
Post subject: | Re: Making A linear graph- I NEED HELP | ||
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. |
Author: | The_Bean [ 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. |
Author: | illzidaneyou [ 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.
|
Author: | The_Bean [ 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. |
Author: | illzidaneyou [ 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 ![]() 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. |
Author: | illzidaneyou [ Sat Jan 10, 2009 8:58 pm ] | ||
Post subject: | RE:Making A linear graph- I NEED HELP | ||
i realised that my program was wrong because the first point cant always be on the line, so i changed it to sumthing else. plus this one only has 1 quadrant now the only problem is that, if my m value is greater than 1, the line goes way up. |