Skip to content

Commit

Permalink
min mas
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehvix committed Nov 30, 2021
1 parent 4cb1d38 commit 6bd6866
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 62 deletions.
17 changes: 11 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# whitelist
/*

!/.gitignore
!/CNAME
!/README.md
!/index.html
!/contest.scm
!/m-scheme-EschQR

!/url*
!/*png
!/gen-scm-qr.py
!/gen-site-qr.py
!/gen-py-qr.py
!/*py-qr*
!/img*.py
doodle*

!/*.png
!/*.scm
!/*.sh
!/*.js

# blacklist
doodle*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MSE

MSE Scheme EschQR<br>
M. Scheme EschQR<br>
Scheme<br>
EschQR<br>

Expand Down
27 changes: 27 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

log() {
now=$(date +"%T.%3N")
echo "$now :: $1"
}

TMP="img-min-tmp.py"
MIN="img-min.py"
GEN="img-to-scm.py"

log "Removing contest.scm..."
command rm contest.scm
log "Minifying $GEN..."
command pyminifier -o $TMP --lzma $GEN # todo pipe to log
MIN="img-min.py"
command head -n -1 $TMP >$MIN
log "Evaluating Python code to get scheme..."
command python $GEN >/dev/null
log "Generating QR of min and reg Python..."
command python gen-py-qr.py $MIN >/dev/null
command python gen-py-qr.py $GEN >/dev/null
log "Evaluating scheme code..."
command python3 scheme.py contest.scm --pillow-turtle --turtle-save-path output >/dev/null
log "Removing tmp files..."
command rm $TMP
command rm $MIN
11 changes: 11 additions & 0 deletions flip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let n = true;
function flippy() {
n = !n;
let fn = "";
if (n) {
fn = "py-qr-reg.png";
} else {
fn = "py-qr-min.png";
}
document.getElementById("QR").setAttribute("src", fn);
}
11 changes: 7 additions & 4 deletions gen-py-qr.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/usr/bin/python
import sys
import qrcode

SCHEME_DATA = open("img-min.py").read()
# SCHEME_DATA = open("img-to-scm.py").read()
py = sys.argv[1]
fn = "py-qr-reg.png" if "min" in py else "py-qr-min.png"
SCHEME_DATA = open(py).read()

qr = qrcode.QRCode()
qr = qrcode.QRCode(border=1, error_correction=qrcode.constants.ERROR_CORRECT_L)
qr.add_data(SCHEME_DATA)
img = qr.make_image()
img.save("py-qr.png")
img.save(fn)
21 changes: 0 additions & 21 deletions img-min.py

This file was deleted.

54 changes: 30 additions & 24 deletions img-to-scm.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
import qrcode
from PIL import Image
from numpy import array
try:
from PIL import Image
from numpy import array
import qrcode

QR_SIZE = 23
CANVAS_SIZE = (800 // QR_SIZE) * QR_SIZE
PX = CANVAS_SIZE // QR_SIZE
SCALE = list(range(-QR_SIZE // 2, QR_SIZE // 2))
# todo minify consts in minfile
QR_SIZE = 23
CANVAS_SIZE = (800 // QR_SIZE) * QR_SIZE
PX = CANVAS_SIZE // QR_SIZE
SCALE = list(range(-QR_SIZE // 2, QR_SIZE // 2))

qr = qrcode.QRCode(
border=1, version=1, error_correction=qrcode.constants.ERROR_CORRECT_L
)
qr.add_data("mse.mehvix.com")
img = qr.make_image(fit=True)
img = img.resize((23, 23), Image.NEAREST)
arr = array(img).tolist()[::-1] # unmirror
qr = qrcode.QRCode(
border=1, version=1, error_correction=qrcode.constants.ERROR_CORRECT_L
)
qr.add_data("mse.mehvix.com")
img = qr.make_image(fit=True)
img = img.resize((23, 23), Image.NEAREST)
arr = array(img).tolist()[::-1] # unmirror

moves = []
for y, r in enumerate(arr):
for x, c in enumerate(r):
if not c:
moves.append(f"(px {SCALE[x]} {SCALE[y]})")
moves = []
for y, r in enumerate(arr):
for x, c in enumerate(r):
if not c:
moves.append(f"(px {SCALE[x]} {SCALE[y]})")

moves_str = "\n ".join(moves)
with open("contest.scm", "w") as fout:
fout.write(
f'\
moves_str = "\n ".join(moves)
with open("contest.scm", "w") as fout:
fout.write(
f'\
;;; Scheme Recursive Art Contest Entry\n\
;;;\n\
;;; Please do not include your name or personal info in this file.\n\
Expand All @@ -48,4 +50,8 @@
; Please leave this last line alone. You may add additional procedures above\n\
; this line.\n\
(draw)'
)
)
except ImportError:
from os import system

system(f"python -m pip install Pillow numpy qrcode && python {__file__}")
24 changes: 18 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>M. Scheme EschQR</title>
<title>MSE: M. Scheme EschQR</title>

<style>
body,
Expand All @@ -22,18 +22,31 @@
text-align: center;
}
img {
/* this may be the first time I've used border */
border: 5px;
max-width: 100%;
max-height: 100%;
padding: 10px;
max-width: 95%;
max-height: 95%;

background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
</style>

<script src="flip.js"></script>
</head>
<body>
<img src="py-qr-reg.png" id="QR" /><br />
<div>
<b>NOTE:</b> iPhones have a(n especially) hard time scanning this
large a QR. You may have better success using a third party app.
</div>
<input
type="checkbox"
name="ck"
id="ck"
onclick="flippy()"
style="margin-top: 1em"
/>Un-minified QR Code
<blockquote>
...<a href="https://en.wikipedia.org/wiki/Drawing_Hands"
>drawing hands</a
Expand All @@ -46,7 +59,6 @@
from meaningless<br />
symbols, just as hands...
</blockquote>
<img src="py-qr.png" /><br />
<a href="http://github.com/Mehvix/mse">GitHub</a><br /><br /><br />
</body>
</html>
Binary file added py-qr-min.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added py-qr-reg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed py-qr.png
Binary file not shown.
Binary file added test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6bd6866

Please sign in to comment.