Omnimaga

Calculator Community => Major Community Projects => The Axe Parser Project => Topic started by: Binder News on May 22, 2011, 10:11:11 pm

Title: The Smallest Axiom Ever (Optimized GetKey routine)
Post by: Binder News 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.
Title: Re: The Smallest Axiom Ever (Optimized GetKey routine)
Post by: calc84maniac 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.
Title: Re: The Smallest Axiom Ever (Optimized GetKey routine)
Post by: Binder News 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.
Title: Re: The Smallest Axiom Ever (Optimized GetKey routine)
Post by: jacobly 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
Title: Re: The Smallest Axiom Ever (Optimized GetKey routine)
Post by: Deep Toaster 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?