File size: 2,193 Bytes
b516e00 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | """
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()
|