@ vegaseat: Thank you. Are you also vegasclimb?
@GothAlice:
"where string of the binary version is useful"?
For generating 1D fractals: http://tatetech.blogspot.com/2011/08/generating-1d-quasi-sierpinski-fractal.html
#!/usr/bin/python
""" make1DFractalBin.py
arg1 = Natural(for order of fractal)
arg2 = Natural(in 512 -- 527, 576 -- 591, 640 -- 655, 704 --719,
768 -- 783, 832 -- 847, 896 -- 911, 960 -- 975) for mask)
Generates a 1D fractal of order N,
where the fractal generated by 975 is
1. removing the middle third of each segment
2. stretching by 3
equivalent to more complicated make1DFractal.py Natural
"""
import sys
# convert a decimal integer to a binary string (base 2)
# tested with Python24 vegaseat 6/1/2005
#
def Denary2Binary(n):
"""convert denary integer n to binary string bStr"""
bStr = ''
if n < 0: raise ValueError, "must be a positive integer"
if n == 0: return '0'
while n > 0:
bStr = str(n % 2) + bStr
n = n >> 1
return bStr
#
def main():
maskDec = 975 # generator for Sierpinski square
#Read commandline argument for order of fractal
if len(sys.argv) < 2:
print "usage: $ python make1DFractalBin.py Natural(Order of fractal) [Natur\
al](default = 975, else see top of file for allowed generators)"
sys.exit(2)
else:
order = int(sys.argv[1])
print "Order of Fractal ordered: ", order, '\n'
if len(sys.argv) ==3:
maskDec = int(sys.argv[2])
print "Generator = ", maskDec
maskB = Denary2Binary(maskDec)
print "Mask = \n",maskB
iter = 0
while iter < order:
l = len(maskB)-1
""" multiply the mask by 2**(twice its binary length), and add its original value. This is equivalent to stretching it and removing middle third.
"""
maskDec = maskDec*((3-1)**(2*l)) + maskDec
maskB = Denary2Binary(maskDec)
print maskB
iter+=1
if __name__ == '__main__':
main()
For order 2 and generator 975 we get:
rtate-mn:paths rtate$ python make1DFractalBin.py 2 975
Order of Fractal ordered: 2
Generator = 975
Mask =
1111001111
1111001111000000001111001111
1111001111000000001111001111000000000000000000000000001111001111000000001111001111
Now all I have to do is "square it"!