See also this post from September:
http://jsoftware.com/pipermail/chat/2023-September/009287.html
outlining how I used J to create the new covers for UK Maths Trust books,
e.g.
https://ukmt.org.uk/textbooks/a-mathematical-olympiad-primer-ll

I had difficulty implementing a recursive algorithm for the turtle tiling,
and was on a tight schedule, so produced the book cover tiling 'by hand'. I
was also a judge for the Hat Competition, which had many wonderful entries;
see the NY Times article for a summary: https://archive.is/fp84g

Here's the relevant J code, though I'm not particularly proud of it.
[See  https://code.jsoftware.com/wiki/User:Ewart_Shaw/Utils  for ~ESutils]
====================================================

NB. Ewart Shaw Turtle tiling

NB. -----------------------------------------

NB. Created 26-Aug-2023

NB. Last modified 1-Sept-2023

NB. ================================================

NB.* FDIR n directory to contain figures
NB.


require '~ESutils'

mkdir FDIR=: jpath '~ESDoutput/UKMT/' NB. home


NB. ================================================
NB. Utilities

NB.


fappendslf=: {{ (x,LF) fappends y }}

fwriteslf=: {{ (x,LF) fwrites y }}


textfpt=: ('(', (":@{.), ',', ')',~ (":@{:))


NB. ================================================

NB. Turtle node coordinates

NB.


M1=: -: (S3,1) ,: _1,S3=: %:3 NB. rotate 30 degrees

M=: tidyreals _1 |. (+/ . *)/\ 12#,:M1 NB. rotate 30*i. 12 degrees


X=: 0 2 4 5 5 5 4 2 2 2 1 _1 _1 _1 + 0 0 0 0 1 2 2 2 2 1 1 1 1 0*S3

Y=: 0 0 0 0 _1 0 0 0 2 3 3 3 1 0 + 0 0 0 1 1 1 2 2 2 2 1 1 1 1*S3

T=: tidyreals X,.Y NB. Nodes of turtle


TM=: tidyreals T (+/ . *)"2 M NB. All 12 orientations of turtle


NB. ================================================
NB. Turtle paths for cover

NB.


addtile=: {{

(,: T) addtile y

:

'oldtile oldnode newnode orientation'=. y

newtile=. orientation { TM

x, newtile +"1 (oldnode { oldtile { x) - newnode { newtile

}}


setsupertile=: {{

a=. addtile 0 1 13 11

a=. a addtile 0 5 11 4

a=. a addtile 1 5 13 2

a=. a addtile 3 1 11 2

a=. a addtile 3 0 10 0

a=. a addtile 1 1 13 10

a=. a addtile 6 1 11 10

a=. a addtile 0 1 13 8

b=. 11 12 13 0 { 0 { a

b=. b, 1 2 3 4 5 6 { 8 { a

b=. b, 1 2 3 4 5 6 7 8 { 7 { a

b=. b, 5 6 { 6 { a

b=. b, 1 2 3 4 5 6 { 5 { a

b=. b, 1 2 3 4 5 6 7 8 { 4 { a

b=. b, 5 6 { 3 { a

b=. b, 1 2 3 4 5 6 7 8 { 2 { a

b=. b, 9 10 { 0 { a

SUPERTILE=: tidyreals a

SUPERBDRY=: tidyreals b

STM=: tidyreals SUPERTILE (+/ . *)"_ 2/ M NB. All 12 orientations

SBM=: tidyreals SUPERBDRY (+/ . *)"_ 2/ M NB. All 12 orientations

'SUPERTILE, SUPERBDRY, STM, STB created'

}}


addst=: {{

(,: 4 { STM) addst y

:

'oldst oldtile oldnode newtile newnode orientation'=. y

newst=. orientation { STM

NB. NEWBDRY=: orientation { SBM NB. currently not needed

x, newst +"1 (oldnode { oldtile { oldst {x) - newnode { newtile { newst

}}


settiling=: {{

a=. addst 0 0 11 2 5 2

a=. a addst 0 7 1 0 11 2

a=. a addst 0 7 6 4 6 8

NB. ...

NB. 72 similar addst lines omitted

NB. ...

a=. a addst 63 0 9 2 3 8

TILING=: a +/ . * ((2&o. , 1&o.@-),: 1&o. , 2&o.) o. 5%12

TILING=: TILING ([ + $@[ $ ]) 35 30 NB. NEW

'TILING created'

}}


NB. code to create TikZ etc. omitted.

🙂



-- 
Ewart Shaw [J.E.H.Shaw]     www.instagram.com/ewartshaw/
www.facebook.com/ewart.shaw     www.ewartshaw.com [WIP]
3  ((4&({*.(=+/))++/=3:)@([:,/0&,^:(i.3)@|:"2^:2))&.>@]^:(i.@[)  <#:3 6 2
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to