Author Topic: The Smallest Axiom Ever (Optimized GetKey routine)  (Read 6244 times)

0 Members and 1 Guest are viewing this topic.

Offline Binder News

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 785
  • Rating: +46/-3
  • Zombie of Tomorrow
    • View Profile
The Smallest Axiom Ever (Optimized GetKey routine)
« on: May 22, 2011, 10:11:11 pm »
First, this Axiom is super-small. Compiled, it's about 60 bytes.
Anyways, it is an optimized form of GetKey when you only want ONE of the four arrow-keys.
For example, if I'm making a maze game where the player can only move up, down, left, or right, but not 2 at once, this would be perfect.
The command is the Zoom In token, with no modifiers.
Also, the version for your calc is a program. If you have it in RAM when you compile something using it, Axe will convert it to an Appvar, and put it into archive. You can then delete the program.
Spoiler For userbars:







Hacker-in-training!   Z80 Assembly Programmer     Axe Programmer
C++ H4X0R             Java Coder                           I <3 Python!

Perdidisti ludum     Cerebrum non habes

"We are humans first, no matter what."
"Fame is a vapor, popularity an accident, and riches take wings. Only one thing endures, and that is character."
Spoiler For Test Results:





Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: The Smallest Axiom Ever (Optimized GetKey routine)
« Reply #1 on: May 22, 2011, 10:16:00 pm »
Hmm, this routine doesn't seem to really check that only one of the keys is pressed. For example, if you pressed all the arrow keys at once, it would return 1.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Binder News

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 785
  • Rating: +46/-3
  • Zombie of Tomorrow
    • View Profile
Re: The Smallest Axiom Ever (Optimized GetKey routine)
« Reply #2 on: May 22, 2011, 10:24:49 pm »
Yes, but the purpose of the routine is that you only want one of the keys. The way I designed it means that the first one happens to be the down key, but it could be redesigned to allow for a different key to be checked first.
Spoiler For userbars:







Hacker-in-training!   Z80 Assembly Programmer     Axe Programmer
C++ H4X0R             Java Coder                           I <3 Python!

Perdidisti ludum     Cerebrum non habes

"We are humans first, no matter what."
"Fame is a vapor, popularity an accident, and riches take wings. Only one thing endures, and that is character."
Spoiler For Test Results:





Offline jacobly

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 205
  • Rating: +161/-1
    • View Profile
Re: The Smallest Axiom Ever (Optimized GetKey routine)
« Reply #3 on: January 22, 2012, 10:50:23 pm »
I believe this is now the smallest axiom ever. :D

The token for this axiom is Zoom Out. It returns what arrow keys are currently pressed. As an added bonus, opposite keys cancel each other out. For example, if both the left and right keys are pressed, then this axiom will return that neither key is pressed. This is useful if pressing a key results in a lot of computation, and pressing opposite keys results in nothing happening.

(In the following example, e is the euler e.)
Code: [Select]
#Axiom(SpeedKey)
Zoom Out→A
If Ae7
.down key pressed
End
If Ae6
.left key pressed
End
If Ae5
.right key pressed
End
If Ae4
.up key pressed
End

This axiom can also be used to easily check for 8 directions.
Code: [Select]
#Axiom(SpeedKey)
Zoom Out→A
If A=1
.south
ElseIf A=2
.west
ElseIf A=3
.south west
ElseIf A=4
.east
ElseIf A=5
.south east
ElseIf A=8
.north
ElseIf A=10
.north west
ElseIf A=12
.north east
End
« Last Edit: June 28, 2012, 05:36:23 pm by jacobly »

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: The Smallest Axiom Ever (Optimized GetKey routine)
« Reply #4 on: January 27, 2012, 06:42:25 pm »
I'm sure someone could make a smaller Axiom that did nothing :P

Anyway, these seem useful. Do they do anything if a non-arrow key is pressed?