Sierpinski carpet: Difference between revisions
Content deleted Content added
→{{header|UNIX Shell}}: Add alternate implementation. |
→{{header|Commodore BASIC}}: Add implementation. |
||
Line 1,378: | Line 1,378: | ||
(println (carpet 3))</lang> |
(println (carpet 3))</lang> |
||
=={{header|Commodore BASIC}}== |
|||
<lang basic>100 PRINT CHR$(147); CHR$(18); "**** SIERPINSKI CARPET ****" |
|||
110 PRINT |
|||
120 INPUT "ORDER"; O$ |
|||
130 O = VAL(O$) |
|||
140 IF O < 1 THEN 120 |
|||
150 PRINT |
|||
160 SZ = 3 ↑ O |
|||
170 FOR Y = 0 TO SZ - 1 |
|||
180 :FOR X = 0 TO SZ - 1 |
|||
190 : CH$ = "#" |
|||
200 : X1 = X |
|||
210 : Y1 = Y |
|||
220 : IF (X1 = 0) OR (Y1 = 0) THEN 290 |
|||
230 : X3 = X1 - 3 * INT(X1 / 3) |
|||
240 : Y3 = Y1 - 3 * INT(Y1 / 3) |
|||
250 : IF (X3 = 1) AND (Y3 = 1) THEN CH$ = " ": GOTO 290 |
|||
260 : X1 = INT(X1 / 3) |
|||
270 : Y1 = INT(Y1 / 3) |
|||
280 : GOTO 220 |
|||
290 : PRINT CH$; |
|||
300 :NEXT X |
|||
310 PRINT |
|||
320 NEXT Y |
|||
</lang> |
|||
{{Out}} |
|||
All of the Commodore 8-bits have a 25-line display, so orders 3 and up scroll the top of the carpet off the screen. Orders 4+ additionally require at least 81 columns, and even a PET or C128 maxes out at 80. So we'll settle for an order-2 demonstration: |
|||
<pre>**** SIERPINSKI CARPET **** |
|||
ORDER? 2 |
|||
######### |
|||
# ## ## # |
|||
######### |
|||
### ### |
|||
# # # # |
|||
### ### |
|||
######### |
|||
# ## ## # |
|||
######### |
|||
READY.</pre> |
|||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |