diff --git a/python_payload/apps/clouds/__init__.py b/python_payload/apps/clouds/__init__.py index 3adc4e8951f4b649c0dcc6d1ba67a9679cb5754d..b7d6c0abe0fdd6dd32dd173c560d90c6a33c79a9 100644 --- a/python_payload/apps/clouds/__init__.py +++ b/python_payload/apps/clouds/__init__.py @@ -71,6 +71,10 @@ class App(Application): for c in self.clouds: c.draw(ctx) + def on_enter(self, vm): + super().on_enter(vm) + sys_display.set_mode(24 + sys_display.osd) + if __name__ == "__main__": from st3m.run import run_app diff --git a/python_payload/apps/mandelbrot/1bit.py b/python_payload/apps/mandelbrot/1bit.py new file mode 100644 index 0000000000000000000000000000000000000000..adbc7bad999e5725559de79ff1b25ec913cd1a24 --- /dev/null +++ b/python_payload/apps/mandelbrot/1bit.py @@ -0,0 +1,65 @@ +from st3m.application import Application +import sys_display, math, random + + +class App(Application): + def __init__(self, app_ctx): + super().__init__(app_ctx) + + def on_enter(self, vm): + super().on_enter(vm) + sys_display.set_mode(1) + pal = bytearray(256 * 3) + modr = random.getrandbits(7) + 1 + modg = random.getrandbits(7) + 1 + modb = random.getrandbits(7) + 1 + + pal[0 * 3] = 0 + pal[0 * 3 + 1] = 0 + pal[0 * 3 + 2] = 0 + pal[1 * 3] = 255 + pal[1 * 3 + 1] = 255 + pal[1 * 3 + 2] = 255 + sys_display.set_palette(pal) + self.y = 0 + self.xa = -1.5 + self.xb = 1.5 + self.ya = -2.0 + self.yb = 1.0 + + def draw(self, ctx: Context): + fb_info = sys_display.fb(0) + fb = fb_info[0] + + max_iterations = 30 + + width = fb_info[1] + height = fb_info[2] + stride = fb_info[3] + + for chunk in range(3): # do 3 scanlines at a time + y = self.y + if y < height: + zy = y * (self.yb - self.ya) / (height - 1) + self.ya + inners = 0 + for x in range(width): + zx = x * (self.xb - self.xa) / (width - 1) + self.xa + z = zy + zx * 1j + c = z + reached = 0 + for i in range(max_iterations): + if abs(z) > 2.0: + break + z = z * z + c + reached = i + val = reached * 255 / max_iterations + val = int(math.sqrt(val / 255) * 16) & 1 + fb[int((y * stride * 8 + x) / 8)] |= int(val) << (x & 7) + + self.y += 1 + + +if __name__ == "__main__": + import st3m.run + + st3m.run.run_app(App) diff --git a/python_payload/apps/mandelbrot/4bit.py b/python_payload/apps/mandelbrot/4bit.py index 628e05c53ea20cdfe6022467a4e2fe6e4318fba5..7c6a293c058ea5c3397be2be2144a5d99c324d9a 100644 --- a/python_payload/apps/mandelbrot/4bit.py +++ b/python_payload/apps/mandelbrot/4bit.py @@ -16,20 +16,22 @@ class App(Application): self.yb = 1.0 def draw(self, ctx: Context): - fb = sys_display.fb(4) + fb_info = sys_display.fb(0) + fb = fb_info[0] max_iterations = 30 - imgx = 240 - imgy = 240 + width = fb_info[1] + height = fb_info[2] + stride = fb_info[3] for chunk in range(3): # do 3 scanlines at a time y = self.y - if y < 240: - zy = y * (self.yb - self.ya) / (imgy - 1) + self.ya + if y < height: + zy = y * (self.yb - self.ya) / (height - 1) + self.ya inners = 0 - for x in range(imgx): - zx = x * (self.xb - self.xa) / (imgx - 1) + self.xa + for x in range(width): + zx = x * (self.xb - self.xa) / (width - 1) + self.xa z = zy + zx * 1j c = z reached = 0 @@ -42,8 +44,7 @@ class App(Application): val = math.sqrt(val / 255) * 16 if val > 15: val = 15 - oval = fb[int((y * 240 + x) / 2)] - fb[int((y * 240 + x) / 2)] = oval | (int(val) << ((x & 1) * 4)) + fb[int((y * stride * 2 + x) / 2)] |= int(val) << ((x & 1) * 4) self.y += 1 def think(self, ins, delta_ms): diff --git a/python_payload/apps/mandelbrot/__init__.py b/python_payload/apps/mandelbrot/__init__.py index 38ddd4dba91ec66c5ca930ea03e93f1a2a81164e..317680b1f8aa602d74470489253d8f12ae3c90bb 100644 --- a/python_payload/apps/mandelbrot/__init__.py +++ b/python_payload/apps/mandelbrot/__init__.py @@ -8,7 +8,7 @@ class App(Application): def on_enter(self, vm): super().on_enter(vm) - sys_display.set_mode(8) + sys_display.set_mode(sys_display.cool | sys_display.x2) self.y = 0 self.xa = -1.5 self.xb = 1.5 @@ -16,24 +16,26 @@ class App(Application): self.yb = 1.0 def draw(self, ctx: Context): - fb = sys_display.fb(8) + fb_info = sys_display.fb(sys_display.cool) + fb = fb_info[0] max_iterations = 30 - imgx = 240 - imgy = 240 + width = fb_info[1] + height = fb_info[2] + stride = fb_info[3] for chunk in range(3): # do 3 scanlines at a time y = self.y - if y < 240: - zy = y * (self.yb - self.ya) / (imgy - 1) + self.ya + if y < height: + zy = y * (self.yb - self.ya) / (height - 1) + self.ya inners = 0 - for x in range(imgx / 2): - zx = x * (self.xb - self.xa) / (imgx - 1) + self.xa + for x in range(width / 2): + zx = x * (self.xb - self.xa) / (width - 1) + self.xa z = zy + zx * 1j c = z reached = 0 - if inners > 10 and y < 180: + if inners > 10 and y < height * 0.7: reached = max_iterations - 1 else: for i in range(max_iterations): @@ -45,8 +47,8 @@ class App(Application): inners += 1 val = reached * 255 / max_iterations val = math.sqrt(val / 255) * 255 - fb[y * 240 + x] = int(val) - fb[y * 240 + 239 - x] = int(val) + fb[y * stride + x] = int(val) + fb[y * stride + width - 1 - x] = int(val) self.y += 1 def think(self, ins, delta_ms):