Robin, for the third time, I don't bloody know fractals! Unless you want to write up a full explanation on how they work and how I could use them, saying "fractals" over and over isn't going to help anyone. Giving me an undocumented tech demo with no explanation of what it does doesn't help, either, especially if it won't even run on a non-beta version of Love.
bartbes, map generation is going to be taken care of by another, complicated step that I've not yet written. It very well may be based on a kind of region-map-editor method, I'm not sure. I'm working from the bottom up since I want to have a working demo as soon as possible. The main problem with your idea is that the map would have to be completely generated beforehand - I can't simply generate little parts of it as I need them.
Quick Lua math question
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Quick Lua math question
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Quick Lua math question
Why doesn't anyone read my posts?bartbes wrote:An approach which could be taken is instead of storing exact properties, storing a seed, which is randomly generated the first time the tile is created. Even though you're still saving tile data, it would considerably increase randomness in the first map, yet still use less memory than completely generated tiles.
I'm just saying, you might not know fractals, but it sounds like the perfect solution to your problem. So why don't you want to get familiar with them?Taehl wrote:Robin, for the third time, I don't bloody know fractals! Unless you want to write up a full explanation on how they work and how I could use them, saying "fractals" over and over isn't going to help anyone.
I was just showing an example, and it needs Framebuffers to get the drawing at a non-glacial pace. Also, technically, there hasn't ever been a stable release of LÖVE.Taehl wrote:Giving me an undocumented tech demo with no explanation of what it does doesn't help, either, especially if it won't even run on a non-beta version of Love.
Help us help you: attach a .love.
Re: Quick Lua math question
Well, I think your problem then is that z*80651+x*101+y*1337 produces a very narrow range of values.
Try this: x*(x+z)*(y+z)*(x+y+z)-x/y
Try this: x*(x+z)*(y+z)*(x+y+z)-x/y
Code: Select all
given z=1,y=100,x=100
z*80651+x*101+y*1337 => min: 82,089 max: 224,451
x*(x+z)*(y+z)*(x+y+z)-x/y => min: 11 max: 205,040,099
Last edited by Mud on Sat Nov 13, 2010 12:56 am, edited 2 times in total.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Quick Lua math question
Mud, you're brilliant! I have no idea why your solution works, but the result is excellent. Thank you very much. Looks like I won't need to make my own PRNG after all.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Re: Quick Lua math question
Now, since that is done, have a look at noise functions, e.g. Value Noise (it says "Perlin Noise", but it's not). With that you will be able to get regions of the same tile, e.g. ponds, grasslands, desert and forests.
Re: Quick Lua math question
This is apparently already solved, but for what it is worth I had a similar problem while designing a random dungeon generator in Love. The solution that worked well for me was the following:
math.randomseed(os.time() + love.timer.getTime())
Using os.time() by itself as the seed would often recreate the same seed if a new dungeon was generated too quickly after the last one. By adding in Love's own internal timer, I was able to create the necessary mixup to keep the seeds fresh.
math.randomseed(os.time() + love.timer.getTime())
Using os.time() by itself as the seed would often recreate the same seed if a new dungeon was generated too quickly after the last one. By adding in Love's own internal timer, I was able to create the necessary mixup to keep the seeds fresh.
Re: Quick Lua math question
That looks quite effective.Taehl wrote:
Mud, you're brilliant! I have no idea why your solution works, but the result is excellent. Thank you very much. Looks like I won't need to make my own PRNG after all.
Its a bit fuzzy and I could be wrong , x*(x+z)*(y+z)*(x+y+z)-x/y is a type of fractal from what i vaguely remember. Basicly a fractal is a set of rules that applies over every pixel(position) that can include alterations based on already previously generated content . For instance when you use a something like
x*(x+z)*(y+z)*(x+y+z)-x/y
this is only applying the current tile you are addressing
too see what it is doing need to look at a test example x=1,y=1,z=1
tile=1*(1+1)*(1+1)*(1+1+1)-1/1
tile=1*2*2*3-1
tile=12-1
tile=11
Simply introducing average like ( tile (x-1,y-1,z)+tile(x-1,y+1,z)+tile(x+1,y-1,z)+tile(x+1,y+1,z) ) /4 can also the out put of your results
math : x*(x+z)*(y+z)*(x+y+z)-x/y + ( ( tile (x-1,y-1,z)+tile(x-1,y+1,z)+tile(x+1,y-1,z)+tile(x+1,y+1,z) ) /4 )
values
x=1,y=1,z=1 ,
tile(x,y,z) = if x,y, or z is out of range return 0;
tile (x-1,y-1,z) = tile(1-1,1-1,1)
=0*(0+1)*(0+1)*(0+0+1)-0/0 + 0 ( last is zero is an assumed zero for convenience but may not be actually zero )
=0
tile(x-1,y+1,z)=(1-1,1+1,1)
=0*(0+1)*(2+1)*(0+2+1)-0/2 + 0 ( last is zero is an assumed zero for convenience but may not be actually zero )
=0 ( actually error because you can't divide by zero by 2 so it is forced to zero)
tile(x+1,y-1,z)=(1+1,1-1,1)
=2*(2+1)*(0+1)*(2+0+1)-2/0 + 0 ( last is zero is an assumed zero for convenience but may not be actually zero )
=2*3*1*3-0+0
=18
tile(x+1,y+1,z) =(1+1,1+1,1)
= 2*(2+1)*(2+1)*(2+2+1)-2/2 +0 ( last is zero is an assumed zero for convenience but may not be actually zero )
= 2*3*3*5-1 +0
=89
tile = x*(x+z)*(y+z)*(x+y+z)-x/y + ( ( tile (x-1,y-1,z)+tile(x-1,y+1,z)+tile(x+1,y-1,z)+tile(x+1,y+1,z) ) /4 )
tile=1*(1+1)*(1+1)*(1+1+1)-1/1 + ( 0+0+18+19 /4 )
tile=1*2*2*3-1 + (37 /4 )
tile=12-1 + 9.25 ( normally we would floor this to 9)
tile=20
Using such a equation to generative the base number for your seed or for even random ranges will changes things up a bit more
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Quick Lua math question
The formula doesn't look familiar to me, but if you're right, then I'd like to say: ha.
Help us help you: attach a .love.
Who is online
Users browsing this forum: No registered users and 10 guests