From be095be5c094cd439f1ce9b2646f4ef6f8be53b1 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 23 Dec 2022 11:39:48 -0800 Subject: [PATCH] Add Zombo's corruptions to the Magic School Bus artwork Of course, with excess fingers, mouths, and eyes. --- eye.svg | 65 +++++++++ hand.svg | 61 ++++++++ index.js | 21 ++- interpret-cairo-to-svg.py | 66 +++++++-- mouth.svg | 286 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 487 insertions(+), 12 deletions(-) create mode 100644 eye.svg create mode 100644 hand.svg create mode 100644 mouth.svg diff --git a/eye.svg b/eye.svg new file mode 100644 index 0000000..ce1db21 --- /dev/null +++ b/eye.svg @@ -0,0 +1,65 @@ + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/hand.svg b/hand.svg new file mode 100644 index 0000000..94c6360 --- /dev/null +++ b/hand.svg @@ -0,0 +1,61 @@ + + + + + + + + + + + + + diff --git a/index.js b/index.js index 606fba7..2f99074 100644 --- a/index.js +++ b/index.js @@ -191,7 +191,10 @@ bus_code = [ for i in range(400): set_color('midnight blue' if i % 2 == 0 else 'navy blue') set_opacity(0.5) - random_dot()`, + random_dot() + +# The only limit is your fingers! +fingers()`, `def random_line(): x = random_within(512) - 60 @@ -204,7 +207,10 @@ for i in range(400): for i in range(200): set_color('black') - random_line()`, + random_line() + +# This is Zombo.com. Welcome! +mouths()`, `def random_blob(): move_to(random_within(512), random_within(512)) @@ -214,7 +220,10 @@ for i in range(200): for i in range(100): set_random_color() - random_blob()`, + random_blob() + +# The infinite eyes is possible! +eyes()`, `def random_curve(): move_to(random_within(512), random_within(512)) @@ -223,7 +232,11 @@ for i in range(100): for i in range(200): set_color('pink' if i % 2 == 0 else 'lime green') - random_curve()` + random_curve() + +# You can do anything! +fingers() +` ]; io_bus.on("connection", (socket) => { diff --git a/interpret-cairo-to-svg.py b/interpret-cairo-to-svg.py index 99edf1b..9c90702 100755 --- a/interpret-cairo-to-svg.py +++ b/interpret-cairo-to-svg.py @@ -4,6 +4,9 @@ import cairo import tempfile import os import sys +import gi +gi.require_version('Rsvg', '2.0') +from gi.repository import Rsvg import math import random as rand @@ -37,6 +40,7 @@ stderr = sys.stderr del tempfile del os del sys +del gi # Note: We'll let the following "safe" imports remain: # @@ -816,7 +820,13 @@ 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) + # Setup RSVG rendering + rsvg = Rsvg.Handle() + + answer_shown = False + del cairo + del Rsvg def random_within(max): return max * random() @@ -873,17 +883,57 @@ with cairo.SVGSurface(filename, 512, 512) as surface: def set_line_width(width): cr.set_line_width(width) + def show_answer(): + global answer_shown + answer_shown = True + # 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]) + + def fingers(): + show_answer() + svg = rsvg.new_from_file("hand.svg") + cr.scale(0.2,0.2) + for i in range(16): + cr.save() + cr.translate(i%4 * 500, i/4 * 500) + cr.rotate(2 * math.pi * random()) + svg.render_cairo(cr) + cr.restore() + + def mouths(): + show_answer() + svg = rsvg.new_from_file("mouth.svg") + cr.scale(0.5,0.5) + for i in range(16): + cr.save() + cr.translate(i%4 * 150, i/4 * 150) + cr.rotate(2 * math.pi * random()) + svg.render_cairo(cr) + cr.restore() + + def eyes(): + show_answer() + svg = rsvg.new_from_file("eye.svg") + cr.scale(0.2,0.2) + for i in range(16): + cr.save() + cr.translate(i%4 * 600, i/4 * 600) + cr.rotate(2 * math.pi * random()) + svg.render_cairo(cr) + cr.restore() + # 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]) + # If the answer hasn't been shown yet, show it now + if not answer_shown: + show_answer() web_file = filename.removeprefix(OUTPUT_DIR_PREFIX) diff --git a/mouth.svg b/mouth.svg new file mode 100644 index 0000000..5f3b851 --- /dev/null +++ b/mouth.svg @@ -0,0 +1,286 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.43.0