Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Platform Racing 3 Lua code for fractals. Don't copy the **START OF CODE** things into blocks if you want to use this, and make sure to look at the getblock commands for placing things and put the setup, otherwise the code wont place blocks right. Code goes on top unless otherwise specified.
- Mandelbrot set (Color, 50 iterations)
- Fractal generated by iteration count of an equation on a complex plane.
- Recommended setup is finish block 3 blocks below, then black 4 blocks below, then 6 other colors below that.
- Generation completes, automatically finishes the player.
- **START OF CODE**
- iterations = 50 -- can change, shouldn't matter as long as it isn't below 25
- progreal = tolua(player.getmetadata("mandelprogreal", -2))
- progimag = tolua(player.getmetadata("mandelprogimag",-1.1))
- detail = 0.02 -- detail used, use if determining scale
- coolvalue = 0
- while coolvalue < 5 do
- z_r = 0 -- real z
- z_i = 0 -- imaginary z
- inset = true
- x = progreal
- y = progimag
- itr = 0 -- iterations passed
- while itr <= iterations do
- itr = itr + 1
- z_rtemp = z_r
- z_r = z_r*z_r - z_i*z_i + x
- z_i = 2*z_rtemp*z_i + y
- if(z_r*z_r + z_i*z_i > 4) then
- inset = false
- iterremoved = itr
- break
- end
- end
- if inset == true then
- xplace = x * 50
- yplace = y * 50 - 125
- block.getblock(0,4).teleportto(math.floor(xplace),math.floor(yplace),false)
- else
- if iterremoved < 3 then
- xplace = x * 50
- yplace = y * 50 - 126
- block.getblock(0,5).teleportto(math.floor(xplace),math.floor(yplace),false)
- elseif iterremoved < 5 then
- xplace = x * 50
- yplace = y * 50 - 127
- block.getblock(0,6).teleportto(math.floor(xplace),math.floor(yplace),false)
- elseif iterremoved < 7 then
- xplace = x * 50
- yplace = y * 50 - 128
- block.getblock(0,7).teleportto(math.floor(xplace),math.floor(yplace),false)
- elseif iterremoved < 10 then
- xplace = x * 50
- yplace = y * 50 - 129
- block.getblock(0,8).teleportto(math.floor(xplace),math.floor(yplace),false)
- elseif iterremoved < 15 then
- xplace = x * 50
- yplace = y * 50 - 130
- block.getblock(0,9).teleportto(math.floor(xplace),math.floor(yplace),false)
- elseif iterremoved < 25 then
- xplace = x * 50
- yplace = y * 50 - 131
- block.getblock(0,10).teleportto(math.floor(xplace),math.floor(yplace),false)
- else
- xplace = x * 50
- yplace = y * 50 - 132
- block.getblock(0,11).teleportto(math.floor(xplace),math.floor(yplace),false)
- end
- end
- progimag = progimag + detail
- if progimag > 1.1 then
- progimag = -1.1
- progreal = progreal + detail
- end
- coolvalue = coolvalue + 1
- end
- if progreal >= 0.5 then
- player.chat("set generated.")
- player.yvelocity = -0.5
- block.getblock(0,3).teleportto(0,-7,false)
- end
- player.setmetadata("mandelprogreal", progreal)
- player.setmetadata("mandelprogimag", progimag)
- **END OF CODE**
- Julia Set (Color, 125 iterations)
- Fractal generated by iteration count of an equation on a complex plane.
- Recommended setup is same as for Mandelbrot set
- Generation completes, automatically finishes the player.
- **START OF CODE**
- iterations = 125 -- can change, shouldn't matter as long as it isn't below 50
- progreal = tolua(player.getmetadata("mandelprogreal", -1.5))
- progimag = tolua(player.getmetadata("mandelprogimag",-1.5))
- detail = 0.01 -- detail used, use if determining scale
- cx = 0
- cy = 0
- coolvalue = 0
- while coolvalue < 25 do
- z_r = progreal -- real z (x)
- z_i = progimag -- imaginary z (y)
- inset = true
- x = progreal
- y = progimag
- itr = 0 -- iterations passed
- while itr <= iterations do
- itr = itr + 1
- z_rtemp = (z_r * z_r) - (z_i * z_i)
- z_i = 2 * z_r * z_i + cy
- z_r = z_rtemp + cx
- if(z_r*z_r + z_i*z_i > 4) then
- inset = false
- iterremoved = itr
- break
- end
- end
- if inset == true then
- xplace = x * 100
- yplace = y * 100 - 185
- block.getblock(0,4).teleportto(math.floor(xplace),math.floor(yplace),false)
- else
- if iterremoved < 2 then
- xplace = x * 100
- yplace = y * 100 - 186
- block.getblock(0,5).teleportto(math.floor(xplace),math.floor(yplace),false)
- elseif iterremoved < 5 then
- xplace = x * 100
- yplace = y * 100 - 187
- block.getblock(0,6).teleportto(math.floor(xplace),math.floor(yplace),false)
- elseif iterremoved < 10 then
- xplace = x * 100
- yplace = y * 100 - 188
- block.getblock(0,7).teleportto(math.floor(xplace),math.floor(yplace),false)
- elseif iterremoved < 20 then
- xplace = x * 100
- yplace = y * 100 - 189
- block.getblock(0,8).teleportto(math.floor(xplace),math.floor(yplace),false)
- elseif iterremoved < 35 then
- xplace = x * 100
- yplace = y * 100 - 190
- block.getblock(0,9).teleportto(math.floor(xplace),math.floor(yplace),false)
- elseif iterremoved < 50 then
- xplace = x * 100
- yplace = y * 100 - 191
- block.getblock(0,10).teleportto(math.floor(xplace),math.floor(yplace),false)
- else
- xplace = x * 100
- yplace = y * 100 - 192
- block.getblock(0,11).teleportto(math.floor(xplace),math.floor(yplace),false)
- end
- end
- progimag = progimag + detail
- if progimag > 1.5 then
- progimag = -1.5
- progreal = progreal + detail
- end
- coolvalue = coolvalue + 1
- end
- if progreal >= 1.5 then
- player.chat("set generated.")
- player.yvelocity = -0.5
- block.getblock(0,3).teleportto(0,-7,false)
- end
- player.setmetadata("mandelprogreal", progreal)
- player.setmetadata("mandelprogimag", progimag)
- **END OF CODE**
- Barnsley Fern (Mutation support)
- Fractal generated by repeatedly iterating a series of equations, chosen randomly each time.
- Recommended setup is block with color of choice directly below the block (and another copy of this block below that), with an area to change iteration rate and mutation range recommended. Generates normal fern if block is not bumped.
- Technically never finishes generating, but after enough iterations it is close enough.
- Top side code:
- **START OF CODE**
- local fernx = tolua(player.getmetadata("bfernx",0))
- local ferny = tolua(player.getmetadata("bferny",0))
- local fernrate = tolua(player.getmetadata("fernrate",5))
- mut1 = 0.16 + tolua(player.getmetadata("fernmut1", 0))
- mut2 = 0.85 + tolua(player.getmetadata("fernmut2", 0))
- mut3 = 1.6 + tolua(player.getmetadata("fernmut3", 0))
- mut4 = 0.04 + tolua(player.getmetadata("fernmut4", 0))
- mut5 = 0.2 + tolua(player.getmetadata("fernmut5", 0))
- mut6 = 0.26 + tolua(player.getmetadata("fernmut6", 0))
- mut0 = tolua(player.getmetadata("fernmut0", 1))
- local coolman = 0
- while coolman < fernrate do
- local r = (math.random()) * 100
- xnew = fernx
- ynew = ferny
- if r < 1 then
- fernx = 0
- ferny = mut1 * ynew
- elseif r < 86 then
- fernx = mut2 * xnew + mut4 * ynew
- ferny = (-1 * mut4) * xnew + mut2 * ynew + mut3
- elseif r < 93 then
- fernx = mut5 * xnew - mut6 * ynew
- ferny = (mut5 + 0.03) * xnew + (mut5 + 0.02) * ynew + mut3
- else
- fernx = (-0.15 * mut0) * xnew + (0.28 * mut0) * ynew
- ferny = mut6 * xnew + (mut5 + 0.04) * ynew + (mut4 + 0.4)
- end
- graphx = fernx * 100
- graphy = (ferny * -100) - 25
- block.getblock(0,1).teleportto(math.floor(graphx),math.floor(graphy),false)
- coolman = coolman + 1
- end
- player.setmetadata("bfernx",fernx)
- player.setmetadata("bferny",ferny)
- **END OF CODE**
- Bump code:
- **START OF CODE**
- local mutrange = tolua(player.getmetadata("fernmutationrange",1))
- mut1 = (math.random() * 0.1 - 0.05) * mutrange
- mut2 = (math.random() * 0.1 - 0.05) * mutrange
- mut3 = (math.random() * 0.3 - 0.15) * mutrange
- mut4 = (math.random() * 0.02 - 0.01) * mutrange
- mut5 = (math.random() * 0.1 - 0.05) * mutrange
- mut6 = (math.random() * 0.1 - 0.05) * mutrange
- mut0 = ((math.random() - 0.5)* mutrange) + 1
- player.setmetadata("fernmut1", mut1)
- player.setmetadata("fernmut2", mut2)
- player.setmetadata("fernmut3", mut3)
- player.setmetadata("fernmut4", mut4)
- player.setmetadata("fernmut5", mut5)
- player.setmetadata("fernmut6", mut6)
- player.setmetadata("fernmut0", mut0)
- mutoffset = (math.floor(((math.abs(mut1)) + (math.abs(mut2)) + math.abs(mut3) + math.abs(mut4) + math.abs(mut5) + math.abs(mut6) + ((math.abs(mut0-1)))/8) *100))/100
- player.chat("fern mutated randomly. total offset is ".. mutoffset ..".",0xff00ff)
- **END OF CODE**
- Sierpinski triangle
- Fractal generated (here) via chaos game, where a point repeatedly picks a random vertex of a shape and goes half way there.
- Recommended setup is block with color of choice directly below, and an area to change iteration rate.
- Technically never finishes generating, but after enough iterations it is close enough.
- **START OF CODE**
- local xpos = tolua(player.getmetadata("chaosx",0))
- local ypos = tolua(player.getmetadata("chaosy",0))
- local iterations = tolua(player.getmetadata("chaositerations",0))
- local coolman = tolua(player.getmetadata("coolrate",5))
- local coolrunner = 0
- if iterations == 0 then
- xpos = math.random() - 0.5
- ypos = math.random() - 0.5
- end
- while coolrunner < coolman do
- coolrunner = coolrunner + 1
- iterations = iterations + 1
- local r = math.random(-1,1)
- if r == -1 then
- xpos = (xpos + 0)/2
- ypos = (ypos + 1)/2
- elseif r == 0 then
- xpos = (xpos - 1)/2
- ypos = (ypos - 1)/2
- else
- xpos = (xpos + 1)/2
- ypos = (ypos - 1)/2
- end
- graphx = math.floor(xpos * 500)
- graphy = math.floor(ypos * -500) - 600
- if iterations > 250 then
- block.getblock(0,1).teleportto(graphx,graphy,false)
- end
- end
- player.setmetadata("chaosx",xpos)
- player.setmetadata("chaosy",ypos)
- player.setmetadata("chaositerations",iterations)
- **END OF CODE**
- Cool Pentagram Fractal
- Fractal generated (here) via chaos game, where a point repeatedly picks a random vertex of a shape and goes half way there. In this instance, it is limited to where the same vertex cannot be chosen twice in a row.
- Recommended setup is same as for Sierpinski triangle.
- Technically never finishes generating, but after enough iterations it is close enough, and in PR3, it may look better with less iterations than more
- **START OF CODE**
- local xpos = tolua(player.getmetadata("chaosx",0))
- local ypos = tolua(player.getmetadata("chaosy",0))
- local iterations = tolua(player.getmetadata("chaositerations",0))
- local coolman = tolua(player.getmetadata("coolrate",5))
- local rsaved = tolua(player.getmetadata("rsaved",-3))
- local coolrunner = 0
- if iterations == 0 then
- xpos = math.random() - 0.5
- ypos = math.random() - 0.5
- end
- while coolrunner < coolman do
- coolrunner = coolrunner + 1
- iterations = iterations + 1
- r = math.random(-2,2)
- if r == rsaved then
- while r == rsaved do
- r = math.random(-2,2)
- if r ~= rsaved then
- break
- end
- end
- end
- if r == -2 then
- xpos = (xpos + 0)/2
- ypos = (ypos + 1)/2
- elseif r == -1 then
- xpos = (xpos + 0.9510565)/2
- ypos = (ypos + 0.309017)/2
- elseif r == 0 then
- xpos = (xpos + 0.587785)/2
- ypos = (ypos - 0.809017)/2
- elseif r == 1 then
- xpos = (xpos - 0.587785)/2
- ypos = (ypos - 0.809017)/2
- else
- xpos = (xpos - 0.9510565)/2
- ypos = (ypos + 0.309017)/2
- end
- rsaved = r
- graphx = math.floor(xpos * 500)
- graphy = math.floor(ypos * -500) - 500
- if iterations > 1200 then
- block.getblock(0,1).teleportto(graphx,graphy,false)
- end
- end
- player.setmetadata("rsaved",rsaved)
- player.setmetadata("chaosx",xpos)
- player.setmetadata("chaosy",ypos)
- player.setmetadata("chaositerations",iterations)
- **END OF CODE**
- If you have any questions about the code, DM me on Discord
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement