1+
2+ from ursina import *
3+ from random import randint
4+ import time
5+ import librosa
6+ import os
7+
8+ filename = 'input/Dior.mp3'
9+ # https://youtu.be/S0nOYs0PRak
10+
11+ y , sr = librosa .load (filename )
12+ t1 = int (time .time ())
13+ i = 0
14+
15+ app = Ursina ()
16+ camera .position = (5 ,0 ,- 30 )
17+ # os.startfile(filename)
18+
19+ c = 0
20+ opt_texture = [
21+ 'sky_default' ,
22+ 'heightmap_1' ,
23+ 'horizontal_gradient' ,
24+ 'noise' ,
25+ ]
26+
27+ def update ():
28+ global speed , deatils , cube , c , i
29+ t2 = int (time .time ())
30+ cube .texture = opt_texture [t2 % len (opt_texture )]
31+ # cube.texture = opt_texture[5]
32+
33+ red = randint (0 ,255 )
34+ green = randint (0 ,255 )
35+ blue = randint (0 ,255 )
36+ cube .color = color .rgb (red , green , blue )
37+
38+ deatils .text = f'''
39+ >>> Details ...
40+ -----------------------------
41+
42+ Time = { (t2 - t1 )// 60 } min { (t2 - t1 )% 60 } sec
43+ Texture = { str (cube .texture ).split ('.' )[0 ]}
44+ Speed = { speed }
45+
46+ Coordinate W = { cube .scale }
47+ Radius R = { sqrt ((cube .scale .x )** 2 + (cube .scale .y )** 2 + (cube .scale .z )** 2 )}
48+
49+ Rotation X = { cube .rotation_x }
50+ Rotation Y = { cube .rotation_y }
51+ Rotation Z = { cube .rotation_z }
52+
53+
54+
55+
56+
57+
58+ >>> Instruction ...
59+ ----------------------------
60+
61+ Press and Hold `W` or `S` key ...
62+ ... to adjust Sphere size.
63+
64+ Press and Hold `A` or `D` key ...
65+ ... to adjust Sphere speed.
66+ '''
67+
68+ try :
69+ print (i , sr , y [i ], t2 - t1 )
70+ cube .scale += (y [i ],y [i ],y [i ])
71+ i += int (sr / 45 )
72+ except :
73+ pass
74+
75+ if cube .scale .x > 10 :
76+ cube .scale = (5 ,5 ,5 )
77+
78+ if held_keys ['w' ]:
79+ cube .scale += (1 ,1 ,1 )
80+ if held_keys ['s' ]:
81+ cube .scale -= (1 ,1 ,1 )
82+
83+ if held_keys ['d' ]:
84+ speed += 5.0
85+ if held_keys ['a' ]:
86+ speed -= 5.0
87+
88+ cube .rotation_x -= time .dt * speed
89+ cube .rotation_y -= time .dt * speed
90+ cube .rotation_z -= time .dt * speed
91+
92+ speed = 220.0
93+ cube = Entity (model = 'sphere' ,
94+ color = color .red ,
95+ texture = 'sky_sunset' ,
96+ origin = (.1 ,.2 ,.1 ),
97+ scale = 6 ,
98+ )
99+
100+ deatils = Text (origin = (- .6 , - .07 ),
101+ font = 'VeraMono.ttf' ,
102+ color = color .red ,
103+ )
104+
105+ Sky ()
106+ window .fullscreen = 1
107+ app .run ()
0 commit comments