Posted: Wed Apr 04, 2012 6:24 am Post subject: RE:Turing Graphing Calculator (Help)
Ok one last question....
Why does this not work?:
code:
for i : 0 .. 10
const x := i * 0.05
fx := (text1 * (x ** 5)) + (text2 * (x ** 4)) + (text3 * (x ** 3)) + (text4 * (x ** 2)) + (text5 * x) + text6
Draw.FillOval (x, fx, 3, 3, black)
end for
Sponsor Sponsor
mirhagk
Posted: Wed Apr 04, 2012 8:32 am Post subject: RE:Turing Graphing Calculator (Help)
you can't use a variable in a constant declaration. It needs to know the value of x before the program starts. Just use a var for x.
Dreadnought
Posted: Wed Apr 04, 2012 11:02 am Post subject: Re: Turing Graphing Calculator (Help)
mirhagk wrote:
you can't use a variable in a constant declaration. It needs to know the value of x before the program starts. Just use a var for x.
Sure you can, mirhagk please read the documentation for const.
http://compsci.ca/holtsoft/doc/const.html wrote:
In the Pascal language, constants must have values known at compile time; Turing has no such restriction.
Turing:
% This is a example I used earlier, IT WORKS for i:0..20 const x := i *0.05% store the value we want (I'm using a constant to mimic the way a for loop works) put x
endfor
The real problem is that Draw.FillOval expects integers as arguments (I'm talking about x and fx) because it draws at specific pixel locations on the screen. Think about it, you're telling it to draw an oval centered at pixel 0.05 on the screen (in the x direction), which doesn't really make sense since there is pixel 1 and pixel 2 but nothing in between.
You can use round to round a real number to the nearest integer, but in this case that wont be enough, since all your values for x are between 0 and 1. What you need to do is multiply x by some number (try 10 or 20) and then round the result of that. Think of it as stretching a graph that goes from 0 to 1 on the x axis across 5 to 10 pixels on screen. (Note: I'm saying you should do this when you draw the dot, not when you compute fx)
Notice, that since fx will be real in this case too, you will need to do something similar for its value.
TW iz Rippin
Posted: Wed Apr 04, 2012 11:03 am Post subject: RE:Turing Graphing Calculator (Help)
yay i figured it out
code:
var fx : real
for i : -200 .. 200
const x := i / 20
fx := (in1 * (x ** 5)) + (in2 * (x ** 4)) + (in3 * (x ** 3)) + (in4 * (x ** 2)) + (in5 * x) + in6
Draw.FillOval (floor (x * 20) + 200, floor (fx * 20) + 200, 1, 1, brightred)
end for
Now.. can someone help me drawline between all the dots so it looks good?
Dreadnought
Posted: Wed Apr 04, 2012 11:21 am Post subject: Re: Turing Graphing Calculator (Help)
TW iz Rippin wrote:
Now.. can someone help me drawline between all the dots so it looks good?
Well, the dots are drawn at values you computed, just keep track of where the last dot was (using a variable or two) and draw a line between the last dot and the new one. (Note: you may need a special case for the first dot)
Now.. can someone help me drawline between all the dots so it looks good?
Well, the dots are drawn at values you computed, just keep track of where the last dot was (using a variable or two) and draw a line between the last dot and the new one. (Note: you may need a special case for the first dot)
you can't use a variable in a constant declaration. It needs to know the value of x before the program starts. Just use a var for x.
Sure you can, mirhagk please read the documentation for const.
http://compsci.ca/holtsoft/doc/const.html wrote:
In the Pascal language, constants must have values known at compile time; Turing has no such restriction.
Huh, did not know that. Just figured it was like a lot of languages where constants are inserted at compile time, rather than just being variables you can't change.
TW iz Rippin
Posted: Thu Apr 05, 2012 7:27 am Post subject: RE:Turing Graphing Calculator (Help)