-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cr
54 lines (46 loc) · 1014 Bytes
/
test.cr
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
#!/usr/bin/env crystal
require "benchmark"
require "./src/crixel"
include Crixel
width = 64_u32
height = 64_u32
img = SixelImage.new(width, height)
def shade(x, y, time)
bg = 0x00FA9A_u32
fg = 0x61001E_u32
color = bg
vx = x + Math.sin(time * 3) * 10
vy = y + Math.cos(time * 3) * 10
if (vy % 32) < 16
if (vx % 32) > 16
color = fg
end
else
if (vx % 32) < 16
color = fg
end
end
color & 0xFFFFFF
end
t_start = Time.now
1.times do # replace with higher num for moar rendering
delta = Benchmark.realtime do
height.times do |y|
width.times do |x|
img.set(x, y, shade(x, y, (Time.now - t_start).total_seconds))
end
end
puts "normal implementation:"
d_norm = Benchmark.realtime do
img.render_full
end
puts "took #{d_norm}\n"
puts "naive implementation:"
d_naive = Benchmark.realtime do
img.render_naive_full
end
puts "took #{d_naive}\n"
end
max = 33.33.milliseconds
sleep max - delta
end