-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
101 lines (75 loc) · 1.67 KB
/
main.lua
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
--
-- Voronoi polygon generator
-- ----------------------------------------------------------------------------
-- Generates voronoi polygons from a series of random points.
--
-- Author: paulpls
-- License: GPL 3.0
--
--
-- Parameters
--
local w,h = love.graphics.getDimensions()
local n = 32 -- Number of points to generate
local a = 1.0 -- Transparency, 0.0 -> 1.0
local d = 0.1 -- Animation delay, seconds
--
-- Dependencies
--
require "class"
local Grid = require "grid"
love.load = function ()
--
-- Load and randomize the grid
--
grid = Grid:new(w, h, n, a, d)
grid:randomize()
end
love.update = function (dt)
--
-- Update and animate the grid
--
grid:update(dt)
end
love.draw = function ()
--
-- Draw points and colors
--
grid:draw()
end
love.keypressed = function (key)
--
-- Detect keyboard input
--
if key == "escape" or key == "q" then
-- Quit
love.event.quit()
elseif key == "r" then
-- Soft refresh if animation has already begun
if grid.elapsed > 0 then
grid:refresh()
else
-- Hard refresh, then randomize
grid:refresh(true)
grid:randomize()
end
elseif key == "c" then
-- Clear all points and reset
grid:refresh(true)
elseif key == "space" then
-- Toggle animaton
grid.animate = not grid.animate
end
end
love.mousepressed = function (x, y)
--
-- Add points where clicked
--
if grid:validate(x, y) then grid:plot(x, y) end
end
love.quit = function ()
--
-- Bye, Felicia
--
print("\nDone")
end