Skip to content

Instantly share code, notes, and snippets.

@tshirtman
Created February 17, 2020 01:40
Show Gist options
  • Save tshirtman/56b1fe7505bdaf50519b7fbe22db062b to your computer and use it in GitHub Desktop.
Save tshirtman/56b1fe7505bdaf50519b7fbe22db062b to your computer and use it in GitHub Desktop.
from random import choice, randint, random
from kivy.animation import Animation
from kivy.properties import ColorProperty, NumericProperty
from kivy.clock import Clock
from kivy.app import App
from kivy.lang import Builder
from kivy.factory import Factory as F
KV = '''
<Circles>:
canvas:
Color:
rgba: self.color1
Line:
cap: 'square'
width: self.width1
circle:
(
self.center_x, self.center_y,
self.radius1, self.start1, self.end1
)
Color:
rgba: self.color2
Line:
width: self.width2
cap: 'square'
circle:
(
self.center_x, self.center_y,
self.radius2, self.start2, self.end2
)
Color:
rgba: self.color3
Line:
width: self.width3
cap: 'square'
circle:
(
self.center_x, self.center_y,
self.radius3, self.start3, self.end3
)
Color:
rgba: self.color4
Line:
width: self.width4
cap: 'square'
circle:
(
self.center_x, self.center_y,
self.radius4, self.start4, self.end4
)
FloatLayout:
'''
class Circles(F.Widget):
color1 = ColorProperty()
color2 = ColorProperty()
color3 = ColorProperty()
color4 = ColorProperty()
radius1 = NumericProperty(0)
radius2 = NumericProperty(0)
radius3 = NumericProperty(0)
radius4 = NumericProperty(0)
width1 = NumericProperty(1)
width2 = NumericProperty(1)
width3 = NumericProperty(1)
width4 = NumericProperty(1)
start1 = NumericProperty()
start2 = NumericProperty()
start3 = NumericProperty()
start4 = NumericProperty()
end1 = NumericProperty()
end2 = NumericProperty()
end3 = NumericProperty()
end4 = NumericProperty()
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.delay = delay = random() * 10 + 5
Clock.schedule_interval(self.animate, delay)
self.color1=[random(), random(), random(), random() * .5 + .5]
self.color2=[random(), random(), random(), random() * .5 + .5]
self.color3=[random(), random(), random(), random() * .5 + .5]
self.color4=[random(), random(), random(), random() * .5 + .5]
self.radius1=randint(40, 100)
self.radius2=randint(40, 100)
self.radius3=randint(40, 100)
self.radius4=randint(40, 100)
self.width1=randint(1, 20)
self.width2=randint(1, 20)
self.width3=randint(1, 20)
self.width4=randint(1, 20)
self.start1=randint(0, 360)
self.start2=randint(0, 360)
self.start3=randint(0, 360)
self.start4=randint(0, 360)
self.end1=randint(0, 360)
self.end2=randint(0, 360)
self.end3=randint(0, 360)
self.end4=randint(0, 360)
self.animate()
def animate(self, *dt):
Animation(
d=self.delay,
t=choice(('out_quad', 'out_sine', 'linear')),
color1=[random(), random(), random(), random() * .5 + .5],
color2=[random(), random(), random(), random() * .5 + .5],
color3=[random(), random(), random(), random() * .5 + .5],
color4=[random(), random(), random(), random() * .5 + .5],
radius1=randint(40, 100),
radius2=randint(40, 100),
radius3=randint(40, 100),
radius4=randint(40, 100),
width1=randint(1, 20),
width2=randint(1, 20),
width3=randint(1, 20),
width4=randint(1, 20),
start1=randint(0, 360),
start2=randint(0, 360),
start3=randint(0, 360),
start4=randint(0, 360),
end1=randint(0, 360),
end2=randint(0, 360),
end3=randint(0, 360),
end4=randint(0, 360),
).start(self)
class Application(App):
def build(self):
root = Builder.load_string(KV)
for i in range(30):
root.add_widget(
Circles(
pos_hint={'center': (random(), random())}
)
)
return root
if __name__ == "__main__":
Application().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment