Text Only
|
Text with Attachments
QB64.org Forum
Active Forums => Programs => Topic started by: AndyA on April 16, 2021, 12:06:09 am
Title:
Sierpinski Carpet (Rosetta Code task)
Post by:
AndyA
on
April 16, 2021, 12:06:09 am
https://rosettacode.org/wiki/Sierpinski_carpet#QB64 (https://rosettacode.org/wiki/Sierpinski_carpet#QB64)
'==================================================
Task
Produce a graphical or ASCII-art representation of a Sierpinski carpet of order N.
'==================================================
I produced the graphical option.
Code: QB64:
[Select]
_Title
"Sierpinski Carpet"
Screen
_NewImage
(
500
,
545
,
8
)
Cls
,
15
:
Color
1
,
15
'labels
_PrintString
(
96
,
8
)
,
"Order 0"
_PrintString
(
345
,
8
)
,
"Order 1"
_PrintString
(
96
,
280
)
,
"Order 3"
_PrintString
(
345
,
280
)
,
"Order 4"
'carpets
Call
carpet
(
5
,
20
,
243
,
0
)
Call
carpet
(
253
,
20
,
243
,
1
)
Call
carpet
(
5
,
293
,
243
,
2
)
Call
carpet
(
253
,
293
,
243
,
3
)
Sleep
System
Sub
carpet
(
x
As
Integer
,
y
As
Integer
,
size
As
Integer
,
order
As
Integer
)
Dim
As
Integer
ix
,
iy
,
isize
,
iorder
,
side
,
newX
,
newY
ix
=
x: iy
=
y: isize
=
size: iorder
=
order
Line
(
ix
,
iy
)
-
(
ix
+
isize
-
1
,
iy
+
isize
-
1
)
,
1
,
BF
side
=
Int
(
isize
/
3
)
newX
=
ix
+
side
newY
=
iy
+
side
Line
(
newX
,
newY
)
-
(
newX
+
side
-
1
,
newY
+
side
-
1
)
,
15
,
BF
iorder
=
iorder
-
1
If
iorder
>=
0
Then
Call
carpet
(
newX
-
side
,
newY
-
side
+
1
,
side
,
iorder
)
Call
carpet
(
newX
,
newY
-
side
+
1
,
side
,
iorder
)
Call
carpet
(
newX
+
side
,
newY
-
side
+
1
,
side
,
iorder
)
Call
carpet
(
newX
+
side
,
newY
,
side
,
iorder
)
Call
carpet
(
newX
+
side
,
newY
+
side
,
side
,
iorder
)
Call
carpet
(
newX
,
newY
+
side
,
side
,
iorder
)
Call
carpet
(
newX
-
side
,
newY
+
side
,
side
,
iorder
)
Call
carpet
(
newX
-
side
,
newY
,
side
,
iorder
)
End
If
End
Sub
Text Only
|
Text with Attachments