Computer Science Canada

Real vs. Int

Author:  TokenHerbz [ Fri Oct 07, 2005 11:42 am ]
Post subject:  Real vs. Int

yeah i have a question about reals and int...

I personally use int because it works with drawfills, and reals dont, but reals look better, especially when trying to get a ball to gradually go faster...

Im aware that you can *round* the real to use it as n int, but wont it round it to the whole? making it usless as a decimal??

I just need some info on how this works...

Author:  Tony [ Fri Oct 07, 2005 12:13 pm ]
Post subject:  Re: Real vs. Int

tokenherbz wrote:
[int] works with drawfills

Well you can't exactly fill 0.25 of a pixel, now can you? Thinking

Author:  codemage [ Fri Oct 07, 2005 12:15 pm ]
Post subject: 

Some functions/procs don't work with reals. You have to live with that.

You can store variables as reals in some cases, and then round them before you actually use them in their respective function. ie:

functionthattakesanint ( round ( realnumbervariable) )

Author:  TokenHerbz [ Fri Oct 07, 2005 2:42 pm ]
Post subject: 

ok well to fill the oval on a real variable...

shall i make a for statment??

for i: 1 .. 10
drawoval(x,y,size+i,size+i,7) %%Where z,y,and size are reals
end for

Will that work?? etc:: i dont want to test it atm, i gotta go to work

Author:  md [ Fri Oct 07, 2005 2:48 pm ]
Post subject:  Re: Real vs. Int

Tony wrote:
tokenherbz wrote:
[int] works with drawfills

Well you can't exactly fill 0.25 of a pixel, now can you? Thinking


I disagree; if you fill a quarter of a blue (RGB[0,0,255]) with red then the pixel would become blue + red/4 = RGB[255/4,0,255]. This goes a surprisingly long way to reducing jaggies when you are rendering polygons.

Author:  Cervantes [ Fri Oct 07, 2005 2:53 pm ]
Post subject: 

Tokenherbz: No, that will not work. Did you even read codemage's post? Round it!

Author:  [Gandalf] [ Fri Oct 07, 2005 2:53 pm ]
Post subject: 

No, they need to be ints...

The advantage of using real numbers in this case is that you can use decimal numbers for calculations, which makes a rounded number more accurate, ie:
code:
var numA, numB, numC : real
var intA, intB, intC : int %The rounded ints
intA := 3
numA := 3.3
intB := 4
numB := 4.1
intC := 3
numC := 3.4
put numA, " + ", numB, " + ", numC
put "real answer: ", numA + numB + numC %if possible, use real numbers
put "rounded: ", round (numA + numB + numC) %this is the better if ints are needed
put intA, " + ", intB, " + ", intC
put "rounded ints: ", intA + intB + intC %if you used ints for calculations

Author:  Tony [ Fri Oct 07, 2005 3:10 pm ]
Post subject:  Re: Real vs. Int

Cornflake wrote:
if you fill a quarter of a blue (RGB[0,0,255]) with red then the pixel would become blue + red/4 = RGB[255/4,0,255].

You're absolutly right. Though that's not how Turing's draw functions work Wink


: