Anonymous user
Sierpinski triangle/Graphical: Difference between revisions
m
→{{header|Python}}: formatting - split program to make room for output-picture
m (→{{header|Sidef}}: code improvement: Array.to_png() now will automatically transform the self input to a fixed-width format) |
m (→{{header|Python}}: formatting - split program to make room for output-picture) |
||
Line 928:
{{libheader|Turtle}}
[[File:SierpinskiTriangle-turtle.png|thumb|right]]
<lang python>#!/usr/bin/env python
▲################################################################################################
# import necessary modules
# ------------------------
from numpy import *
import turtle
# Functions defining the drawing actions (used by the function DrawSierpinskiTriangle).▼
# Functions defining the drawing actions
# -------------------------------------------------------------------------------------▼
def Left(turn, point, fwd, angle, turt):
turt.left(angle)
Line 948:
turt.forward(fwd)
return [turn, point, fwd, angle, turt]
</lang>
# The drawing function
# --------------------
Line 954 ⟶ 955:
# level level of Sierpinski triangle (minimum value = 1)
# ss screensize (Draws on a screen of size ss x ss. Default value = 400.)
#
def DrawSierpinskiTriangle(level, ss=400):
# typical values
Line 1,005 ⟶ 1,006:
for i in path:
[turn, point, fwd, angle, turt]=decode[i](turn, point, fwd, angle, turt)
DrawSierpinskiTriangle(5)
</lang>
|