Page 5 of 5

Re: Quick Lua math question

Posted: Fri Nov 12, 2010 11:21 pm
by Taehl
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.

Re: Quick Lua math question

Posted: Sat Nov 13, 2010 12:27 am
by Robin
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.
Why doesn't anyone read my posts? :cry:
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'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: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.
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. ;)

Re: Quick Lua math question

Posted: Sat Nov 13, 2010 12:35 am
by Mud
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

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

Re: Quick Lua math question

Posted: Sat Nov 13, 2010 12:43 am
by Taehl
Image
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.

Re: Quick Lua math question

Posted: Sat Nov 13, 2010 10:51 am
by vrld
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

Posted: Tue Nov 16, 2010 1:12 am
by Simtex
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.

Re: Quick Lua math question

Posted: Tue Nov 16, 2010 5:36 am
by trookat
Taehl wrote:Image
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.
That looks quite effective.

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

Re: Quick Lua math question

Posted: Tue Nov 16, 2010 5:06 pm
by Robin
The formula doesn't look familiar to me, but if you're right, then I'd like to say: ha. :P