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

Username:   Password: 
 RegisterRegister   
 real values with drawfilloval()
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
piemaster




PostPosted: 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 Smile
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: 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




PostPosted: 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 Smile

//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.
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 1  [ 3 Posts ]
Jump to:   


Style:  
Search: