-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwind_weave.lua
87 lines (63 loc) · 2.12 KB
/
wind_weave.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
--[[
import the streamlines from streamlines.dat,
draw them using conkys cairo backend via wind_blow.lua.
moritz siegel @ 210623
]]--
require 'cairo'
-- set max number of streamlines.
threads = 5000
scale = 1920/360
x0 = 0
y0 = math.floor( ( 1080 - 181*scale )/2 )
wo = io.popen( "cat ~/wind/streamlines.dat" ) -- 10k eats up half of one core!
w = wo:read( "*all" )
wo:close()
bunch = {}
line = { x = {}, y = {} }
local pat = "(%S+)%s+(%S+)"
for xt, yt in string.gmatch( w, pat ) do
if ( xt == "0" and yt == "0" ) then --indicating new streamline block.
table.insert( bunch, line ) -- save whole streamline.
line = { x = {}, y = {} }
else
table.insert( line.x, xt ) -- save x y coordinates.
table.insert( line.y, yt )
end
end
heads = {}
for s = 1, #bunch do
table.insert( heads, math.floor( math.random( 60 ) ) )
end
function weave( thread, head, lwd, red, green, blue, alpha )
cairo_set_line_width(cr, lwd)
cairo_set_source_rgba (cr, red, green, blue, alpha);
head = math.floor( #thread.x * math.fmod( head + cursec, 60 )/60 )
for s = 1,head do
local xs = math.floor( x0 + thread.x[s] * scale )
local ys = math.floor( y0 + thread.y[s] * scale )
if ( s == 1 ) then
cairo_move_to( cr, xs, ys )
else
cairo_line_to( cr, xs, ys )
end
end
cairo_stroke_preserve( cr )
cairo_stroke( cr )
end
function conky_wind()
if conky_window == nil then return end
local cs = cairo_xlib_surface_create(conky_window.display,
conky_window.drawable,
conky_window.visual,
conky_window.width,
conky_window.height)
cr = cairo_create( cs )
cursec = tonumber( os.date("%S") ) --cursec = updates % slots.
quiver = math.min( #bunch, threads )
for b = 1,quiver do
-- val, start, lwd, red, green, blue, alpha
weave( bunch[b], heads[b], 1, 255, 255, 255, 0.2 )
end
cairo_destroy( cr )
cairo_surface_destroy( cs )
end