How to resolve the algorithm Sierpinski triangle/Graphical step by step in the Forth programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sierpinski triangle/Graphical step by step in the Forth programming language
Table of Contents
Problem Statement
Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Sierpinski triangle/Graphical step by step in the Forth programming language
Source code in the forth programming language
include lib/graphics.4th \ graphics support is needed
520 pic_width ! \ width of the image
520 pic_height ! \ height of the image
9 constant order \ Sierpinski's triangle order
black 255 whiteout \ black ink, white background
grayscale_image \ we're making a gray scale image
\ do we set a pixel or not?
: ?pixel over over and if drop drop else set_pixel then ;
: triangle 1 order lshift dup 0 do dup 0 do i j ?pixel loop loop drop ;
triangle s" triangle.ppm" save_image \ done, save the image
You may also check:How to resolve the algorithm A+B step by step in the 8080 Assembly programming language
You may also check:How to resolve the algorithm Address of a variable step by step in the M2000 Interpreter programming language
You may also check:How to resolve the algorithm Show ASCII table step by step in the 6502 Assembly programming language
You may also check:How to resolve the algorithm Gray code step by step in the bc programming language
You may also check:How to resolve the algorithm Sum of a series step by step in the Genie programming language