Skip to content

Commit 1524c71

Browse files
committed
Initial commit
1 parent 9400080 commit 1524c71

File tree

7 files changed

+335
-0
lines changed

7 files changed

+335
-0
lines changed

ClockSnow/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Snow Screen
2+
3+
<p align="center">
4+
<img align="center" src="https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/snow-screen.gif"/>
5+
</p>

ClockSnow/clock_snow_screen.kv

+176
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
#:import SnowFall snow.SnowFall
2+
#:import get_color_from_hex kivy.utils.get_color_from_hex
3+
4+
5+
<TemperatureCelsius@MDBoxLayout>
6+
scale: 1
7+
size_hint_y: None
8+
height: self.width
9+
adaptive_width: True
10+
padding: "4dp"
11+
12+
canvas.before:
13+
PushMatrix
14+
Scale:
15+
x: root.scale
16+
y: root.scale
17+
z: root.scale
18+
origin: self.center
19+
Color:
20+
rgba: app.theme_cls.primary_color
21+
RoundedRectangle:
22+
size: self.size
23+
pos: self.pos
24+
radius: [root.width / 2,]
25+
canvas.after:
26+
PopMatrix
27+
28+
MDLabel:
29+
adaptive_size: True
30+
text: "-3"
31+
pos_hint: {"center_y": .5}
32+
theme_text_color: "Custom"
33+
text_color: 1, 1, 1, 1
34+
35+
MDIcon:
36+
adaptive_size: True
37+
icon: "temperature-celsius"
38+
pos_hint: {"center_y": .5}
39+
theme_text_color: "Custom"
40+
text_color: 1, 1, 1, 1
41+
42+
43+
<SnowFlakeBg>
44+
canvas.before:
45+
PushMatrix
46+
Scale:
47+
x: root.scale
48+
y: root.scale
49+
z: root.scale
50+
origin: self.center
51+
Color:
52+
rgba: 0, 1, 1, .2
53+
RoundedRectangle:
54+
size: self.size
55+
pos: self.pos
56+
radius: [root.width / 2,]
57+
canvas.after:
58+
PopMatrix
59+
60+
61+
<ClockSnowScreen>
62+
canvas.before:
63+
Rectangle:
64+
size: self.size
65+
pos: self.pos
66+
source: "data/images/bg.png"
67+
68+
RoundShadowBox:
69+
size_hint: None, None
70+
size: "300dp", "300dp"
71+
md_bg_color: get_color_from_hex("#09222a")
72+
pos_hint: {"center_x": .5, "center_y": .5}
73+
74+
canvas.before:
75+
StencilPush
76+
RoundedRectangle:
77+
size: self.size
78+
pos: self.pos
79+
radius: [root.width / 2,]
80+
StencilUse
81+
82+
canvas.after:
83+
StencilUnUse
84+
RoundedRectangle:
85+
size: self.size
86+
pos: self.pos
87+
radius: [root.width / 2,]
88+
StencilPop
89+
90+
SnowFall:
91+
id: snow
92+
size_hint: None, None
93+
size: root.size
94+
number: 300
95+
size_range: (dp(2), dp(7))
96+
97+
SnowFlakeBg:
98+
id: snowflake_bg
99+
size_hint: None, None
100+
size: "110dp", "110dp"
101+
pos_hint: {"center_x": .5}
102+
y: snow.center[1] - dp(12)
103+
104+
MDIconButton:
105+
id: snowflake
106+
scale: 0
107+
icon: "snowflake"
108+
user_font_size: "72sp"
109+
pos_hint: {"center_x": .5, "center_y": .5}
110+
opposite_colors: True
111+
112+
canvas.before:
113+
PushMatrix
114+
Scale:
115+
x: self.scale
116+
y: self.scale
117+
z: self.scale
118+
origin: self.center
119+
canvas.after:
120+
PopMatrix
121+
122+
MDLabel:
123+
id: temperature_label
124+
scale: 0
125+
text: "TEMPERATURE"
126+
theme_text_color: "Custom"
127+
adaptive_size: True
128+
bold: True
129+
text_color: 1, 1, 1, .4
130+
font_name: "data/font/Weather.ttf"
131+
font_size: "24sp"
132+
x: snow.center[0] - self.width / 2
133+
y: snow.center[1] - self.height / 2 - dp(64)
134+
135+
canvas.before:
136+
PushMatrix
137+
Scale:
138+
y: self.scale
139+
origin: self.center
140+
canvas.after:
141+
PopMatrix
142+
143+
MDLabel:
144+
id: city_label
145+
scale: 0
146+
text: "FINLAND"
147+
theme_text_color: "Custom"
148+
adaptive_size: True
149+
bold: True
150+
text_color: 1, 1, 1, .4
151+
font_name: "data/font/Weather.ttf"
152+
font_size: "18sp"
153+
x: temperature_label.center[0] - self.width / 2
154+
y: temperature_label.center[1] - self.height / 2 - temperature_label.height
155+
156+
canvas.before:
157+
PushMatrix
158+
Scale:
159+
y: self.scale
160+
origin: self.center
161+
canvas.after:
162+
PopMatrix
163+
164+
TemperatureCelsius:
165+
id: temperature_celsius_box
166+
scale: 0
167+
y: snowflake_bg.y + self.height * 2 - root.shift_celsius_box / 2
168+
x: snowflake_bg.x + self.width / 2 + root.shift_celsius_box
169+
170+
canvas.before:
171+
PushMatrix
172+
Scale:
173+
y: self.scale
174+
origin: self.center
175+
canvas.after:
176+
PopMatrix

