X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=interpret-cairo-to-svg.py;h=99edf1b1acc59bcc050e90cb2c2c9dc88a493027;hb=c602113cdb101e4664037eed3771559c0770f1c5;hp=bc0c6b1053ab8eaf406ea95f5c55d7f33a534bf3;hpb=ffa1852b92b28242e1923f2036026e17766ff849;p=zombocom-ai diff --git a/interpret-cairo-to-svg.py b/interpret-cairo-to-svg.py index bc0c6b1..99edf1b 100755 --- a/interpret-cairo-to-svg.py +++ b/interpret-cairo-to-svg.py @@ -26,6 +26,13 @@ if "import" in input: os.close(fd) os.chmod(filename, 0o644) +if len(sys.argv) < 2: + sys.stderr.write("This script requires a single argument (value, 1 - 4)") + sys.exit(1) + +user = int(sys.argv[1]) +stderr = sys.stderr + # Also delete our import for some more safety del tempfile del os @@ -791,10 +798,38 @@ COLORS = { 'yellowgreen': (0x9a/0xff, 0xcd/0xff, 0x32/0xff) } +hint = [ + "WAT", "ER ", "PLA", "NET" +] + +code = [ + "304", "570", "325", "6" +] + +r = 0 +g = 0 +b = 0 +a = 1.0 + with cairo.SVGSurface(filename, 512, 512) as surface: + cr = cairo.Context(surface); + cr.set_font_size(190) + cr.select_font_face("sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) del cairo + def random_within(max): + return max * random() + + def wiggle(): + delta = 200 + cr.rel_curve_to(-delta/2 + random_within(delta), + -delta/2 + random_within(delta), + -delta/2 + random_within(delta), + -delta/2 + random_within(delta), + -delta/2 + random_within(delta), + -delta/2 + random_within(delta)) + def arc(x, y, r, a1, a2): cr.arc(x, y, r, a1, a2) @@ -804,18 +839,52 @@ with cairo.SVGSurface(filename, 512, 512) as surface: def fill(): cr.fill() + def stroke(): + cr.stroke() + def set_color(color): + global r, g, b, a if color in COLORS: (r,g,b) = COLORS[color] else: (r,g,b) = (0,0,0) - cr.set_source_rgb(r, g, b) + cr.set_source_rgba(r, g, b, a) + + def set_random_color(): + global r, g, b, a + (r,g,b) = rand.choice(list(COLORS.values())) + cr.set_source_rgba(r, g, b, a) + + def set_opacity(opacity): + global a + a = opacity + cr.set_source_rgba(r, g, b, a) + + def move_to(x, y): + cr.move_to(x, y) - cr.set_line_width(6) + def line_to(x, y): + cr.line_to(x, y) + + def line(x, y, dx, dy): + cr.move_to(x, y) + cr.rel_line_to(dx, dy) + + def set_line_width(width): + cr.set_line_width(width) # Run the submitted code exec(input) + # After the submitted code, draw the solution in white, (so it will + # only be clearly visible if they've made their drawing big enough). + cr.set_source_rgb(1, 1, 1) + cr.move_to(0,250) + cr.show_text(hint[user]) + cr.set_font_size(240) + cr.move_to(0,480) + cr.show_text(code[user]) + web_file = filename.removeprefix(OUTPUT_DIR_PREFIX) print(web_file)