Skip to content

Instantly share code, notes, and snippets.

@tshirtman
Created July 5, 2023 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tshirtman/16f283cabb63fa272467e1c4eb3b61bc to your computer and use it in GitHub Desktop.
Save tshirtman/16f283cabb63fa272467e1c4eb3b61bc to your computer and use it in GitHub Desktop.
from kivy.app import App
from kivy.lang import Builder
from kivy.clock import Clock
from kivy import properties as P
KV = '''
#:import chain itertools.chain
#:import sin math.sin
#:import pi math.pi
#:import rgba kivy.utils.rgba
#:set offset 66
<WigglyLine@Widget>:
top_func: lambda x: x
bottom_func: lambda x: x
step: 6
color: 0, 0, 0, 0
points:
tuple(chain((
self.x + x, self.y + self.top_func(x),
self.x + x, self.y + self.bottom_func(x + self.step),
self.x + x + self.step, self.y + self.bottom_func(x + self.step),
self.x + x + self.step, self.y + self.top_func(x + self.step * 2),
) for x in range(-self.width, self.width * 2, self.step * 2)
)) if self.top_func and self.bottom_func else ()
canvas:
Color:
rgba: self.color
Line:
width: 2
points: self.points or ()
FloatLayout:
WigglyLine:
top_func: lambda x: sin(2 * app.time + x) * 20 + 100
bottom_func: lambda x: sin(2 * app.time + x + pi) * 20 + 50
color: rgba("FFFFFF")
WigglyLine:
top_func: lambda x: sin(2 * app.time + x) * 20 + 150
bottom_func: lambda x: sin(2 * app.time + x + pi) * 20 + 106
color: rgba("AAAAAA")
x: offset
WigglyLine:
top_func: lambda x: sin(2 * app.time + x) * 20 + 200
bottom_func: lambda x: sin(2 * app.time + x + pi) * 20 + 156
color: rgba("555555")
x: offset * 2
WigglyLine:
top_func: lambda x: sin(2 * app.time + x) * 20 + 250
bottom_func: lambda x: sin(2 * app.time + x + pi) * 20 + 20e
color: rgba("333333")
x: offset * 3
'''
class Application(App):
time = P.NumericProperty()
def build(self):
Clock.schedule_interval(self._update_time, 0)
return Builder.load_string(KV)
def _update_time(self, dt):
self.time -= dt
if __name__ == "__main__":
Application().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment