{
let path = [[0,0],[0,1]]
while(true){
let res = pathOnGrid(turtle(path))
yield res
await Promises.delay(1000)
res.children[1].style.transform="rotate(-.125turn) scale(1.414)"
await Promises.delay(1250)
path=path.map(p => [p[0]+p[1],p[1]-p[0]])
let options = []
let candidates = {}
for(let i=0; i<path.length-1; i++){
options.push(
[[path[i][0],path[i+1][1]], [path[i+1][0],path[i][1]]]
)
for(let p of options[i]){
if(!candidates[p])candidates[p]=[i]
else candidates[p].push(i)
}
}
function attempt(i,dir){
let tmp = options[i]
options[i]=[dir]
for(let j of candidates[dir]){
if (j!=i){
let safe=true
let o = options[j]
if (o.length==1) {
safe = (o[0]+""!=""+dir)
} else {
safe = attempt(j,o[o[0]+""==""+dir?1:0])
}
if(!safe){
options[i]=tmp
return false
}
}
}
return true
}
let newpath = [[0,0]]
for(let i=1; i<path.length; i++){
let stop=true
for (var tst of options[i-1]){
if (attempt(i-1,tst)){
stop=false
break
}
}
if (stop) {
for(;i<path.length;i++){
if(options[i-1].length==1) newpath.push(options[i-1][0])
newpath.push(path[i])
}
yield pathOnGrid(turtle(newpath))
await Promises.delay(5000)
newpath = [[0,0],[0,1]]
break
}
newpath.push(tst,path[i])
}
path=newpath
}
}