Author Topic: A few simple questions...  (Read 13332 times)

0 Members and 1 Guest are viewing this topic.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: A few simple questions...
« Reply #15 on: August 16, 2010, 01:22:26 am »
There is a way to get a kind of 'cheating' decimals, although it can be hard to grasp.  Lets represent all of our numbers x256.  So 1 would be 256, 17 would be 4352 and so on.  This means that we can represent numbers with an integer, but with more precision.  128 becomes .5, 400 becomes 1.5625, and so on.  All the math is the same, all that needs to change is your display.  Instead of

Pxl-On(X,Y

you would do

Pxl-On(X/256,Y/256

And this gives you much more precision.  You might want to experiment with this, as it can be quite useful, but it isn't necessary to make a great game.

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: A few simple questions...
« Reply #16 on: August 16, 2010, 01:25:45 am »
What you can do is "inflate" the value to get more accuracy.  256 is a great number since it's very optimized in both division and multiplication.  Since Axe variables hold 16-bit numbers, you can use the lower byte as the decimal and the higher byte as the number.  9.8 can be represented by 9 + 205/256.  You get your inflated number by multiplying by 256 so that's 9*256 + 205 = 2509 == 9.8 as an inflated decimal.  You can treat this number like any other number.  If you add 1 to it, you're really adding 1/256th and adding 256 is like adding 1, etc.  When it comes time to display the point, just divide by 256 so that you recover the integer part for the pixel.  So you're doing math with the precision of 1/256th and then just drawing it to the nearest pixel.

EDIT: Damn!  I knew I'd be ninja'd :P
« Last Edit: August 16, 2010, 01:26:19 am by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: A few simple questions...
« Reply #17 on: August 16, 2010, 01:31:37 am »
Actually, since it is just to the tenth's place, you could simply have another variable to use as the tenth's place.  Then, subtract the 8 from it.  If it wraps around, say to 248 and above, then subtract one off the integer counter, and change the decimal to the appropriate number by subtracting 246. Just remember that a negative number is really that number +256. so -8=248.

This works in theory, and should work in code, although is not tested.

[edit] double ninja'd, but with a different  response.
« Last Edit: August 16, 2010, 01:34:29 am by graphmastur »

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: A few simple questions...
« Reply #18 on: August 16, 2010, 01:34:29 am »
but wont it wrap around to 65536 since Axe is 16bit?

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: A few simple questions...
« Reply #19 on: August 16, 2010, 01:35:25 am »
Not unless he is dealing with 16 bit, I don't think.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: A few simple questions...
« Reply #20 on: August 16, 2010, 01:37:23 am »
But axe variables are 16bit by nature

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: A few simple questions...
« Reply #21 on: August 16, 2010, 02:38:27 am »
Builderboy, how did you implement gravity in Zedd? I'm pretty sure my formula Y-VT² is off.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: A few simple questions...
« Reply #22 on: August 16, 2010, 03:36:32 am »
Code: [Select]
.AA
ClrDraw
47->X
5->Y
0->V
Rect(0, 60, 96, 4)
For(A, 0, 200)
DispGraph
V-9.8->V
Y+V->Y
Pxl-On(X,Y)
Pause
If Y+2V>60
-V->V
End
End

Just wanted to point out some other things that you might want to change.  First off, there is no Implied multiplication in Axe, so things like 2V dont wok.  You need to do 2*V.  Secondly, there is no PEMDAS, everything is evaluated left to right.  So Y+2*V is really (Y+2)*V.  You should change it to V*2+Y.

Also, note that your initial velocity is 0, and then you Subtract 9 from it, making it negative.  This moves your pixel *up*, not down.  And whats more is that it will keep moving up indefinitely because you are waiting for it to go below the screen, but it just went off the top.

As for gravity, how it is done is simple.  There is a variable for velocity for each object, and ever frame, the position is incremented by the velocity, and the velocity is incremented by the acceleration.  For a deeper explanation you might want to check out my tutorial on Gravity and Acceleration over here: http://ourl.ca/4279

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: A few simple questions...
« Reply #23 on: August 16, 2010, 09:44:03 pm »
What you can do is "inflate" the value to get more accuracy.  256 is a great number since it's very optimized in both division and multiplication.  Since Axe variables hold 16-bit numbers, you can use the lower byte as the decimal and the higher byte as the number.  9.8 can be represented by 9 + 205/256.  You get your inflated number by multiplying by 256 so that's 9*256 + 205 = 2509 == 9.8 as an inflated decimal.  You can treat this number like any other number.  If you add 1 to it, you're really adding 1/256th and adding 256 is like adding 1, etc.  When it comes time to display the point, just divide by 256 so that you recover the integer part for the pixel.  So you're doing math with the precision of 1/256th and then just drawing it to the nearest pixel.

Let's say that 47->X and 32->Y, with velocities U and V respectively.

So, it would be something like
Code: [Select]
While 1
256*X+U->X
256*Y+V->Y
Pt-On(X/256, Y/256, Pic1)
End

 or am I not understanding this? I think I'm okay with the N mod 256 part, but I'm not sure if this is precisely that.
« Last Edit: August 16, 2010, 09:45:15 pm by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: A few simple questions...
« Reply #24 on: August 17, 2010, 12:18:40 am »
What you want is the initial conditions 47*256→X and 32*256→Y, and then use code like the following:

Code: [Select]
While 1
X+U→X
Y+V→Y
Pt-On(X/256, Y/256, Pic1)
End

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: A few simple questions...
« Reply #25 on: August 17, 2010, 12:55:13 am »
I really am new to this language. I've tried to rewrite the program like that at least a half dozen times without success.  It kept producing weird results, until the last time.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: A few simple questions...
« Reply #26 on: August 27, 2010, 12:55:27 pm »
I think I'll revive this thread...  with a new question!

I've tried using 'input' on Axe 0.4.4, but it keeps spewing this weird string of characters at the start.  I've attached a gif that shows what I'm talking about.
This is my code:
Code: [Select]
.INPUT
ClrHome
input->A
Disp A,i            //The i is the imaginary i for newline
Repeat getKey
End

What am I doing wrong, and how can I get rid of that string at the start?
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline Raylin

  • Godslayer
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1392
  • Rating: +83/-25
  • I am a certifiable squirrel ninja.
    • View Profile
    • Ray M. Perry
Re: A few simple questions...
« Reply #27 on: August 27, 2010, 01:53:37 pm »
I think that your input is actually unreadable right now.
Try using a >Char after something.
Bug me about my book.

Sarah: TI-83 Plus Silver Edition [OS 1.19]
Cassie: TI-86 [OS 1.XX]
Elizabeth: TI-81 [OS 1.XX]
Jehuty: TI-83 Plus Silver Edition [OS 1.19]
Tesla: CASIO Prizm







Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: A few simple questions...
« Reply #28 on: August 27, 2010, 03:00:45 pm »
That shouldn't be happening.  Is anyone else getting that?
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Tribal

  • The Fallen
  • LV5 Advanced (Next: 300)
  • *
  • Posts: 218
  • Rating: +15/-1
    • View Profile
Re: A few simple questions...
« Reply #29 on: August 27, 2010, 04:47:29 pm »
I typed the program given exactly and it doesn't do it to that extent per se, but when I typed in 'TEST' it appended a 'v' to the output the first time few times I tried it until I recompiled.