Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
26 May, 2013, 00:27:53 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1]   Go Down
  Print  
Author Topic: The Smallest Axiom Ever (Optimized GetKey routine) -  (Read 1137 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
Binder News
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: 13 May, 2013, 22:50:58
Date Registered: 26 October, 2010, 22:05:05
Location: In a pit on an island somewhere in the Atlantic.
Posts: 779


Topic starter
Total Post Ratings: +43

View Profile
« on: 23 May, 2011, 04:11:11 »
0

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.

* SpeedKey.z80 (0.43 KB - downloaded 83 times.)
* SpeedKey.8xp (0.11 KB - downloaded 71 times.)
Logged

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:




calc84maniac
Epic z80 roflpwner
Coder Of Tomorrow
LV11 Super Veteran (Next: 3000)
*
Offline Offline

Gender: Male
Last Login: Yesterday at 16:59:06
Date Registered: 28 August, 2008, 05:09:05
Location: Right behind you.
Posts: 2735


Total Post Ratings: +373

View Profile
« Reply #1 on: 23 May, 2011, 04:16:00 »
0

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.
Logged

"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman
Binder News
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: 13 May, 2013, 22:50:58
Date Registered: 26 October, 2010, 22:05:05
Location: In a pit on an island somewhere in the Atlantic.
Posts: 779


Topic starter
Total Post Ratings: +43

View Profile
« Reply #2 on: 23 May, 2011, 04:24:49 »
0

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.
Logged

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:




jacobly
LV4 Regular (Next: 200)
****
Offline Offline

Last Login: Yesterday at 21:17:40
Date Registered: 09 October, 2011, 01:53:09
Posts: 199

Total Post Ratings: +149

View Profile
« Reply #3 on: 23 January, 2012, 05:50:23 »
0

I believe this is now the smallest axiom ever. Cheesy

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.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#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

* SpeedKey.8Xv (0.12 KB - downloaded 42 times.)
* speedkey.8xv (0.12 KB - downloaded 16 times.)
« Last Edit: 28 June, 2012, 23:36:23 by jacobly » Logged
Deep Thought
So much to do, so much time, so little motivation
Administrator
LV13 Extreme Addict (Next: 9001)
*
Offline Offline

Gender: Male
Last Login: Yesterday at 19:54:09
Date Registered: 19 May, 2009, 08:00:00
Location: The Universe
Posts: 7813


Total Post Ratings: +706

View Profile WWW
« Reply #4 on: 28 January, 2012, 01:42:25 »
0

I'm sure someone could make a smaller Axiom that did nothing Tongue

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




Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.393 seconds with 31 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.