Skip to content

Instantly share code, notes, and snippets.

@Gro-Tsen
Created March 9, 2022 21:31
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 Gro-Tsen/bb30c6456faf2040eb1ac77bc1554147 to your computer and use it in GitHub Desktop.
Save Gro-Tsen/bb30c6456faf2040eb1ac77bc1554147 to your computer and use it in GitHub Desktop.
# Base 3-w where w is a 6-th root of unity
w = N(exp(I*pi/3))
def dragonpoints(depth):
if depth <= 0:
return [(1+w)/3]
else:
parta = [z+1 for z in dragonpoints(depth-1)]
partb = [z/w+w for z in dragonpoints(depth-1)]
partc = [z+w for z in dragonpoints(depth-1)]
return [z/(3-w) for z in parta+partb+partc]
def dragoncurve(depth, scale=1, translate=0):
l0 = dragonpoints(depth)
l = [z*scale+translate for z in l0] + [z*w*scale+translate for z in l0] + [z*w^2*scale+translate for z in l0] + [z*w^3*scale+translate for z in l0] + [z*w^4*scale+translate for z in l0] + [z*w^5*scale+translate for z in l0]
return [(z.real(), z.imag()) for z in l]
(sum([polygon(dragoncurve(8,translate=t),color=c) for (t,c) in [(0,Color(0.8,0.8,0.8)), (1,Color(0.8,0.2,0.2)), (w,Color(0.8,0.8,0.2)), (w^2,Color(0.2,0.8,0.2)), (w^3,Color(0.2,0.8,0.8)), (w^4,Color(0.2,0.2,0.8)), (w^5,Color(0.8,0.2,0.8))]]) + sum([polygon(dragoncurve(7,scale=1/(3-w),translate=t),color=c) for (t,c) in [(0,Color(0.9,0.9,0.9)), (1,Color(0.9,0.4,0.4)), (w,Color(0.9,0.9,0.4)), (w^2,Color(0.4,0.9,0.4)), (w^3,Color(0.4,0.9,0.9)), (w^4,Color(0.4,0.4,0.9)), (w^5,Color(0.9,0.4,0.9))]])).show(dpi=192,aspect_ratio=1)
# Base 2-i where i is a 4-th root of unity
i = N(I)
def dragonpoints(depth):
if depth <= 0:
return [(1+i)/2]
else:
parta = [z+1 for z in dragonpoints(depth-1)]
partb = [z/i+i for z in dragonpoints(depth-1)]
partc = [z+i for z in dragonpoints(depth-1)]
return [z/(2-i) for z in parta+partb+partc]
def dragoncurve(depth, scale=1, translate=0):
l0 = dragonpoints(depth)
l = [z*scale+translate for z in l0] + [z*i*scale+translate for z in l0] + [z*i^2*scale+translate for z in l0] + [z*i^3*scale+translate for z in l0]
return [(z.real(), z.imag()) for z in l]
(sum([polygon(dragoncurve(8,translate=t),color=c) for (t,c) in [(0,Color(0.8,0.8,0.8)), (1,Color(0.8,0.2,0.2)), (i,Color(0.8,0.8,0.2)), (i^2,Color(0.2,0.8,0.2)), (i^3,Color(0.2,0.2,0.8))]]) + sum([polygon(dragoncurve(7,scale=1/(2-i),translate=t),color=c) for (t,c) in [(0,Color(0.9,0.9,0.9)), (1,Color(0.9,0.4,0.4)), (i,Color(0.9,0.9,0.4)), (i^2,Color(0.4,0.9,0.4)), (i^3,Color(0.4,0.4,0.9))]])).show(dpi=192,aspect_ratio=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment