Sierpinski carpet: Difference between revisions

Added Fōrmulæ entry
imported>Lacika7
No edit summary
(Added Fōrmulæ entry)
(2 intermediate revisions by 2 users not shown)
Line 323:
###########################</pre>
=={{header|AppleScript}}==
===Functional===
 
{{Trans|JavaScript}}
(ES5 Functional version)
Line 696:
█ ██ ██ █
█████████</pre>
----
===Simple===
<syntaxhighlight lang="applescript">on SierpinskiCarpet(n, char)
if (n < 0) then return {}
script o
property lst1 : {char}
property lst2 : missing value
end script
set gap to space
repeat with k from 0 to (n - 1)
copy o's lst1 to o's lst2
repeat with i from 1 to (3 ^ k)
set str to o's lst1's item i
set o's lst1's item i to str & str & str
set o's lst2's item i to str & gap & str
end repeat
set o's lst1 to o's lst1 & o's lst2 & o's lst1
set gap to gap & gap & gap
end repeat
return join(o's lst1, linefeed)
end SierpinskiCarpet
 
on join(lst, delim)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to delim
set txt to lst as text
set AppleScript's text item delimiters to astid
return txt
end join
 
return SierpinskiCarpet(3, "#")</syntaxhighlight>
 
{{output}}
<pre>###########################
# ## ## ## ## ## ## ## ## #
###########################
### ###### ###### ###
# # # ## # # ## # # #
### ###### ###### ###
###########################
# ## ## ## ## ## ## ## ## #
###########################
######### #########
# ## ## # # ## ## #
######### #########
### ### ### ###
# # # # # # # #
### ### ### ###
######### #########
# ## ## # # ## ## #
######### #########
###########################
# ## ## ## ## ## ## ## ## #
###########################
### ###### ###### ###
# # # ## # # ## # # #
### ###### ###### ###
###########################
# ## ## ## ## ## ## ## ## #
###########################</pre>
 
=={{header|Arturo}}==
Line 3,260 ⟶ 3,322:
end subroutine Carpet
end program Sierpinski_carpet</syntaxhighlight>
 
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/L-system}}
 
'''Solution'''
 
It can be done using an [[wp:L-system|L-system]]. There are generic functions written in Fōrmulæ to compute an L-system in the page [[L-system#Fōrmulæ | L-system]].
 
The program that creates a Sierpiński carpet is:
 
[[File:Fōrmulæ - L-system - Sierpiński carpet 01.png]]
 
[[File:Fōrmulæ - L-system - Sierpiński carpet 02.png]]
 
=={{header|Gnuplot}}==
Line 6,993 ⟶ 7,069:
=={{header|Wren}}==
{{trans|Python}}
<syntaxhighlight lang="ecmascriptwren">var inCarpet = Fn.new { |x, y|
while (true) {
if (x == 0 || y == 0) return true
2,120

edits