Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
22 May, 2013, 09:35:02 *
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: [Lua] Speedcubing Timer -  (Read 555 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
NecroBumpist
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: 04 November, 2012, 07:02:18
Date Registered: 18 August, 2011, 05:44:50
Location: In my IDE, programming shit
Posts: 129


Topic starter
Total Post Ratings: +9

View Profile
« on: 21 December, 2011, 05:33:43 »
+1

Hey guys, it's been a while since I've contributed anything here, but over the last week I had some free time.
Last week I took 8 different finals, and in the time after the tests I spent crafting a tool to help me with a new passion of mine.

Speed cubing, or the process of competitively solving a Rubik's cube.

At first I included a simple timer, that was originally measured in milliseconds, but after further work I formatted the time into a 00:00.00 format and added a list of previous times, automagic saving, and statistic keeping (best, total average, average of 10, soon to be median 3 of 5 and 10 of 12)

So, the controls:
Enter: Start/stop the timer
"Y"/"N": After stopping the timer you have the option whether or not to add it to the list of times, the options should be obvious
"D": Clears the current list of times
"S"/"R": Saves/Recalls one saved list of times

Since I wrote this on calc, and not with the assistance of an emulator, I have no screenshots for you, but here's the code (hopefully it works after transcribing it from my calc)

I'll probably add new features here as I make them.
Note: You can just compile this with luna or something and run it on calc.

So if any of you guys are cubers, maybe you'll use this to practice when you can't access a computer  Smiley


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
tn, msg = 0, "";
t, n, aa, a10, b = 0, 0, 0, 0, 0
save = false
times = {};

function a()
local min, avg10, avga = 2^32, 0, 0
for i = 1, tn do
local v = times[i]
if v < min then
min = v
end
if i <= 10 then
avg10 = avg10 + v
end
avga = avga + v
end
b = min
aa = math.floor(avga/tn)
a10 = math.floor(avg10 / math.min(tn, 10))
end

function f(t)
return ("%02d:%02d.%02d"):format(t/60000, t/1000%60, t/10%100)
end

function on.paint(g)
if c then
t = (timer.getMilliSecCounter() - n)
end
g:drawString("time: " .. f(t), 0, 0, "top");
g:drawString(msg, 0, 20, "top");
g:drawString("best:              " .. f(b), 150, 0, "top");
g:drawString("average (10): " .. f(a10), 150, 20, "top");
g:drawString("average (all): " .. f(aa), 150, 40, "top");
for i = 1, 8 do
local v = times[i];
if not v then break end
g:drawString(i .. ")      " .. f(v), 0, 20+i*20, "top")
end
timer.start(0.01);
end

function on.timer()
timer.stop()
platform.window:invalidate()
end

function on.charIn(c)
if save then
save = false
msg = ""
if c == "y" then
table.insert(times, 1, t)
tn = tn + 1
a()
on.charIn("s")
end
end
if c == "d" then
t = 0
times = {};
tn = 0;
msg = "";
a();
elseif c == "s" then
local s = "" .. tn
msg = "saved"
for i = 1, tn do
s = s .. " " .. times[i]
end
var.store("cube_times", s .. " ");
elseif c == "r" then
local s, b , n = var.recall("cube_times") or "0 ", {}, 0;
msg = "loaded";
for w in s:gmatch("%d+%s") do
n = n + 1;
b[n] = tonumber(w);
end
tn = table.remove(b, 1);
times = b;
a();
end
end

function on.enterKey()
 if save then
 save = false
msg = ""
return
end
if c then
save = true;
msg = "save? (y/n)";
c = nil;
else
c = true;
msg = "";
n = timer.getMilliSecCounter();
end
end

on.charIn("r")

« Last Edit: 21 December, 2011, 18:47:01 by NecroBumpist » Logged

Developing Lua scripts for the NSpire ?
Check out the Necrotorium
Need a few routines to run faster ? Checkout the MODS Lua Assembly Toolkit.
Need to save space for your scripts ? Checkout LuaSrcDiet
Jim Bauwens
Lua! Nspire! Linux!
Editor
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Today at 08:05:41
Date Registered: 28 February, 2011, 22:32:12
Location: Belgium
Posts: 1733


Total Post Ratings: +180

View Profile WWW
« Reply #1 on: 21 December, 2011, 08:39:35 »
0

I'll check it out when I got some time Smiley
Logged

Nick
LV9 Veteran (Next: 1337)
*********
Offline Offline

Gender: Male
Last Login: 20 May, 2013, 20:44:19
Date Registered: 05 June, 2011, 20:01:07
Location: 51° 12′ 34″ N, 3° 13′ 31″ E
Posts: 1178


Total Post Ratings: +158

View Profile WWW
« Reply #2 on: 21 December, 2011, 09:04:53 »
0


1
2
nice, but i had to put this in the code:
[code],2^32,2^32
in

1
2
3
function a()
local min, avg10, avga = 2^32[b],2^32,2^32[/b]

and the averages are in milliseconds again?

but except for those things, it works perfect, and is fast (i mean it stops when you enter, and not a second later)[/code]
« Last Edit: 21 December, 2011, 09:06:44 by Nick » Logged

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

Gender: Male
Last Login: 04 November, 2012, 07:02:18
Date Registered: 18 August, 2011, 05:44:50
Location: In my IDE, programming shit
Posts: 129


Topic starter
Total Post Ratings: +9

View Profile
« Reply #3 on: 21 December, 2011, 18:46:30 »
0

nice, but i had to put this in the code:

1
,2^32,2^32
in

1
2
3
function a()
local min, avg10, avga = 2^32,2^32,2^32

and the averages are in milliseconds again?

but except for those things, it works perfect, and is fast (i mean it stops when you enter, and not a second later)

Oh yeah, I forgot that avg10 and avga need to be initialized to a number before they can be used, so I'll go change that.

And yes, all the times are stored and manipulated in milliseconds, then before it's printed to the screen it gets formatted into the 00:00.00 format.
Logged

Developing Lua scripts for the NSpire ?
Check out the Necrotorium
Need a few routines to run faster ? Checkout the MODS Lua Assembly Toolkit.
Need to save space for your scripts ? Checkout LuaSrcDiet
Nick
LV9 Veteran (Next: 1337)
*********
Offline Offline

Gender: Male
Last Login: 20 May, 2013, 20:44:19
Date Registered: 05 June, 2011, 20:01:07
Location: 51° 12′ 34″ N, 3° 13′ 31″ E
Posts: 1178


Total Post Ratings: +158

View Profile WWW
« Reply #4 on: 21 December, 2011, 18:53:40 »
0

one thing you could add is a random scrambler to (well yeah, you could guess this) scramble the cube before you start (like RU (right up) LD (left down) etc etc) so you can totally use it as a rubik's game
oh and do you use the modulus to calculate, or another way?

is scramble te right word for this? xp
« Last Edit: 21 December, 2011, 18:56:25 by Nick » Logged

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

Gender: Male
Last Login: 04 November, 2012, 07:02:18
Date Registered: 18 August, 2011, 05:44:50
Location: In my IDE, programming shit
Posts: 129


Topic starter
Total Post Ratings: +9

View Profile
« Reply #5 on: 21 December, 2011, 19:14:59 »
0

one thing you could add is a random scrambler to (well yeah, you could guess this) scramble the cube before you start (like RU (right up) LD (left down) etc etc) so you can totally use it as a rubik's game
oh and do you use the modulus to calculate, or another way?

is scramble te right word for this? xp

Yeah, I've though of adding a scramble generator, so I'll get started on that soon.

I use both plain division and modulus for formatting the time for simplicity, for averages it's division and math.floor()
Logged

Developing Lua scripts for the NSpire ?
Check out the Necrotorium
Need a few routines to run faster ? Checkout the MODS Lua Assembly Toolkit.
Need to save space for your scripts ? Checkout LuaSrcDiet
Nick
LV9 Veteran (Next: 1337)
*********
Offline Offline

Gender: Male
Last Login: 20 May, 2013, 20:44:19
Date Registered: 05 June, 2011, 20:01:07
Location: 51° 12′ 34″ N, 3° 13′ 31″ E
Posts: 1178


Total Post Ratings: +158

View Profile WWW
« Reply #6 on: 21 December, 2011, 19:26:23 »
0

i just read you couldn't get a screenshot, so here is one.
i hope i've used all functions possible, but i think so

screenietime Smiley


i have to be honest: the timer runs a lot smoother on calc, you can see the milliseconds passing, and here it just flickers, but that is to make it not too huge to upload..
« Last Edit: 21 December, 2011, 19:26:37 by Nick » 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.317 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.