Skip to main content
added 375 characters in body
Source Link
Oleh Prypin
  • 774
  • 4
  • 13

Python (245234)

Sierpinski Triangle Maximal golfing, tiny image:

#!/usr/bin/env python3
from cairo import*
s=SVGSurface('_',63097,54584)
g=Context(s)
g.scale(63097,54584)
def f(w,x,y):
 v=w/2
 if w>0w>.051:f(w/2v,x,y);f(w/2v,x+w/4,y-w/2v);f(w/2v,x+w/2x+v,y)
 else:g.move_to(x,y);g.line_to(x+w/2x+v,y-w);g.line_to(x+w,y);g.fill()
f(1,0,1)
s.write_to_png('s.png')

Requires python3-cairo.

To get a nice large image I needed 239 characters.

Sierpinski Triangle

Python (245)

Sierpinski Triangle

#!/usr/bin/env python3
from cairo import*
s=SVGSurface('_',630,545)
g=Context(s)
g.scale(630,545)
def f(w,x,y):
 if w>0.05:f(w/2,x,y);f(w/2,x+w/4,y-w/2);f(w/2,x+w/2,y)
 else:g.move_to(x,y);g.line_to(x+w/2,y-w);g.line_to(x+w,y);g.fill()
f(1,0,1)
s.write_to_png('s.png')

Python (234)

Maximal golfing, tiny image:

#!/usr/bin/env python3
from cairo import*
s=SVGSurface('_',97,84)
g=Context(s)
g.scale(97,84)
def f(w,x,y):
 v=w/2
 if w>.1:f(v,x,y);f(v,x+w/4,y-v);f(v,x+v,y)
 else:g.move_to(x,y);g.line_to(x+v,y-w);g.line_to(x+w,y);g.fill()
f(1,0,1)
s.write_to_png('s.png')

Requires python3-cairo.

To get a nice large image I needed 239 characters.

Sierpinski Triangle

deleted 3 characters in body; deleted 3 characters in body
Source Link
Oleh Prypin
  • 774
  • 4
  • 13

Python (251245)

Sierpinski Triangle

#!/usr/bin/env python3
importfrom cairo import*
s=cairo.SVGSurfaces=SVGSurface('_',630,545)
g=cairo.Contextg=Context(s)
g.scale(630,545)
def f(w,x,y):
 if w>0.05:f(w/2,x,y);f(w/2,x+w/4,y-w/2);f(w/2,x+w/2,y)
 else:g.move_to(x,y);g.line_to(x+w/2,y-w);g.line_to(x+w,y);g.fill()
f(1,0,1)
s.write_to_png('s.png')

Python (251)

Sierpinski Triangle

#!/usr/bin/env python3
import cairo
s=cairo.SVGSurface('_',630,545)
g=cairo.Context(s)
g.scale(630,545)
def f(w,x,y):
 if w>0.05:f(w/2,x,y);f(w/2,x+w/4,y-w/2);f(w/2,x+w/2,y)
 else:g.move_to(x,y);g.line_to(x+w/2,y-w);g.line_to(x+w,y);g.fill()
f(1,0,1)
s.write_to_png('s.png')

Python (245)

Sierpinski Triangle

#!/usr/bin/env python3
from cairo import*
s=SVGSurface('_',630,545)
g=Context(s)
g.scale(630,545)
def f(w,x,y):
 if w>0.05:f(w/2,x,y);f(w/2,x+w/4,y-w/2);f(w/2,x+w/2,y)
 else:g.move_to(x,y);g.line_to(x+w/2,y-w);g.line_to(x+w,y);g.fill()
f(1,0,1)
s.write_to_png('s.png')
Source Link
Oleh Prypin
  • 774
  • 4
  • 13

Python (251)

Sierpinski Triangle

#!/usr/bin/env python3
import cairo
s=cairo.SVGSurface('_',630,545)
g=cairo.Context(s)
g.scale(630,545)
def f(w,x,y):
 if w>0.05:f(w/2,x,y);f(w/2,x+w/4,y-w/2);f(w/2,x+w/2,y)
 else:g.move_to(x,y);g.line_to(x+w/2,y-w);g.line_to(x+w,y);g.fill()
f(1,0,1)
s.write_to_png('s.png')