Created
December 12, 2017 04:50
-
-
Save ConorOBrien-Foxx/134210fc55566cb1c54489105f678f10 to your computer and use it in GitHub Desktop.
Koch Snowflake in PostScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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