Release NaraMotion v0.26.0: Structure of Arrays (SoA), Path Arena Allocator, Uniform Grid Indexing, Dual-Buffer Rendering & Centroid Spring Pop-in
b516e00 verified Download examples/01_basic_shapes.py from ArifiIslam/NaraMotion: direct link, hf CLI and curl.
- Browser
- Download file 2.19 kB
-
https://huggingface.co/ArifiIslam/NaraMotion/resolve/main/examples/01_basic_shapes.py
- Command line
-
hf download hf://ArifiIslam/NaraMotion/examples/01_basic_shapes.py
-
curl -L -o 01_basic_shapes.py https://huggingface.co/ArifiIslam/NaraMotion/resolve/main/examples/01_basic_shapes.py
2.19 kB
| """ | |
| NaraMotion Example 01: Basic Shapes & Primitives | |
| """ | |
| import os | |
| from naramotion import Image, Context, Format, Rect, Circle, RoundRect, Triangle, Path | |
| def main(): | |
| width, height = 800, 600 | |
| img = Image(width, height, Format.PRGB32) | |
| with Context(img) as ctx: | |
| # Dark clean background | |
| ctx.fill_all("#121826") | |
| # 1. Antialiased smooth Circles with glow / outline | |
| ctx.fill_circle(150, 150, 80, "#3B82F6") | |
| ctx.stroke_width = 4.0 | |
| ctx.stroke_circle(150, 150, 80, "#93C5FD") | |
| # 2. Rounded Rectangle with custom radii | |
| ctx.fill_round_rect(300, 70, 200, 160, 24, "#10B981") | |
| ctx.stroke_width = 3.0 | |
| ctx.stroke_round_rect(300, 70, 200, 160, 24, "#A7F3D0") | |
| # 3. Triangle | |
| ctx.fill_triangle(650, 70, 560, 230, 740, 230, "#F59E0B") | |
| ctx.stroke_width = 3.0 | |
| ctx.stroke_triangle(650, 70, 560, 230, 740, 230, "#FDE68A") | |
| # 4. Five-pointed Star vector path | |
| star = Path() | |
| import math | |
| cx, cy, r_outer, r_inner, points = 150, 420, 90, 40, 5 | |
| for i in range(points * 2): | |
| r = r_outer if i % 2 == 0 else r_inner | |
| angle = i * math.pi / points - math.pi / 2 | |
| x = cx + r * math.cos(angle) | |
| y = cy + r * math.sin(angle) | |
| if i == 0: | |
| star.move_to(x, y) | |
| else: | |
| star.line_to(x, y) | |
| star.close() | |
| ctx.fill_path(star, "#EC4899") | |
| ctx.stroke_width = 4.0 | |
| ctx.stroke_path(star, "#FBCFE8") | |
| # 5. Concentric Arc / Pie segments | |
| ctx.fill_pie(400, 420, 80, 80, 0.0, 4.2, "#8B5CF6") | |
| ctx.stroke_width = 5.0 | |
| ctx.stroke_arc(400, 420, 100, 100, 0.0, 5.5, "#C4B5FD") | |
| # 6. Smooth rounded pill shape | |
| ctx.fill_round_rect(560, 370, 180, 90, 45, "#06B6D4") | |
| ctx.stroke_width = 4.0 | |
| ctx.stroke_round_rect(560, 370, 180, 90, 45, "#CFFAFE") | |
| os.makedirs("output", exist_ok=True) | |
| out_file = "output/01_basic_shapes.png" | |
| img.write_to_file(out_file) | |
| print(f"Saved: {out_file}") | |
| if __name__ == "__main__": | |
| main() | |