Fractals: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Mindraker
→‎3D Cantor set 2: meh, let's just use single bricks instead of sheets
>Mindraker
→‎3D Cantor set 2: meh, let's just use single bricks instead of sheets
(No difference)

Revision as of 10:42, 18 December 2008

Sierpinsky Triangle

Sierpinksy Triangle
x = 0
y = 1.8
z = 0
for i = 1, 4000 do
a = math.random(1,3)

if a == 1 then 
x = x / 2
z = (z - 250)/2
end

if a == 2 then 
x = (x - 250)/2
z = (z + 250)/2
end

if a == 3 then 
x = (x + 250)/2
z = (z + 250)/2
end


p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(x,1.8,z))
p.Size = Vector3.new(1,1,1)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace
--wait(.1)
end

3D Sierpinsky Triangle

3D Sierpinsky Triangle

WARNING This can freeze up your computer. (My computer could only handle 5000 after about a half hour.) If you have a slow computer, reduce the "For" loop to a lower number, like 500, then work your way up to 1000.

For a better picture of what this is, see the wikipedia article on Sierpinsky triangles

local x = 0
local y = 1.8
local z = 0

for i = 1, 5000 do
a = math.random(1,8)

if a == 1 then 
x = (x - 200)/2
y = (y - 200)/2
z = (z + 200)/2
end

if a == 2 then 
x = (x + 200)/2
y = (y - 200)/2
z = (z + 200)/2
end

if a == 3 then 
x = (x - 200)/2
y = (y - 200)/2
z = (z - 200)/2
end

if a == 4 then 
x = (x + 200)/2
y = (y - 200)/2
z = (z - 200)/2
end

if a == 5 then 
x = (x + 0)/2
y = (y + 200)/2
z = (z + 0)/2
end

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(x,y,z))
p.Size = Vector3.new(1,1,1)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace
--wait(.1)
end

Sierpinksy

Sierpinsky

This won't make a mathematical recreation of the Sierpinksy fractal, but it will merely make a pretty visual representation of it.

x=1
y=1

for i = 50, 1, -1 do

x=i
y=(50-i)
z=(50-i)

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(1,i,1))
p.Size = Vector3.new(y,x,z)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace
--wait(1)

end


for i = 50, 1, -1 do

x=i
y=(50-i)
z=(50-i)

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(1+50,i,1+50))
p.Size = Vector3.new(y,x,z)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace
--wait(1)

end

for i = 50, 1, -1 do

x=i
y=(50-i)
z=(50-i)

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(1+50,i,1))
p.Size = Vector3.new(y,x,z)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace
--wait(1)

end

for i = 50, 1, -1 do

x=i
y=(50-i)
z=(50-i)

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(1,i,1+50))
p.Size = Vector3.new(y,x,z)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace
--wait(1)

end

for i = 50, 1, -1 do

x=i
y=(50-i)
z=(50-i)

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(1+25,i+75,1+25))
p.Size = Vector3.new(y,x,z)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace
--wait(1)

end

Fern leaf

Fern leaf fractal
x = 1
y = 1.8
z = 1
for i = 1, 500 do
a = math.random(1,100)

if a == 1 then

x = 0
z = (0.16*z)

elseif a > 1 and a <= 8 then

x = ((0.20*x) - (0.26*z))
z= (0.23*x + 0.22*z + 16)

elseif a > 8 and a <= 15 then

x = ((-0.15*x) + 0.28*z)
z = (0.26*x + 0.24*z + 4.4)

elseif a > 15 and a <= 100 then

x = 0.85*x + 0.04*z
z = ((-0.04*x) + 0.85*z + 16)

end

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(x,1.8,z))
p.Size = Vector3.new(1,1,1)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace
wait(.1)
end

Mandelbrot set

Mandelbrot set

This image requires the Output window of Roblox studio. Thanks to Serveringhaus.org for this code.

iter=100
esclim=2.0
ulx=-2.0
uly=1.0
lrx=1.0
lry=-1.0
width=70
height=40

function abs(x,y)
    return math.sqrt(x*x+y*y)
end

function escapeq(cx,cy)
    local zx=0.0
    local zy=0.0
    local i=0

    while i<iter and abs(zx,zy)<esclim do
        tmp=zx*zx-zy*zy
        zy=2.0*zx*zy
        zx=tmp

        zx=zx+cx
        zy=zy+cy
        i=i+1
    end

    return i<iter
end

for y=1,height do
    line=''
    for x=1,width do
        zx=ulx+(lrx-ulx)/width*x;
        zy=uly+(lry-uly)/height*y;
        if escapeq(zx,zy) then
            line=line..'.'
        else
            line=line..'#'
        end
    end
    print(line);
end

Mandelbrot Brick Set

Brick version of the Mandelbrot Fractal

This is almost identical to the script above, but it uses bricks instead of the Output menu.

iter=100
esclim=2.0
ulx=-2.0
uly=1.0
lrx=1.0
lry=-1.0
width=70
height=40

function abs(x,y)
    return math.sqrt(x*x+y*y)
end

function escapeq(cx,cy)
    local zx=0.0
    local zy=0.0
    local i=0

    while i<iter and abs(zx,zy)<esclim do
        tmp=zx*zx-zy*zy
        zy=2.0*zx*zy
        zx=tmp

        zx=zx+cx
        zy=zy+cy
        i=i+1
    end

    return i<iter
end

for y=1,height do
    for x=1,width do
        zx=ulx+(lrx-ulx)/width*x;
        zy=uly+(lry-uly)/height*y;
        if escapeq(zx,zy) then
p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(x,1.8,y))
p.Size = Vector3.new(1,1,1)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace
--wait(.1)
        else
p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(x,1.8,y))
p.Size = Vector3.new(1,1,1)
p.Anchored = true
--p.Color = Color3.new(2)
p.Parent = game.Workspace
--wait(.1)
        end
    end
end

Cantor set

2D Cantor set
x = 0
y = 1.8
z = 0
for i = 1, 3000 do
a = math.random(1,4)

if a == 1 then 
x = (x - 250)/3
z = (z - 250)/3
end

if a == 2 then 
x = (x - 250)/3
z = (z + 250)/3
end

if a == 3 then 
x = (x + 250)/3
z = (z + 250)/3
end

if a == 4 then 
x = (x + 250)/3
z = (z - 250)/3
end

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(x,1.8,z))
p.Size = Vector3.new(1,1,1)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace
--wait(.1)
end

3D Cantor set

3D Cantor set

WARNING This can freeze up your computer. If you have a slow computer, reduce the "For" loop to a lower number, like 500, then work your way up to 1000.

local x = 0
local y = 1.8
local z = 0

for i = 1, 2000 do
a = math.random(1,8)

if a == 1 then 
x = (x - 250)/3
y = (y - 250)/3
z = (z - 250)/3
end

if a == 2 then 
x = (x - 250)/3
y = (y - 250)/3
z = (z + 250)/3
end

if a == 3 then 
x = (x - 250)/3
y = (y + 250)/3
z = (z - 250)/3
end

if a == 4 then 
x = (x - 250)/3
y = (y + 250)/3
z = (z + 250)/3
end

if a == 5 then 
x = (x + 250)/3
y = (y + 250)/3
z = (z + 250)/3
end

if a == 6 then 
x = (x + 250)/3
y = (y - 250)/3
z = (z + 250)/3
end

if a == 7 then 
x = (x + 250)/3
y = (y + 250)/3
z = (z - 250)/3
end

if a == 8 then 
x = (x + 250)/3
y = (y - 250)/3
z = (z - 250)/3
end

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(x,y,z))
p.Size = Vector3.new(1,1,1)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace
--wait(.1)
end

3D Cantor set 2

3D Cantor set

This is a proportional representation of the 3D Cantor set.

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(1,17,1))
p.Size = Vector3.new(33,33,33)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(1+66,17,1+66))
p.Size = Vector3.new(33,33,33)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(1+66,17,1))
p.Size = Vector3.new(33,33,33)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(1,17,1+66))
p.Size = Vector3.new(33,33,33)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(1+66,17+66,1+66))
p.Size = Vector3.new(33,33,33)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(1,17+66,1+66))
p.Size = Vector3.new(33,33,33)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(1+66,17+66,1))
p.Size = Vector3.new(33,33,33)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(1,17+66,1))
p.Size = Vector3.new(33,33,33)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace

Untitled

Untitled
x = 68
y = 1.8
z = 56
for i = 1, 500 do
a = math.random(1,5)

if a == 1 then 
x = x / 3
z = (z - 57)/3
end

if a == 2 then 
x = (x + 68)/3
z = (z - 13)/3
end

if a == 3 then 
x = (x + 42)/3
z = (z + 58)/3
end

if a == 4 then 
x = (x - 42)/3
z = (z + 58)/3
end

if a == 5 then 
x = (x - 68)/3
z = (z - 13)/3
end

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(x,1.8,z))
p.Size = Vector3.new(1,1,1)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace
--wait(.1)
end

Untitled2

Untitled
x = 82
y = 1.8
z = 30
for i = 1, 500 do
a = math.random(1,6)

if a == 1 then 
x = (x - 185)/5
z = (z - 300)/5
end

if a == 2 then 
x = (x + 180)/5
z = (z - 300)/5
end

if a == 3 then 
x = (x + 345)/5
z = (z + 5)/5
end

if a == 4 then 
x = (x + 175)/5
z = (z + 300)/5
end

if a == 5 then 
x = (x - 180)/5
z = (z + 300)/5
end

if a == 6 then 
x = (x - 350)/5
z = (z + 5)/5
end

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(x,1.8,z))
p.Size = Vector3.new(1,1,1)
p.Anchored = true
p.Color = Color3.new(1)
p.Parent = game.Workspace
--wait(.1)
end

Other Roblox Fractal images

3D Cantor dust Third iteration of 3D Koch quadratic fractal Square koch 3
Sierpinsky triangle fractal Variation of the Sierpinsky triangle fractal Vicsek fractal
Fractal T Fractal kite

See Also

Wikipedia article on Fractals

Beauty in Mathematics, an introductory article on fractals with helpful images