chamesle

chamesle.org: the site of Chamesle, a small Linux distribution
git clone https://github.com/tortr-rs/chamesle
Log | Files | Refs | README

wallpaper.py (3801B)


      1 #!/usr/bin/env python3
      2 # writes wallpaper.svg: a silk wave made of many thin lines, a glow, a vignette and grain
      3 # usage: wallpaper.py > wallpaper.svg
      4 import math
      5 
      6 W, H = 3840, 2160
      7 LINES = 90
      8 
      9 
     10 def wave(t, x, k=0):
     11     # height of line t (0..1) at x (0..1), k picks the ribbon
     12     a = 0.52 + 0.10 * math.sin(2.2 * x + 0.6 + 1.3 * k) - 0.16 * x + 0.11 * k
     13     b = 0.06 * math.sin(5.5 * x + 3.0 * t + 1.2) * (0.4 + t)
     14     # the ribbon twists: lines fan out, cross over and come back together
     15     spread = (t - 0.5) * (0.34 - 0.12 * k) * math.sin(3.4 * x + 0.5 - 1.1 * k) + 0.015 * math.sin(9 * x + 6 * t)
     16     return (a + b + spread) * H
     17 
     18 
     19 def path(t, k=0):
     20     pts = [(i / 60 * (W + 400) - 200, wave(t, i / 60, k)) for i in range(61)]
     21     d = "M%.1f %.1f" % pts[0]
     22     # catmull-rom through the points, as cubic beziers
     23     for i in range(1, len(pts) - 2):
     24         p0, p1, p2, p3 = pts[i - 1], pts[i], pts[i + 1], pts[i + 2]
     25         c1 = (p1[0] + (p2[0] - p0[0]) / 6, p1[1] + (p2[1] - p0[1]) / 6)
     26         c2 = (p2[0] - (p3[0] - p1[0]) / 6, p2[1] - (p3[1] - p1[1]) / 6)
     27         d += " C%.1f %.1f %.1f %.1f %.1f %.1f" % (c1 + c2 + p2)
     28     return d
     29 
     30 
     31 out = ['<svg xmlns="http://www.w3.org/2000/svg" width="%d" height="%d" viewBox="0 0 %d %d">' % (W, H, W, H), '''<defs>
     32   <linearGradient id="sky" x1="0" y1="0" x2="1" y2="1">
     33     <stop offset="0" stop-color="#06122a"/>
     34     <stop offset="0.5" stop-color="#0b2552"/>
     35     <stop offset="1" stop-color="#073a4f"/>
     36   </linearGradient>
     37   <linearGradient id="silk" x1="0" y1="0" x2="1" y2="0">
     38     <stop offset="0" stop-color="#3b82f6" stop-opacity="0"/>
     39     <stop offset="0.25" stop-color="#60a5fa" stop-opacity="0.9"/>
     40     <stop offset="0.6" stop-color="#38bdf8"/>
     41     <stop offset="1" stop-color="#2dd4bf" stop-opacity="0.9"/>
     42   </linearGradient>
     43   <radialGradient id="glow" cx="0.62" cy="0.48" r="0.5">
     44     <stop offset="0" stop-color="#2563eb" stop-opacity="0.45"/>
     45     <stop offset="1" stop-color="#2563eb" stop-opacity="0"/>
     46   </radialGradient>
     47   <radialGradient id="vignette" cx="0.5" cy="0.5" r="0.75">
     48     <stop offset="0.6" stop-color="#000" stop-opacity="0"/>
     49     <stop offset="1" stop-color="#000" stop-opacity="0.45"/>
     50   </radialGradient>
     51   <filter id="blur" x="-20%" y="-20%" width="140%" height="140%"><feGaussianBlur stdDeviation="40"/></filter>
     52   <filter id="grain" x="0" y="0" width="100%" height="100%">
     53     <feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="2" seed="7"/>
     54     <feColorMatrix values="0 0 0 0 0.5  0 0 0 0 0.5  0 0 0 0 0.5  0 0 0 0.06 0"/>
     55   </filter>
     56 </defs>''', '<rect width="%d" height="%d" fill="url(#sky)"/>' % (W, H),
     57        '<rect width="%d" height="%d" fill="url(#glow)"/>' % (W, H)]
     58 
     59 # a soft blurred copy of the wave underneath, then the lines on top
     60 out.append('<g filter="url(#blur)" opacity="0.25">')
     61 for i in range(0, LINES, 6):
     62     out.append('<path d="%s" fill="none" stroke="url(#silk)" stroke-width="40"/>' % path(i / (LINES - 1)))
     63 out.append('</g><g fill="none" stroke="url(#silk)">')
     64 for i in range(LINES):
     65     t = i / (LINES - 1)
     66     # brighter in the middle of the ribbon
     67     op = 0.10 + 0.55 * math.exp(-((t - 0.5) / 0.22) ** 2)
     68     out.append('<path d="%s" stroke-width="%.1f" stroke-opacity="%.3f"/>' % (path(t), 1.6 + 1.4 * (1 - abs(t - 0.5) * 2), op))
     69 out.append('</g>')
     70 # a second, fainter ribbon behind and below
     71 out.append('<g fill="none" stroke="url(#silk)" opacity="0.45">')
     72 for i in range(0, LINES, 2):
     73     t = i / (LINES - 1)
     74     out.append('<path d="%s" stroke-width="1.4" stroke-opacity="%.3f"/>' % (path(t, 1), 0.08 + 0.35 * math.exp(-((t - 0.5) / 0.25) ** 2)))
     75 out.append('</g>')
     76 out.append('<rect width="%d" height="%d" fill="url(#vignette)"/>' % (W, H))
     77 out.append('<rect width="%d" height="%d" filter="url(#grain)"/>' % (W, H))
     78 out.append('</svg>')
     79 print('\n'.join(out))