Skip to content
Snippets Groups Projects
Commit a78a9e63 authored by pippin's avatar pippin
Browse files

clouds: move to Badge menu, use IMU and bundle_path

parent e0b6bd75
No related branches found
No related tags found
1 merge request!213clouds: move to Badge menu, use IMU and bundle_path
Pipeline #7281 passed
...@@ -6,7 +6,8 @@ from ctx import Context ...@@ -6,7 +6,8 @@ from ctx import Context
class Cloud: class Cloud:
def __init__(self, x: float, y: float, z: float) -> None: def __init__(self, path: str, x: float, y: float, z: float) -> None:
self.path = path
self.x = x self.x = x
self.y = y self.y = y
self.z = z self.z = z
...@@ -14,10 +15,10 @@ class Cloud: ...@@ -14,10 +15,10 @@ class Cloud:
def draw(self, ctx: Context) -> None: def draw(self, ctx: Context) -> None:
x = self.x / self.z * 120 x = self.x / self.z * 120
y = self.y / self.z * 120 y = self.y / self.z * 120
width = 200.0 / self.z * 120 width = 200.0 / self.z * 160
height = 100.0 / self.z * 120 height = 100.0 / self.z * 160
ctx.image( ctx.image(
"/flash/sys/apps/clouds/cloud.png", self.path,
x - width / 2, x - width / 2,
y - height / 2, y - height / 2,
width, width,
...@@ -29,11 +30,15 @@ class Clouds(Application): ...@@ -29,11 +30,15 @@ class Clouds(Application):
def __init__(self, app_ctx: ApplicationContext) -> None: def __init__(self, app_ctx: ApplicationContext) -> None:
super().__init__(app_ctx) super().__init__(app_ctx)
self.clouds = [] self.clouds = []
bundle_path = app_ctx.bundle_path
if bundle_path == "":
bundle_path = "/flash/sys/apps/clouds"
for i in range(10): for i in range(10):
self.clouds.append( self.clouds.append(
Cloud( Cloud(
bundle_path + "/cloud.png",
((random.getrandbits(16) - 32767) / 32767.0) * 200, ((random.getrandbits(16) - 32767) / 32767.0) * 200,
((random.getrandbits(16)) / 65535.0) * 50 - 5, ((random.getrandbits(16)) / 65535.0) * 60 - 10,
((random.getrandbits(16)) / 65535.0) * 200 + 5, ((random.getrandbits(16)) / 65535.0) * 200 + 5,
) )
) )
...@@ -41,9 +46,18 @@ class Clouds(Application): ...@@ -41,9 +46,18 @@ class Clouds(Application):
def think(self, ins: InputState, delta_ms: int) -> None: def think(self, ins: InputState, delta_ms: int) -> None:
super().think(ins, delta_ms) super().think(ins, delta_ms)
for c in self.clouds: for c in self.clouds:
c.z -= 40 * delta_ms / 1000.0 c.x -= (delta_ms / 1000.0) * ins.imu.acc[1] * 10
c.z -= (delta_ms / 1000.0) * (ins.imu.acc[2] - 5) * 20
# wrap x and z coordinates around
if c.z < 10: if c.z < 10:
c.z = 300 c.z = 300
elif c.z > 300:
c.z = 10
if c.x < -200:
c.x = 200
elif c.x > 200:
c.x = -200
self.clouds = sorted(self.clouds, key=lambda c: -c.z) self.clouds = sorted(self.clouds, key=lambda c: -c.z)
def draw(self, ctx: Context) -> None: def draw(self, ctx: Context) -> None:
......
[app] [app]
name = "Clouds" name = "Clouds"
menu = "Apps" menu = "Badge"
[entry] [entry]
class = "Clouds" class = "Clouds"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment