Skip to content

Instantly share code, notes, and snippets.

@tuzz
Created March 6, 2019 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuzz/c7e8c4b04156d09861dca68d1b0f09bc to your computer and use it in GitHub Desktop.
Save tuzz/c7e8c4b04156d09861dca68d1b0f09bc to your computer and use it in GitHub Desktop.
A very quick experiment to draw superpermutations as colored spirals moving out from the center.
<center>
<canvas id="canvas" width="1000" height="1000"></canvas>
</center>
<script>
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
var done = false;
function circle_around(callback) {
var r = 1;
var x = -1;
var y = -1;
callback(0, 0);
while(true) {
while(x < r) {
x += 1;
callback(x, y);
}
while(y < r) {
y += 1;
callback(x, y);
}
while(x > -r) {
x -= 1;
callback(x, y);
}
while(y > -r) {
y -= 1;
callback(x, y);
}
r += 1
y -= 1
callback(x, y);
if (done) {
return
}
}
}
var s = "12345671234561723456127345612374562137456231754623175642317562431752643715246371524367152437615243716524371562437152643751264375216437526143752641375264317524631752436175243167524136752416375241673524167532416752341675243176524317562341756231475623174562371456273145627134562714356271453627415362745136274531627453612745362174536271456327415632745163274561324756132457613245671324561732456137245631724563712456372145637241563724516372456132745631274563217456327145623741562374516237456123475612346571234651723465127346512374651234765123467512346157234615273461523746152347615234671523461752346125734162573412657341256734152674315276413527641532764152376415273641527634152764315274631527436152743165274136527416352741653274165237416527341652743156274315267413526741532674152367415263741526734156273415672341567324156734215763421573642157346215734261573421657432156743215764321574632157436215743261547326514732654173265471326547312654732165473261543726514372654137265431726543712654372165437261543276154326715432617543216754321765432175643217546321754362175432615743216574231567423157642315746231574263154726315427631542673154263715426317542631574236157423165742136574216354721635427163542176354216735421637542163574216537421563742153674215376421537462153742615374216573421567341257634125736412573461253741625374126537412563741253674125376412537461253476125346712534617253461275341627534126753412765341726354172634517263415726341752634172563417265341762534176523417653241763524176325417632451763241576324175632417653421756342175364217534621753426175342167534217653412756341275364127534612357416235741263574123657412356741235764123574612354762135476231547623514672315467231456723146572314675231467253146723514627351462375146235714625371462573146257134625714362571463257146235174625317465231746532174653127465317246537124653721465372416573241657234165724315672431576243157264351726435712643572164357261435726413572643157246315724361572431657241365724163572416537246153274615324761532467153246175324615732461537246513274651324765132467513246571324651732465137246531742651374265173426517432651742365174263514726351427635142673514263751426357142653714265731426571342657143265714236571426351742653174625137462517346251743625174632517462351476235417623547162345761234576213457623145762341576234517623457163247516324715632471653247163524716325471632457163425716345271634572163457126347512634715263471256347126534712635471263457162347516234715623471652347162534716235476123546712354617235461327541632754136275413267541327654132756413275461325741632574136257413265741325674132576413257461325476132546713254617325461372546317254637125463721546372514637254167325416723541672534167254316725413672541637254613527461352476135246713524617352461375246135724613542761354267135426173542613754261357426135472613546271534267153427615342716534271563427153642715346271543627154632715462371546273154627135462173546213754621357462135647213564271356421735642137564213576421356742135624713562417356241375624135762413567241356274135621473562143756214357621435672143657214367521436725143672154367214536724153672451367245316724536172453671245367214356127435612473561243756124357612435671243561724356142735614237561423576142356714235617423561472356143275164327156432716543271645327164352716432571643275146327514362751432675143276514327561432576143256714325617432561473256417325647132564731256473215647325164732561437256413725643172564371256437215643725164372561435276143526714352617435216745321674523167452136745216374521673451267435126745312674513267451236745126374512673451627345167234516732451673425167432516742351674253167425136742516374251673452176345217364521734652173456217345261734521674352176435217463521476325147632154763214576321475632147653124763512467315246731254673124567312465731246753124673512463751246357124635172463512746351247631524763125476312457631247563124765314275631425763142567314256371425631742563147256314275361425736142537614253671425361742536147253614275316427351642731564273165427361542736514273654127356412735461273541627354126735412763541273654217365427136542731645273164257316427531462753142675314276531472653147625314765231476532147635214673251467321546732145673214657321467532146735214637521463572146352714653271465237146527314652713465271436527146352174365217435621743526147352641735264713526473152647351264735216473526145372641537264513726453176245371624537612453762145376241537624513762453176425137642517364251763425176432517642351764253176452317645321764531276451327645123764512736451276345127643512764531726453712645372164537261453276145326714532617453261475326417532647153264751326475312647532164753261457326415732645173264571362457316247536124753621475362417536247153624751362475316247351624375162435716243517624351672435162743516247315624731652473615247365124376512436751243657124365172436512743651247365214736524173652471365247316254736125437621543762514376254137625431762543716254376125436712543617254361275431627543126754312765431275643127546312754361257431625743126574312567431257643125746312574361254736215473625147362541736254713625473162457361245736214573624157362451736245713642571364527136457213645712364751236471523647125364712356471236547213654723164572316475231647253164723516472315647231654723615472365147236541723645172364157236417523641725364172356417236547123645713264573126457321645732614523761452367145236174523614752361457236145273614526371452631745263147526314572631452763145267314526137452613475216347521364752134672513476251347265134725613427516342751364275134627513426751342765134275613425761342567134256173425613742561347251634725136472513467215347621534726153472165347215634721536472153467213546721345672134657213467521347652137465213764521376542317654237164523716425371642357164237516423715642371654237615423765142376541237564123754612375416237541263754123675421367542316754236175423671542367514236754123765421376524137652143765213475621347526134572613452761345267134526";
var i = 0;
circle_around(function (x, y) {
if (i >= s.length) {
done = true;
return;
}
var color;
switch (s[i]) {
case "1": color = "#FF0000"; break;
case "2": color = "#00FF00"; break;
case "3": color = "#0000FF"; break;
case "4": color = "#FFFF00"; break;
case "5": color = "#000000"; break;
case "6": color = "#00FFFF"; break;
case "7": color = "#FF00FF"; break;
default: alert("not enough colors");
}
context.fillStyle = color;
context.fillRect((x * 10) + 500, (y * 10) + 500, 10, 10);
i += 1;
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment