Skip to content

Instantly share code, notes, and snippets.

@timClicks
Created November 11, 2026 06:05
Show Gist options
  • Select an option

  • Save timClicks/657f875ca803c924d96e67cdbcb7eeba to your computer and use it in GitHub Desktop.

Select an option

Save timClicks/657f875ca803c924d96e67cdbcb7eeba to your computer and use it in GitHub Desktop.
Technicolour Quine
#!/usr/bin/env bash
q='
#\
00
40
A\
00
40so
urce
-pow
ered\0
040pla
sma:\0
040two\0
040sine\
0040wave
s\0040and\
0040concen
tric\0040int
erference\00
40rings.\nmo
de=\0044{1:-au
to}\nif\0040((
\0040\0044#\00
40>\00401\0040))
;\0040then\n\004
0\0040printf\004
0\0042Usage:\0040%
s\0040[--plain|--c
olour|--animate]\0
134n\0042\0040\0042\
00440\0042\0040>&2;\
0040exit\00402\nfi\nca
se\0040\0042\0044mode\
0042\0040in\n\0040\004
0--plain)\0040colour=0\0
040;;\n\0040\0040--colou
r|--animate)\0040colour=
1\0040;;\n\0040\0040auto)\
0040colour=0;\0040[[\0040-
t\00401\0040&&\0040\0044{T
ERM:-dumb}\0040!=\0040dumb\0
040&&\0040-z\0040\0044{NO_CO
LOR+x}\0040]]\0040&&\0040col
our=1\0040;;\n\0040\0040*)\004
0printf\0040\0042Usage:\0040%s
\0040[--plain|--colour|--anima
te]\0134n\0042\0040\0042\00440\0
042\0040>&2;\0040exit\00402\0040
;;\nesac\n#\0040The\0040builder\00
40inserts\0040source\0040reconstru
ction\0040here.\n#\0040shellcheck\
0040disable=SC2016,SC2154\nprintf\00
40-v\0040source\0040\0047#!/usr/bin/
env\0040bash\n\0040\0040\0040\0040\0
040\0040\0040\0040\0040\0040\0040\0040
\0040\0040\0040\0040\0040\0040\0040\00
40\0040\0040\0040\0040\0040\0040\0040\
0040\0040\0040\0040\0040\0040\0040\0040\
0040q=\0047\0042\0047\0042\0047%s\0047\0
042\0047\0042\0047\n\0040\0040\0040\0040
\0040\0040\0040\0040\0040\0040\0040\0040\0
040\0040\0040\0040\0040\0040\0040\0040\004
0\0040\0040\0040\0040\0040\0040\0040\0040\00
40\0040\0040\0040\0040\0040\0040\0040t=\n\00
40\0040\0040\0040\0040\0040\0040\0040\0040\0
040\0040\0040\0040\0040while\0040read\0040-r\0
040l;\0040do\0040t+=\0044l;\0040done\0040<<<\0
040\0042\0044q\0042\n\0040\0040\0040\0040\0040
\0040\0040\0040\0040\0040\0040\0040\0040\0040\00
40\0040\0040\0040\0040\0040\0040\0040\0040\0040p
rintf\0040-v\0040t\0040%%b\0040\0042\0044t\0042\
n\0040\0040\0040\0040\0040\0040\0040\0040\0040\004
0\0040\0040\0040\0040\0040\0040\0040\0040\0040\004
0\0040\0040\0040\0040\0040\0040\0040\0040\0040\004
0\0040\0040\0040eval\0040\0042\0044t\0042\n\0047\004
0\0042\0044q\0042\nif\0040((\0040!\0040colour\0040))
;\0040then\0040printf\0040\0042%s\0042\0040\0042\004
4source\0042;\0040exit;\0040fi\nif\0040[[\0040\0044mod
e\0040==\0040--animate\0040&&\0040!\0040-t\00401\0040]
];\0040then\n\0040\0040printf\0040\0042Animation\0040nee
ds\0040a\0040terminal.\0040Use\0040--colour\0040for\0040
a\0040single\0040frame.\0134n\0042\0040>&2;\0040exit\004
02\nfi\nsine=(0\00403\00406\00409\004011\004013\004015\004
016\004016\004016\004015\004013\004011\00409\00406\00403\0
0400\0040-3\0040-6\0040-9\0040-11\0040-13\0040-15\0040-16\
0040-16\0040-16\0040-15\0040-13\0040-11\0040-9\0040-6\0040-3
)\nwheel=(196\0040202\0040208\0040214\0040220\0040226\004019
0\0040154\0040118\004082\004046\004047\004048\004049\004050\
004051\004045\004039\004033\004027\004021\004057\004093\004012
9\0040165\0040201\0040200\0040199\0040198\0040197)\nfor\0040((
\0040i=0;\0040i<30;\0040i++\0040));\0040do\n\0040\0040printf\0
040-v\0040escape\0040\0042\0134033[38;5;%sm\0042\0040\0042\0044{
wheel[i]}\0042;\0040ink[i]=\0044escape\ndone\nprintf\0040-v\0040
escape\0040\0042\0134033[38;5;231m\0042;\0040ink[30]=\0044escape\n
printf\0040-v\0040escape\0040\0042\0134033[38;5;255m\0042;\0040ink
[31]=\0044escape\nphase=\0044((\0040\0044(date\0040+%s)\0040%\0040
960\0040))\nrows=0;\0040cols=0\n#\0040Cache\0040lines\0040once:\0040
animation\0040samples\0040the\0040entire\0040diamond,\0040rather\004
0than\0040clipping\0040it.\nlines=()\nwhile\0040IFS=\0040read\0040-r
\0040line;\0040do\0040lines[\0044{#lines[@]}]=\0044line;\0040done\0040
<\0040<(printf\0040\0042%s\0042\0040\0042\0044source\0042)\nif\0040[[\
0040\0044mode\0040==\0040--animate\0040]];\0040then\n\0040\0040diamond
=()\n\0040\0040while\0040IFS=\0040read\0040-r\0040line;\0040do\n\0040\00
40\0040\0040[[\0040\0044line\0040==\0040*[![:space:]]*\0040]]\0040&&\004
0diamond[\0044{#diamond[@]}]=\0044line\n\0040\0040done\0040<<<\0040\0042
\0044q\0042\n\0040\0040fit()\0040{\n\0040\0040\0040\0040read\0040-r\0040ro
ws\0040cols\0040<\0040<(stty\0040size\0040<&3)\0040||\0040return\00401\n\0
040\0040\0040\0040((\0040rows\0040>\00401\0040&&\0040cols\0040>\00401\0040))
\0040||\0040return\00401\n\0040\0040\0040\0040height=\0044((\0040rows-1\00
40));\0040width=\0044((\0040cols-1\0040))\n\0040\0040\0040\0040((\0040heig
ht\0040>\0040\0044{#diamond[@]}\0040))\0040&&\0040height=\0044{#diamond[
@]}\n\0040\0040\0040\0040((\0040width\0040>\004076\0040))\0040&&\0040wid
th=76\n\0040\0040\0040\0040lines=()\n\0040\0040\0040\0040for\0040((\0040
y=0;\0040y<height;\0040y++\0040));\0040do\n\0040\0040\0040\0040\0040\0
040sy=\0044((\0040(\0044{#diamond[@]}-1)/2\0040))\n\0040\0040\0040\004
0\0040\0040((\0040height\0040>\00401\0040))\0040&&\0040sy=\0044((\0040
y*(\0044{#diamond[@]}-1)/(height-1)\0040))\n\0040\0040\0040\0040\004
0\0040raw=\0044{diamond[sy]};\0040padding=\0044{raw%%[!\0040]*}\n\00
40\0040\0040\0040\0040\0040start=\0044{#padding};\0040length=\0044((
\0040\0044{#raw}-start\0040))\n\0040\0040\0040\0040\0040\0040count
=\0044((\0040(length*width+75)/76\0040))\n\0040\0040\0040\0040\004
0\0040left=\0044((\0040start*width/76\0040+\0040(cols-1-width)/2\0
040))\n\0040\0040\0040\0040\0040\0040printf\0040-v\0040line\0040
\0042%*s\0042\0040\0042\0044left\0042\0040\0042\0042\n\0040\0040
\0040\0040\0040\0040for\0040((\0040x=0;\0040x<count;\0040x++\0
040));\0040do\n\0040\0040\0040\0040\0040\0040\0040\0040sx=\004
4start\n\0040\0040\0040\0040\0040\0040\0040\0040((\0040count\0
040>\00401\0040))\0040&&\0040sx=\0044((\0040start+x*(length-
1)/(count-1)\0040))\n\0040\0040\0040\0040\0040\0040\0040\004
0line+=\0044{raw:sx:1}\n\0040\0040\0040\0040\0040\0040done\n
\0040\0040\0040\0040\0040\0040lines[y]=\0044line\n\0040\00
40\0040\0040done\n\0040\0040\0040\0040printf\0040\0042\013
4033[2J\0042\n\0040\0040}\n\0040\0040exec\00403>&1\n\0040\
0040trap\0040\0042printf\0040\0134\0042\0134\0134033[0m\
0134\0134033[?25h\0134\0134033[?1049l\0134\0042\0042\004
0EXIT\n\0040\0040trap\0040\0042exit\0040130\0042\0040INT
\n\0040\0040trap\0040\0042exit\0040143\0042\0040TERM\n
\0040\0040trap\0040\0042resize=1\0042\0040WINCH\n\0040
\0040printf\0040\0042\0134033[?1049h\0134033[?25l\00
42\n\0040\0040resize=1\nfi\nwhile\0040:;\0040do\n\00
40\0040if\0040[[\0040\0044mode\0040==\0040--animate\
0040]]\0040&&\0040((\0040resize\0040));\0040then\n
\0040\0040\0040\0040resize=0\n\0040\0040\0040\0040
fit\0040||\0040exit\00401\n\0040\0040fi\n\0040\004
0frame=;\0040y=0\n\0040\0040for\0040line\0040in\
0040\0042\0044{lines[@]}\0042;\0040do\n\0040\004
0\0040\0040last=-1\n\0040\0040\0040\0040for\0040
((\0040x=0;\0040x<\0044{#line};\0040x++\0040))
;\0040do\n\0040\0040\0040\0040\0040\0040a=\004
4((\0040(x/2\0040+\0040phase)\0040&\004031\004
0));\0040b=\0044((\0040(y*2\0040-\0040phase)
\0040&\004031\0040))\n\0040\0040\0040\0040\0
040\0040c=\0044((\0040((x-40)*(x-40)/32\0040
+\0040(y-12)*(y-12)/8\0040-\0040phase)\004
0&\004031\0040))\n\0040\0040\0040\0040\004
0\0040shade=\0044((\0040(sine[a]\0040+\0
040sine[b]\0040+\0040sine[c]\0040+\00404
8\0040+\0040phase)\0040%\004030\0040))\n
\0040\0040\0040\0040\0040\0040glint=\0
044((\0040(x+2*y-phase)\0040&\0040127\
0040))\n\0040\0040\0040\0040\0040\0040
if\0040((\0040glint\0040==\00400\004
0));\0040then\0040shade=30\n\0040\00
40\0040\0040\0040\0040elif\0040((\00
40glint\0040==\00401\0040||\0040gl
int\0040==\0040127\0040));\0040the
n\0040shade=31;\0040fi\n\0040\0040
\0040\0040\0040\0040if\0040((\00
40shade\0040!=\0040last\0040));\
0040then\0040frame+=\0044{ink[
shade]};\0040last=\0044shade;\
0040fi\n\0040\0040\0040\0040\0
040\0040frame+=\0044{line:x:
1}\n\0040\0040\0040\0040done
\n\0040\0040\0040\0040printf
\0040-v\0040frame\0040\004
2%s\0134033[0m\0134n\0042\
0040\0042\0044frame\0042\n
\0040\0040\0040\0040((\0
040y+=1\0040))\n\0040\00
40done\n\0040\0040[[\004
0\0044mode\0040==\0040
--animate\0040]]\0040&
&\0040printf\0040\0042
\0134033[H\0042\n\00
40\0040printf\0040\0
042%s\0042\0040\00
42\0044frame\0042\
n\0040\0040[[\0040
\0044mode\0040!=
\0040--animate\0
040]]\0040&&\004
0break\n\0040\
0040phase=\004
4((\0040(phase
+1)\0040%\00
40960\0040))
\n\0040\0040
sleep\0040
0.06\ndone
\n######
########
########
######
######
######
####
####
####
##
##
##
##
##
'
t=
while read -r l; do t+=$l; done <<< "$q"
printf -v t %b "$t"
eval "$t"
@timClicks

Copy link
Copy Markdown
Author
$ ./quine.sh --animate
quine-demo.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment