|
Post by krzysztof on Aug 8, 2013 6:10:34 GMT -5
I've always wondered how the AND operator works in this case: 'Sierpinski graphic #Sierpinski, 200, 200
for x = 0 to 127 for y = 0 to 127 if (x and y) = 0 then #Sierpinski set(x, y) next y next x
render #Sierpinski end Probably it is one of the best known codes for Sierpiński triangle. The similar program (operator AND) works fine under FreeBASIC, but not under Quite BASIC. Strange, isn't it?
|
|
|
Post by krzysztof on Aug 12, 2013 3:14:54 GMT -5
Example of program that can draw the Sierpinski triangle using iterated function systems ( en.wikipedia.org/wiki/Iterated_function_system). I'm not entirely happy with the used subroutines and arrays, maybe they can be improved? 'Sierpinski triangle, IFS graphic #Sierpinski, 500, 500
x = 0 y = 0
for i = 1 to 100000 j = rnd(1) if j <= 0.33 then call array1 if j > 0.33 and j <= 0.66 then call array2 if j > 0.66 then call array3
x1 = array(1) * x + array(2) * y + array(5) y = array(3) * x + array(4) * y + array(6) x = x1
#Sierpinski set(250 * x, 250 * y) next i
render #Sierpinski
end
sub array1 array(1) = 0.5 array(2) = 0 array(3) = 0 array(4) = 0.5 array(5) = 0 array(6) = 0 end sub
sub array2 array(1) = 0.5 array(2) = 0 array(3) = 0 array(4) = 0.5 array(5) = 1 array(6) = 0 end sub
sub array3 array(1) = 0.5 array(2) = 0 array(3) = 0 array(4) = 0.5 array(5) = 0.5 array(6) = 0.5 end sub
|
|
|
Post by meerkat on Aug 12, 2013 7:52:03 GMT -5
|
|
|
Post by tenochtitlanuk on Aug 12, 2013 16:37:03 GMT -5
I did an IFS example some time back- see my OLD website at atschool.eduweb.co.uk/taunton/LB/indexlb.html and find it near the bottom. I love the way that random jumps create such 'organised' figures. First met it in Byte magazine years ago & programmed on other machines.
|
|
|
Post by krzysztof on Aug 13, 2013 5:50:25 GMT -5
Thank both of You for the tips. The first concerns a completely different way of generating the fractal, but it is interesting too. Second, that the ifs system, just like in my program. I have read the code and I see that I can improve my one: 'Sierpinski triangle IFS method
graphic #Sierpinski, 500, 500
read j p1 = 0
for i = 1 to j read a, b, c, d, e, f, p0 a(i) = a b(i) = b c(i) = c d(i) = d e(i) = e f(i) = f p1 = p1 + p0 p(i) = p1 next i
for w = 1 to 500000 p2 = rnd(1)
if p2 <= p(1) then k = 1 if p2 > p(1) and p2 <= p(2) then k = 2 if p2 > p(2) and p2 <= p(3) then k = 3
'One can use instead: 'if p1 <= p(3) then k = 3 'if p1 <= p(2) then k = 2 'if p1 <= p(1) then k = 1
x1 = a(k) * x + b(k) * y + e(k) y = c(k) * x + d(k) * y + f(k) x = x1 #Sierpinski set(250 * x, 250 * y) next w
render #Sierpinski
end
data 3 data 0.5, 0, 0, 0.5, 0.0, 0.0, 0.33 data 0.5, 0, 0, 0.5, 1.0, 0.0, 0.33 data 0.5, 0, 0, 0.5, 0.5, 0.5, 0.34
|
|
|
Post by krzysztof on Aug 24, 2013 5:17:12 GMT -5
Another version of random Sierpinski triangle, found in the Microsoft Small Basic manual. graphic #Sierpinski, 600, 500 x = 1 y = 1
for i = 1 to 200000 r = int(3 * rnd(1)) ux = 150 uy = 30 if r = 1 then ux = 30 uy = 1000 end if if r = 2 then ux = 1000 uy = 1000 end if
x = (x + ux) / 2 y = (y + uy) / 2 #Sierpinski set(x, y)
next i
render #Sierpinski
end
|
|