ClockSnow/clock_snow_screen.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import os
2+
3+
from kivy.animation import Animation
4+
from kivy.core.window import Window
5+
from kivy.lang import Builder
6+
from kivy.properties import NumericProperty
7+
from kivy.uix.widget import Widget
8+
9+
Window.size = (800, 600)
10+
Window.minimum_width, Window.minimum_height = Window.size
11+
12+
from kivymd.uix.screen import MDScreen
13+
from kivymd.uix.behaviors import CircularElevationBehavior
14+
from kivymd.uix.floatlayout import MDFloatLayout
15+
16+
17+
class ClockSnowScreen(MDScreen):
18+
shift_celsius_box = NumericProperty(0)
19+
20+
def start_animation_snowflake_bg(self, interval):
21+
Animation(scale=1, t="out_elastic", d=1.4).start(self.ids.snowflake_bg)
22+
23+
def start_animation_snowflake(self, interval):
24+
Animation(scale=1, t="out_elastic", d=1.4).start(self.ids.snowflake)
25+
26+
def start_animation_temperature_label(self, interval):
27+
Animation(scale=1, t="out_back", d=0.2).start(self.ids.temperature_label)
28+
29+
def start_animation_city_label(self, interval):
30+
Animation(scale=1, t="out_back", d=0.2).start(self.ids.city_label)
31+
32+
def start_animation_celsius_box(self, interval):
33+
Animation(shift_celsius_box=60, t="out_back", d=1.2).start(self)
34+
Animation(scale=1, t="out_elastic", d=1.2).start(self.ids.temperature_celsius_box)
35+
36+
37+
class RoundShadowBox(CircularElevationBehavior, MDFloatLayout):
38+
pass
39+
40+
41+
class SnowFlakeBg(MDFloatLayout):
42+
scale = NumericProperty(0)
43+
44+
45+
Builder.load_file(os.path.join(os.path.dirname(__file__), "clock_snow_screen.kv"))

ClockSnow/data/font/Weather.ttf

608 KB
Binary file not shown.

ClockSnow/data/images/bg.png

414 KB
Loading

ClockSnow/main.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from kivy.clock import Clock
2+
3+
from kivymd.app import MDApp
4+
5+
from clock_snow_screen import ClockSnowScreen
6+
7+
8+
class ClockSnow(MDApp):
9+
def build(self):
10+
return ClockSnowScreen()
11+
12+
def on_start(self):
13+
Clock.schedule_once(self.root.start_animation_snowflake_bg, 1)
14+
Clock.schedule_once(self.root.start_animation_snowflake, 2.2)
15+
Clock.schedule_once(self.root.start_animation_temperature_label, 3.2)
16+
Clock.schedule_once(self.root.start_animation_city_label, 3.2)
17+
Clock.schedule_once(self.root.start_animation_celsius_box, 2.8)
18+
19+
20+
ClockSnow().run()

ClockSnow/snow.py

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# https://gist.github.com/quitegreensky/9050acdb0cee666efb161ceaec564a85
2+
3+
from random import randint
4+
5+
from kivy.clock import Clock
6+
from kivy.metrics import dp
7+
from kivy.properties import ListProperty, NumericProperty
8+
from kivy.uix.floatlayout import FloatLayout
9+
from kivy.lang import Builder
10+
from kivy.animation import Animation
11+
12+
Builder.load_string(
13+
"""
14+
<SnowItem>
15+
opacity: 0
16+
size_hint: None, None
17+
18+
canvas.before:
19+
Color:
20+
rgba: .8, .8, .8, 1
21+
Ellipse:
22+
pos: self.pos
23+
size: self.size
24+
"""
25+
)
26+
27+
28+
class SnowItem(FloatLayout):
29+
def __init__(self, **kwargs):
30+
super().__init__(**kwargs)
31+
Clock.schedule_once(self._update)
32+
33+
def _update(self, *args):
34+
(Animation(opacity=1, d=randint(*self.parent.time_before_fade))).start(
35+
self)
36+
37+
38+
class SnowFall(FloatLayout):
39+
size_range = ListProperty([dp(5), dp(15)])
40+
time_range = ListProperty([3, 8])
41+
speed = ListProperty([4, 15])
42+
time_before_fade = ListProperty([0, 2])
43+
number = NumericProperty(50)
44+
45+
def __init__(self, **kwargs):
46+
super().__init__(**kwargs)
47+
Clock.schedule_once(self._update)
48+
49+
def add_item(self, count):
50+
for x in range(count):
51+
item = SnowItem(
52+
size=[
53+
randint(*self.size_range),
54+
randint(*self.size_range)
55+
],
56+
57+
pos=[
58+
randint(0, self.width),
59+
randint(int(self.height * 0.7), self.height)
60+
]
61+
)
62+
self.add_widget(item)
63+
self.start_anim(item)
64+
return item
65+
66+
def _update(self, *args):
67+
self.add_item(self.number)
68+
69+
def start_anim(self, item):
70+
target_pos = [randint(0, self.width), 0]
71+
final_time = randint(*self.time_range)
72+
73+
speed = randint(*self.time_range)
74+
anim = Animation(pos=target_pos, d=speed)
75+
anim.start(item)
76+
77+
# remove
78+
Clock.schedule_once(lambda x: self.remove_widget(item), final_time)
79+
80+
# add new
81+
Clock.schedule_once(lambda x: self.add_item(1), final_time)
82+
83+
fade_time = final_time - randint(*self.time_before_fade)
84+
Clock.schedule_once(lambda x: self._fade_out(item, fade_time),
85+
final_time - fade_time)
86+
87+
def _fade_out(self, item, time):
88+
anim = Animation(opacity=0, d=time)
89+
anim.start(item)

0 commit comments

Comments
 (0)