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

Username:   Password: 
 RegisterRegister   
 Turing Graphing Calculator (Help)
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TW iz Rippin




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




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




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


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




PostPosted: Wed Apr 04, 2012 11:03 am   Post subject: RE:Turing Graphing Calculator (Help)

yay i figured it out Smile

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? Smile
Dreadnought




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


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)

I hope that made sense.
TW iz Rippin




PostPosted: Wed Apr 04, 2012 1:06 pm   Post subject: Re: Turing Graphing Calculator (Help)

Dreadnought @ Wed Apr 04, 2012 11:21 am wrote:
TW iz Rippin wrote:
Now.. can someone help me drawline between all the dots so it looks good? Smile


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)

I hope that made sense.


sure does! ty
Raknarg




PostPosted: Wed Apr 04, 2012 1:24 pm   Post subject: RE:Turing Graphing Calculator (Help)

Just an interestiong note, in Turing you can state anything anywhere, but it will only be active for that space. for instance, if I did this:

loop
var x
end loop

It would work, but I would not be allowed to use it outside that loop
TW iz Rippin




PostPosted: Wed Apr 04, 2012 2:19 pm   Post subject: RE:Turing Graphing Calculator (Help)

YES!!!!!!!!!!! Thanks so much for all the help guys

here is the code... (not posting full code with gui just the function:

code:

for i : -200 .. 200
    const x := i / 20
    var xx := x
    fx := (text1 * (xx ** 5)) + (text2 * (xx ** 4)) + (text3 * (xx ** 3)) + (text4 * (xx ** 2)) + (text5 * xx) + text6
    Draw.FillOval (floor (xx * 20) + 200, floor (fx * 20) + 200, 1, 1, brightred)
    var track1 : real := floor (xx * 20) + 200
    var track12 : real := floor (fx * 20) + 200
    xx := xx + 1
    fx := (text1 * (xx ** 5)) + (text2 * (xx ** 4)) + (text3 * (xx ** 3)) + (text4 * (xx ** 2)) + (text5 * xx) + text6
    Draw.FillOval (floor (xx * 20) + 200, floor (fx * 20) + 200, 1, 1, brightred)
    var track2 : real := floor (xx * 20) + 200
    var track22 : real := floor (fx * 20) + 200
    drawline (round (track1), round (track12), round (track2), round (track22), brightred)
end for


ty again I <3 you all
Sponsor
Sponsor
Sponsor
sponsor
mirhagk




PostPosted: Wed Apr 04, 2012 3:11 pm   Post subject: Re: Turing Graphing Calculator (Help)

Dreadnought @ Wed Apr 04, 2012 11:02 am wrote:
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.


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




PostPosted: Thu Apr 05, 2012 7:27 am   Post subject: RE:Turing Graphing Calculator (Help)

bump
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 2 of 2  [ 25 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: