Computer Science Canada Formula Error? |
Author: | YuNoMad? [ Wed Jun 15, 2011 9:43 pm ] | ||
Post subject: | Formula Error? | ||
What is it you are trying to achieve? To graph an equation y = 2x -3 on a graph when x is -20 to 20 by an increment of 1 each time What is the problem you are having? The graphed line will not appear on the screen or if it does it stops after one segment Describe what you have tried to solve this problem I have tried fixing this by changing what x is and it still isn't working, but since my teacher doesn't really teach us he just posts tutorials from this site, I don't know how to fix it. Also, I tried making the boxes that get drawn larger by 1000 pixels and they barely show up in the top left Post any relevant code
Please specify what version of Turing you are using At school I'm not sure what version we use but at home I use 4.1.1 |
Author: | RandomLetters [ Wed Jun 15, 2011 10:11 pm ] | ||
Post subject: | Re: Formula Error? | ||
It's working for me, it draws green squares with segments attached to them. Are you trying to connect them as one line?
|
Author: | Zren [ Wed Jun 15, 2011 11:16 pm ] | ||||
Post subject: | RE:Formula Error? | ||||
You can ignore the top bit, but seeing as your teach is... You can learn more about functions and subroutines in the Turing Walkthrough.
Now onto your assumed problem. Where the graph goes way offscreen. You need to scale it. More precisely, you need to scale the numbers you calculate of the equation to be used for the coordinates.
That was either overkill, or completely off the mark. Oh well. |
Author: | YuNoMad? [ Wed Jun 15, 2011 11:39 pm ] | ||||
Post subject: | Re: Formula Error? | ||||
if I had the time I would throw out what I have now and start over with functions, but I need it finished tomorrow so I'm going to change it up a bit as I have it below. it's uncommented, sorry, don't have the time >.> (two projects and this for tomorrow)
the drawline code is just to go through to the next step of the formula and draw a line to there. The next step of this program is to use a "sin(x)" and I know that has to do with wavelengths but we haven't learnt those yet and I don't know how to convert my xx to something that can be used in a sin, or vice versa, and still be graphed in pixel graphics. Here is what I have now:
should I make a yy3r/xx3r as reals to be used in a sin and round them into ints? |
Author: | Zren [ Wed Jun 15, 2011 11:48 pm ] |
Post subject: | RE:Formula Error? |
> should I make a yy3r/xx3r as reals to be used in a sin and round them into ints? Yes. Just so you know, sin() returns fractions from 0 .. 1. Eg: 0.745113. You might need to scale the number up a bit before rounding it. |
Author: | YuNoMad? [ Wed Jun 15, 2011 11:52 pm ] | ||
Post subject: | RE:Formula Error? | ||
is there anything else specific I should know about sins before attempting to use them in a program, such as limit to the input? this is what I am going to end up using, but my lines that I'm trying to draw from dot to dot are going off on some odd tangent. why is this?
Fixed. I accidentally accounted for the scale of pixel to graph twice. |