-
Notifications
You must be signed in to change notification settings - Fork 6
/
spinner1.nim
37 lines (35 loc) · 1.33 KB
/
spinner1.nim
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
import nimsvg, os, math
let settings = animSettings("examples" / sourceBaseName())
let numFrames = 40
settings.buildAnimation(numFrames) do (frame: int) -> Nodes:
let w = 200
let h = 200
let centerX = w / 2
let centerY = h / 2
let numDots = 20
let dotRadius = w / 40
let circleRadius = 0.4 * w.float
buildSvg:
svg(width=w, height=h, baseProfile="full"):
defs:
filter(id="shadow", x="-200%", y="-200%", width="500%", height="500%"):
feOffset(result="offOut", `in`="SourceAlpha", dx="2", dy="2")
feGaussianBlur(result="blurOut", `in`="offOut", stdDeviation="5")
feBlend(`in`="SourceGraphic", in2="blurOut", mode="normal")
for i in 0 ..< numDots:
let alpha = i / numDots * 2 * PI
let x = centerX + circleRadius * sin(alpha)
let y = centerY + circleRadius * cos(alpha)
let peakIndex = 1.0 - frame / numFrames
let frac = i / numDots
let dist = [
abs(peakIndex - frac),
abs(peakIndex - frac + 1),
abs(peakIndex - frac - 1),
].min()
let radius = dotRadius + max(dotRadius - dist*dist * 20, 0)
# call: echo(i, " ", frame, " ", dist, " ", peakIndex, " ", frac)
circle(
cx=x, cy=y, r=radius, stroke="#3D4574", `stroke-width`=1, fill="#DDD",
filter="url(#shadow)"
)