real values with drawfilloval()
Author |
Message |
piemaster
|
Posted: Wed Feb 28, 2007 8:09 pm Post subject: real values with drawfilloval() |
|
|
We recently started [and some of us have finished] a Turing unit in class. we have an "alternate assignment" that was not actually assigned, but provided for extra fun.
it goes as following. Create a graphing calc screen that will output a graph based upon the above function. Plot the above function when give then domain {-3.2<x<=3.2}
the function mentioned is this. ((4 * (x ** 3)) + (3 * (x ** 2)) - (2 * x) + 6) / (x + 9)
the following is the code i have so far.
code: |
var x : real := 0
function fx (x : real) : real
result ((4 * (x ** 3)) + (3 * (x ** 2)) - (2 * x) + 6) / (x + 9)
end fx
drawfillbox(0,0,maxx,maxy,black)
Draw.ThickLine(320,maxy,320,0,2,white)
Draw.ThickLine(0,200,maxx,200,2,white)
loop
x:=-3.2
drawfilloval(x,fx(x),2,2,white)
x:=x+0.1
exit when x = 3.2
end loop
|
as you can see, i have a function that calculates the y value for the center of the circle [which is a plot point on the graph, the x value is initially -3.2 and increases incrementally till 3.2]
the error Turing throws at me is Argument is the wrong type. I assume this means I cant use a decimal value for either coordinate in the drawfilloval. is there any way around this?
ps: I'm new here, if this post is completely out of bounds please lmk. Its not for homework, just for fun and i have valid , self-written code.
pps: I'm also new to turing, so if im going about this in a completely idiotic manner, please don't judge |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Clayton
|
Posted: Wed Feb 28, 2007 8:15 pm Post subject: Re: real values with drawfilloval() |
|
|
you simply have to take the real value that you are getting and round() it to an integer. This makes sense because you can't have 1/2 a pixel right? |
|
|
|
|
|
piemaster
|
Posted: Wed Feb 28, 2007 8:21 pm Post subject: RE:real values with drawfilloval() |
|
|
but if i do that, wont the graph be inaccurate? i understand you can have half a pixel, but then is the problem given flawed?
thanks for the help btw
//edit:
if i edit the code to look something like this:
code: |
loop
x:=-3.2
drawfilloval(round(x),round(fx(x)),2,2,white)
x:=x+.1
exit when x = 3.2
end loop
|
the output kaboomerates itself. |
|
|
|
|
|
|
|