How to generate clumps of minerals?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

How to generate clumps of minerals?

Post by Gunroar:Cannon() »

Which algorithm could I use to generate ore veins in a 2D (side) view? Where I can adjust how much the ore is generated?

Image
Kind of like this
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
pgimeno
Party member
Posts: 3541
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to generate clumps of minerals?

Post by pgimeno »

Have you tried thinking instead of asking?
  1. Pick a random coordinate
  2. Pick two random numbers for offset.
  3. If coordinate + offset is dirt, replace it with mineral.
  4. Repeat steps 2 and 3 as many times as desired.
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: How to generate clumps of minerals?

Post by Gunroar:Cannon() »

pgimeno wrote: Tue Oct 19, 2021 8:14 pm Have you tried thinking instead of asking?
Image

Hmmm, that's a nice and clean solution, I guess I was expecting something like cellular or perlin noise. :? :ultrahappy:
Also does that method deal with bigger clumps? From what I understand won't most of the clumps look the same?
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
darkfrei
Party member
Posts: 1168
Joined: Sat Feb 08, 2020 11:09 pm

Re: How to generate clumps of minerals?

Post by darkfrei »

Gunroar:Cannon() wrote: Tue Oct 19, 2021 9:58 pm Also does that method deal with bigger clumps? From what I understand won't most of the clumps look the same?
Create particle, add some mineral here.
Create new particle and move both of them in random direction.
Repeat until you want.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: How to generate clumps of minerals?

Post by Gunroar:Cannon() »

darkfrei wrote: Create particle, add some mineral here.
Create new particle and move both of them in random direction.
Repeat until you want.
What's a particle in your terminology?
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
darkfrei
Party member
Posts: 1168
Joined: Sat Feb 08, 2020 11:09 pm

Re: How to generate clumps of minerals?

Post by darkfrei »

Gunroar:Cannon() wrote: Tue Oct 19, 2021 11:06 pm
darkfrei wrote: Create particle, add some mineral here.
Create new particle and move both of them in random direction.
Repeat until you want.
What's a particle in your terminology?
The thing that will be created, it moves and disappears, maybe generates other particles.
It can move freeways as

Code: Select all

x,y=x+dt*vx,y+dt*vy
or chunk-based, like

Code: Select all

x,y=x+math.random(-1,1)*chunkSize, y+math.random(-1,1)*chunkSize
.
After the movement it can check if it can place here some ore, creates another particle, counts one step down and if it is lower than lowest value, then disappears.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
milon
Party member
Posts: 472
Joined: Thu Jan 18, 2018 9:14 pm

Re: How to generate clumps of minerals?

Post by milon »

There are going to be dozens - if not hundreds - of ways to accomplish this. The "best" will be determined by your desired outcome. Do you want random blobs? Seams of ore that branch? Tiny specs here and there? etc... You could certainly use a cellular automata (you'll get a LOT of ore) or a 2D noise map (with a set threshold) for a more fine-tuneable setup.
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: How to generate clumps of minerals?

Post by Gunroar:Cannon() »

I kind of want to use both random blobs (I guess pgimeno's method works for that) and seems of ore that branch...
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
darkfrei
Party member
Posts: 1168
Joined: Sat Feb 08, 2020 11:09 pm

Re: How to generate clumps of minerals?

Post by darkfrei »

Gunroar:Cannon() wrote: Wed Oct 20, 2021 1:44 pm I kind of want to use both random blobs (I guess pgimeno's method works for that) and seems of ore that branch...
Please try this solution (click on the screen):



ore-patches-01.png
ore-patches-01.png (62.38 KiB) Viewed 4687 times
ore-patches-01.love
(1.06 KiB) Downloaded 158 times
ore-patches-02.love
(1.17 KiB) Downloaded 174 times
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: How to generate clumps of minerals?

Post by Gunroar:Cannon() »

Woah, that's really cool though advanced. So I could just make the white parts minerals . I just ran it but haven't checked out the code, any way to scale it?
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests