X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=interpret-cairo-to-svg.py;h=bc0c6b1053ab8eaf406ea95f5c55d7f33a534bf3;hb=ffa1852b92b28242e1923f2036026e17766ff849;hp=de296f5288d02a3d538a63fd06235ff772fc6538;hpb=99fdf6accc38514ec375f05912741b7d4d2ecef6;p=zombocom-ai diff --git a/interpret-cairo-to-svg.py b/interpret-cairo-to-svg.py index de296f5..bc0c6b1 100755 --- a/interpret-cairo-to-svg.py +++ b/interpret-cairo-to-svg.py @@ -24,7 +24,7 @@ if "import" in input: (fd, filename) = tempfile.mkstemp(suffix=".svg", prefix="busart", dir=OUTPUT_DIR); os.close(fd) -os.chmod(filename, 0o644); +os.chmod(filename, 0o644) # Also delete our import for some more safety del tempfile @@ -789,33 +789,33 @@ COLORS = { 'yellow3': (0xcd/0xff, 0xcd/0xff, 0x00/0xff), 'yellow4': (0x8b/0xff, 0x8b/0xff, 0x00/0xff), 'yellowgreen': (0x9a/0xff, 0xcd/0xff, 0x32/0xff) -}; +} with cairo.SVGSurface(filename, 512, 512) as surface: cr = cairo.Context(surface); del cairo def arc(x, y, r, a1, a2): - cr.arc(x, y, r, a1, a2); + cr.arc(x, y, r, a1, a2) def circle(x, y, r): - cr.arc(x, y, r, 0, 2 * math.pi); + cr.arc(x, y, r, 0, 2 * math.pi) def fill(): - cr.fill(); + cr.fill() def set_color(color): if color in COLORS: - (r,g,b) = COLORS[color]; + (r,g,b) = COLORS[color] else: (r,g,b) = (0,0,0) cr.set_source_rgb(r, g, b) - cr.set_line_width(6); - exec(input) - -web_file = filename.removeprefix(OUTPUT_DIR_PREFIX); + cr.set_line_width(6) -print(web_file); + # Run the submitted code + exec(input) +web_file = filename.removeprefix(OUTPUT_DIR_PREFIX) +print(web_file)