Iteration. Has anyone ever made fractals within a game?
Moderators: Bob the Hamster, marionline, SDHawk
- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
Iteration. Has anyone ever made fractals within a game?
Just wondering if anyone has ever accomplished any sort of fractal programming within their game/program? I've been contemplating if it's worth trying myself and wanted to see if/how someone else has approached this.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
- BMR
- Metal King Slime
- Posts: 3310
- Joined: Mon Feb 27, 2012 2:46 pm
- Location: The Philippines
- Contact:
Kinda... Not really sure if it exactly counts as fractal programming, but I've managed to get a decent diamond square thing going for random terrain generation. Not sure if that's what you're looking for though. What/How/Where are you planning to use fractals?
Being from the third world, I reserve the right to speak in the third person.
Using Editor version wip 20170527 gfx_sdl+fb music_sdl
Using Editor version wip 20170527 gfx_sdl+fb music_sdl
- Bob the Hamster
- Liquid Metal King Slime
- Posts: 7460
- Joined: Tue Oct 16, 2007 2:34 pm
- Location: Hamster Republic (Ontario Enclave)
- Contact:
Re: Iteration. Has anyone ever made fractals within a game?
Depends on what you mean by fractal.sheamkennedy wrote:Just wondering if anyone has ever accomplished any sort of fractal programming within their game/program? I've been contemplating if it's worth trying myself and wanted to see if/how someone else has approached this.
If you mean like rendering a mandelbrot set, i know I tried once, but quickly got bogged down and gave it up.
If you mean something like perlin noise terrain, I am pretty sure someone did it successfully (BMR, I think?)
EDIT: Oops! haha! BMR posted before I submitted. Diamond-square and perlin-noise are pretty similar.
Last edited by Bob the Hamster on Fri Nov 15, 2013 5:35 pm, edited 1 time in total.
- BMR
- Metal King Slime
- Posts: 3310
- Joined: Mon Feb 27, 2012 2:46 pm
- Location: The Philippines
- Contact:
Re: Iteration. Has anyone ever made fractals within a game?
But despite that, BMR has yet to figure out a good way to script Perlin noise, hehe. One day he shall, perhaps on yet another late-night scripting spree =pBob the Hamster wrote:Diamond-square and perlin-noise are pretty similar.
Being from the third world, I reserve the right to speak in the third person.
Using Editor version wip 20170527 gfx_sdl+fb music_sdl
Using Editor version wip 20170527 gfx_sdl+fb music_sdl
- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
Re: Iteration. Has anyone ever made fractals within a game?
BMR wrote:But despite that, BMR has yet to figure out a good way to script Perlin noise, hehe. One day he shall, perhaps on yet another late-night scripting spree =p[/quoteBob the Hamster wrote:Diamond-square and perlin-noise are pretty similar.
Yeah I consider all of what has been mentioned as fractal related stuff. I'm not asking about it for any particular reason, I just wanted to know if something like that has been done and if there is any examples of it out of curiosity. I was originally intrigued by Julia sets and considered that someone in the community may have taken something like that on as a challenge. I was thinking of maybe trying to make a tree thing in which the branches multiply shorten segment by segment until a random shaped tree is formed.
If you have a program that shows off the Diamond-square terrain mapping, I'd love to see it. Where can I find it?
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
Perhaps I could make a simple tree in which a "branch" slice spawns 2 more smaller slices at its tip and at random angles, then those branches further spawn 2 more branches each, and so forth. Seems like it may be doable with just parent and child slices. Not sure how i'd do angled branches... might have to draw each angle of branch from scratch but I'm not sure.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
- BMR
- Metal King Slime
- Posts: 3310
- Joined: Mon Feb 27, 2012 2:46 pm
- Location: The Philippines
- Contact:
I don't have a game up, sadly. I do have a forum thread where I posted results and a few details about what I was working on. If you're interested, I could PM you the scripts. That is, if you're willing to sift through a bunch of messy code, heh.
Being from the third world, I reserve the right to speak in the third person.
Using Editor version wip 20170527 gfx_sdl+fb music_sdl
Using Editor version wip 20170527 gfx_sdl+fb music_sdl
- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
Yeah I'd love to take a peek. I'm sure it'll give me some insight and maybe inspire some ideas.BMR wrote:I don't have a game up, sadly. I do have a forum thread where I posted results and a few details about what I was working on. If you're interested, I could PM you the scripts. That is, if you're willing to sift through a bunch of messy code, heh.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
- BMR
- Metal King Slime
- Posts: 3310
- Joined: Mon Feb 27, 2012 2:46 pm
- Location: The Philippines
- Contact:
Here you go:
I'll post it here rather than PMing it so anyone can see the code. It's not the entire terrain generation thing I use, as this code doesn't include river generation, coastlines, etc... I haven't tested this in a while, so I'm not sure if it'll work well by itself (i.e. without the other parts) or even at all. If you have any questions (or comments, or suggestions, or disparaging remarks) feel free to get in touch.
Code: Select all
#====================================================================================================
#This script generates a height map for everything using a very -very- crude diamond-square algorithm
#====================================================================================================
script, generate height, begin
#Variable Declarations
#---------------------
variable(
minX #The smallest possible X value
maxX #The largest possible X value
minY #The smallest possible Y value
maxY #The largest possible Y value
bs #Block Size, the size of the current block being worked
curX #The current X value
curY #The current Y value
x1
x2
y1
y2
va #Variance, this is how much the surrounding terrain affects the code. Larger values make for rougher terrain.
rgh #Roughness, this is how much the random value ranges. Higher numbers make for rougher terrain. (2-16)
tp #Temporary Passes, used for debugging
ctr #A counter
)
#---------------------
#Prime the variables
#-------------------
minX := 0
maxX := map width
minY := 0
maxY := map height
bs := map width #This assumes that the map is square
va := 2 #Only 2% of the generated value is random, the other 98% is based on surrounding terrain
rgh := 10 #The random numbers are relatively low.
#-------------------
tp := 1
while(bs >= 1) do( #This block will repeat until bs reaches its minimum
for(curX, minX, maxX + 1, bs) do(
for(curY, minY, maxY + 1, bs) do(
x1 := curX
y1 := curY
x2 := curX + bs
y2 := curY + bs
if(x2 >> maxX) then(x2 := maxX)
if(y2 >> maxY) then(y2 := maxY)
diamond pass(x1, y1, x2, y2, va, rgh)
square pass(x1, y1, x2, y2, va, rgh)
)
)
bs := bs / 2 #This halves the size of the block the code works with
tp += 1
)
end
#====================================================================================================
#====================================================================================================
#========================================================================================================
#These two functions are the main block used.
#========================================================================================================
#-----------------------------------------------------------
#This script runs the diamond pass of the generation process
#-----------------------------------------------------------
script, diamond pass, x1, y1, x2, y2, va, rgh, begin
#Variable Declarations
#---------------------
variable(
x3 #This is the X-cooridinate of the newly generated value
y3 #This is the Y-cooridinate of the newly generated value
p1v #The height value of point 1, this is known
p2v #The height value of point 2, this is known
p3v #The height value of point 3, this is known
p4v #The height value of point 4, this is known
p5v #The height value of point 5, this will be generated
ap #Average Points, the average of the four known points
vp #Variance Percent, a fraction of the above average as determined by variance
rp #Roandom Percent, a random value from 0 to 15, how much is applied is determined by variance
rl #Roughness Low, the lowest roughness value
rh #Roughness High, the highest roughness value
rf #Roughness Final, the final roughness value
pv #The point value of a coordinate
tv #The temporary working value for the new point
nv #The new value of a coordinate
crX #Current X
crY #Current Y
)
#---------------------
#Prime the variables
#-------------------
p1v := read map block(x1, y1, 0)
p2v := read map block(x2, y1, 0)
p3v := read map block(x1, y2, 0)
p4v := read map block(x2, y2, 0)
x3 := (x2 + x1) / 2
y3 := (y2 + y1) / 2
ap := (p1v + p2v + p3v + p4v) / 4
vp := (ap * (100 -- va)) / 100
rp := (random(0, 15) * va) / 100
rl := rgh * -1
rh := rgh
rf := random(rl, rh)
#-------------------
tv := (vp + rp) + rf #Change the temporary value to a new randomly generated one
if(tv <<0>> 127) then(tv := 127) #Make sure the value is not higher than 127
p5v := tv
nv := (p1v + p2v + p3v + p4v + p5v) / 5
write map block(x3, y3, p5v, 0) #Write the tiles
end
#-----------------------------------------------------------
#-----------------------------------------------------------
#----------------------------------------------------------
#This script runs the square pass of the generation process
#----------------------------------------------------------
script, square pass, x1, y1, x2, y2, va, rgh, begin
#Variable Declarations
#---------------------
variable(
x3 #This is the X-cooridinate of the newly generated value
y3 #This is the Y-cooridinate of the newly generated value
p1v #The height value of point 1, this is known
p2v #The height value of point 2, this is known
p3v #The height value of point 3, this is known
p4v #The height value of point 4, this is known
p5v #The height value of point 5, this is known after the diamond pass
ap1 #The average of three points, for use with the top point
ap2 #The average of three points, for use with the right point
ap3 #The average of three points, for use with the bottom point
ap4 #The average of three points, for use with the left point
vp1 #A fraction of the above average as determined by va
vp2 #A fraction of the above average as determined by va
vp3 #A fraction of the above average as determined by va
vp4 #A fraction of the above average as determined by va
rp1 #A random value from 0 to 15, how much is applied is determined by va for the top point
rp2 #A random value from 0 to 15, how much is applied is determined by va for the right point
rp3 #A random value from 0 to 15, how much is applied is determined by va for the bottom point
rp4 #A random value from 0 to 15, how much is applied is determined by va for the left point
rl #The lowest rgh value
rh #The highest rgh value
rf1 #The final rgh value for the top point
rf2 #The final rgh value for the right point
rf3 #The final rgh value for the bototm point
rf4 #The final rgh value for the left point
tv1 #The temporary working value for the top point
tv2 #The temporary working value for the right point
tv3 #The temporary working value for the bottom point
tv4 #The temporary working value for the left point
)
#---------------------
#Prime the variables
#-------------------
x3 := (x2 + x1) / 2
y3 := (y2 + y1) / 2
p1v := read map block(x1, y1, 0)
p2v := read map block(x2, y1, 0)
p3v := read map block(x1, y2, 0)
p4v := read map block(x2, y2, 0)
p5v := read map block(x3, y3, 0)
ap1 := (p1v + p2v + p5v) / 3
ap2 := (p2v + p4v + p5v) / 3
ap3 := (p3v + p4v + p5v) / 3
ap4 := (p1v + p3v + p5v) / 3
vp1 := (ap1 * (100 -- va)) / 100
vp2 := (ap2 * (100 -- va)) / 100
vp3 := (ap3 * (100 -- va)) / 100
vp4 := (ap4 * (100 -- va)) / 100
rp1 := (random(0, 15) * va) / 100
rp2 := (random(0, 15) * va) / 100
rp3 := (random(0, 15) * va) / 100
rp4 := (random(0, 15) * va) / 100
rl := rgh * -1
rh := rgh
rf1 := random(rl, rh)
rf2 := random(rl, rh)
rf3 := random(rl, rh)
rf4 := random(rl, rh)
#-------------------
tv1 := (vp1 + rp1) + rf1 #\
tv2 := (vp2 + rp2) + rf2 # \Change the new random value for
tv3 := (vp3 + rp3) + rf3 # /the temporary points
tv4 := (vp4 + rp4) + rf4 #/
if(tv1 << 0) then(tv1 := 0) #\
if(tv2 << 0) then(tv2 := 0) # \Make sure the value
if(tv3 << 0) then(tv3 := 0) # /is not lower than 0
if(tv4 <<0>> 127) then(tv1 := 127) #\
if(tv2 >> 127) then(tv2 := 127) # \Make sure the value is
if(tv3 >> 127) then(tv3 := 127) # /not higher than 127
if(tv4 >> 127) then(tv4 := 127) #/
tv1 := (tv1 + read map block(x3, y1, 0)) / 2 #This is the top point
tv2 := (tv2 + read map block(x2, y3, 0)) / 2 #This is the right point
tv3 := (tv3 + read map block(x3, y2, 0)) / 2 #This is the bottom point
tv4 := (tv4 + read map block(x1, y3, 0)) / 2 #This is the left point
write map block(x3, y1, tv1, 0) #Write this to the top point
write map block(x2, y3, tv2, 0) #Write this to the right point
write map block(x3, y2, tv3, 0) #Write this to the bottom point
write map block(x1, y3, tv4, 0) #Write this to the left point
end
#----------------------------------------------------------
#----------------------------------------------------------
#========================================================================================================
#End of block
#========================================================================================================
Being from the third world, I reserve the right to speak in the third person.
Using Editor version wip 20170527 gfx_sdl+fb music_sdl
Using Editor version wip 20170527 gfx_sdl+fb music_sdl
- Meowskivich
- Blubber Bloat
- Posts: 2199
- Joined: Tue Mar 06, 2012 12:38 am
- Location: Earth
- Contact:
- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
Thanks
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
- BMR
- Metal King Slime
- Posts: 3310
- Joined: Mon Feb 27, 2012 2:46 pm
- Location: The Philippines
- Contact:
Yes! Read/Write pixels would indeed be amazing! All the amazing stuff you'd be able to do 
And I shall fix the script when I get back to my main computer as I do not have any of my OHRRPGCE stuff on this machine.
And I shall fix the script when I get back to my main computer as I do not have any of my OHRRPGCE stuff on this machine.
Being from the third world, I reserve the right to speak in the third person.
Using Editor version wip 20170527 gfx_sdl+fb music_sdl
Using Editor version wip 20170527 gfx_sdl+fb music_sdl