-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tl
129 lines (114 loc) · 3.27 KB
/
main.tl
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
--[[
little pomodoro timer script to go off on a configurable interval
based on https://gist.github.com/1bardesign/fac82485d67b8d97f6a38a68f685b5be#file-main-lua-L31
]]
require 'love'
local intervals = {
{"work", 25},
{"rest", 5},
}
local t = 0
local i = 0
local limit = 0
local label = ""
love.graphics.setFont(love.graphics.newFont(32))
local nosoundImg = love.graphics.newImage('nosound.png')
local sound = true
-- generate beep audio
local rate = 44100
local duration = 1.0
local freq_a = 440
local freq_b = 440 * 2
local samples = rate * duration
local beep: love.audio.Source -- = love.sound.newSoundData(samples, rate, 16, 1 )
local selectedBorder = false
local function genBeep(): love.sound.SoundData
local beepData = love.sound.newSoundData(samples, rate, 16, 1 )
for i = 1, samples do
local lt = i / rate
local note = ((1 - (i / samples)) * 2)
local note_vol = note % 1
local freq = note < 1 and freq_a or freq_b
local a = math.sin(lt * freq * math.pi * 2)
local b = (a * a) * 2 - 1
local v = a * b * note_vol
beepData:setSample(i - 1, 1, v)
end
return beepData
end
beep = love.audio.newSource(genBeep())
--function love.update(dt)
love.update = function(dt: number)
t = t - dt
if t <= 0 then
--beep
beep:seek(0)
if sound then
beep:play()
end
--next interval
i = i + 1
if i > #intervals then
i = 1
end
local cfg = intervals[i]
label = cfg[1]
limit = cfg[2] * 60
t = limit
end
local mx, my = love.mouse.getPosition()
local w, h = love.graphics.getDimensions()
--print(mx, my, )
if mx > 0 and my > 0 and mx < w and my < h then
selectedBorder = true
else
selectedBorder = false
end
end
local mode = "grey"
function love.draw()
--love.graphics.setColor(0.5, 0.5, 0.5, 1.0)
if label == "work" then
love.graphics.setColor(1.0, 0.0, 0., 1.)
elseif label == "rest" then
love.graphics.setColor(0., 1., 0., 1.)
end
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth() * t / limit, love.graphics.getHeight())
print("selectedBorder", selectedBorder )
--love.graphics.setColor(.0, .0, .0, 1.0)
--love.graphics.rectangle("line", 0, 0, love.graphics.getWidth() * t / limit, love.graphics.getHeight())
love.graphics.setColor(1.0, 1.0, 1.0, 1.0)
print('label', label)
love.graphics.printf( label, 0, 10, love.graphics.getWidth(), "center")
if not sound then
love.graphics.draw(nosoundImg as love.graphics.Drawable, 0, 0)
end
end
function love.keypressed(k: love.keyboard.KeyConstant)
--love.keypressed = function(k: string)
if k == "n" or k == "space" then
--skip to next
t = 0
end
if k == "r" then
mode = "red"
elseif k == "g" then
mode = "gray"
end
if k == "escape" then
love.event.quit()
end
if k == 's' then
sound = not sound
end
if love.keyboard.isDown("lctrl") then
if k == "q" then
love.event.quit()
elseif k == "r" then
love.event.quit("restart")
end
end
end
function love.mousemoved(_: number, _: number, dx: number, dy: number)
print("m", dx, dy)
end