1

Is there any fast way of creating filled organic looking blob shapes in a list/array? (around 30x30 would be enough, nothing bigger) I have referred to this post C++ create random shaped "blob" objects but the problem is that this creates an outline and is not fast as it has to loop through every integer angle.

Any ideas would be appreciated. I'm coding in python but just the plain algorithm would work :) Thanks in advance!

DaNubCoding
  • 320
  • 2
  • 11
  • Have you tried marching cubes? (or in this case, squares?) Not sure about the patent status. – Neil Aug 22 '22 at 15:01
  • Given an outline, there's ways of filling it in (e.g. scan horizontally, filling in squares once you reach the outline, stop once you reach the outline again - you need to scan until the end because the blob could be concave). Are you sure that going through a list of angles would be too slow? You could just choose an evenly spaced set of angles, then interpolate between them. – 10762409 Aug 23 '22 at 01:16
  • Also, potential duplicate of https://stackoverflow.com/questions/3587704/good-way-to-procedurally-generate-a-blob-graphic-in-2d – 10762409 Aug 23 '22 at 01:17

1 Answers1

0

Eventually I settled on using metaballs. Here's the code:

@dataclass
class Metaball:
    center: tuple[int, int]
    radius: float

def blob():
    balls = [Metaball((randint(4, 11), randint(4, 11)), randint(2, 4)) for _ in range(randint(3, 4))]

    result = []

    for y in range(16):
        result.append([])
        for x in range(16):
            if sum([(ball.radius / distance / 2) if (distance := dist(ball.center, (x, y))) else 10 for ball in balls]) > 1.2:
                result[y].append("#")
            else:
                result[y].append(".")

    return result

for row in blob():
     for ch in row:
         print(ch, end=" ")
     print()
DaNubCoding
  • 320
  • 2
  • 11