Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ConorOBrien-Foxx
Created December 12, 2017 04:50
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 ConorOBrien-Foxx/134210fc55566cb1c54489105f678f10 to your computer and use it in GitHub Desktop.
Save ConorOBrien-Foxx/134210fc55566cb1c54489105f678f10 to your computer and use it in GitHub Desktop.
Koch Snowflake in PostScript
% yes, I really did implement a turtle for this.
%-- turtle functions --%
% CONSTANTS
/T-Angle 0 def
/T-Drawing true def
/T-coorfromangle {
dup T-Angle cos mul exch T-Angle sin mul
} def
/T-penup { /T-Drawing false def } def
/T-pendown { /T-Drawing true def } def
/T-forward {
T-coorfromangle
T-Drawing {
rlineto
}{
rmoveto
} ifelse
} def
/T-right {
T-Angle add /T-Angle exch def
} def
/T-left {
T-Angle exch sub /T-Angle exch def
} def
% <size> <iter> koch
/koch {
dup 15 div dup dup setrgbcolor
dup 0 gt {
1 sub exch 3 div exch
[60 -120 60 0] {
3 copy
3 1 roll koch T-right
pop
} forall
pop pop
}{
pop T-forward
} ifelse
} def
/inches { 72 mul } def
0.5 setlinewidth
/order 5 def
1 inches 7.25 inches moveto
3 {
6.5 inches order koch
120 T-left
} repeat
stroke
%final
showpage
quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment