Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm looking to draw irregular shapes on an x,y grid, and I'd like to come up with a simple, fast method if possible. My only idea so far is to draw a bunch of circles of random sizes very near each other, but at a random distance apart from a more or less central coordinate, then fill in any blank spaces. I realize this is a clunky, inelegant method, hopefully it will give you a rough idea of the kinds of rounded, random blotchy shapesI'm shooting for. Please suggest methods to accomplish this, I'm not so much interested in code. I can noodle that part out myself. Thanks!

share|improve this question
2  
I would help if you attached some examples of such shapes, but from what I understood, Marching Squares algorithm might be what you're looking for. –  Alexander Konstantinov Sep 24 '13 at 8:56
    
For examples, in all seriousness, think liver spots: rounded, random, but generally ovoid. –  Yttermayn Sep 24 '13 at 13:15
6  
This mathematica.SE post has some examples you might find interesting: mathematica.stackexchange.com/questions/3345/… The top answer basically does what you're doing. another finds the convex hull of random points and then interpolates a spline through it, but that seems a little complicated... –  Jeremy Sep 24 '13 at 18:46
    
Thanks for your responses! Unfortunately I think I might be a little bit in over my head. I may have to figure something else out. –  Yttermayn Sep 24 '13 at 20:54
4  
What about starting with a circle close to the desired size and then permutate it using perlin noise. Either by moving selected pixel, or by fading / extending the circle. –  floAr Sep 25 '13 at 11:49

3 Answers 3

You might want to choose some points, choose a vector at each point and draw a spline through them. See this wikipedia page for a simple description of a cubic spline (aka Irwin-Hall spline). It's been a while since I used them, but if I remember correctly, this was the one that I found to be the easiest to understand and use. If you know the pen tool from photoshop, this works very similar (I'm convinced photoshop uses splines too, but I'm not sure if it is a cubic spline).

If you're interested, there are many more splines: for example, Bezier splines and B-splines are interesting.

Another thing that comes to mind are level sets, although that would probably require a little more research from your side (to find functions that satisfy your requirements).

Level sets are inequalities in the form
f(x, y) = c
where f is some function and c is some constant.
This is a very general description. You might want to fill out some shape, and draw all pixels where
f(x, y) <= c
with some color. For example, for a perfectly round 2d shape, you have the well-known equation:
x^2 + y^2 <= r^2
You can scale the x and y components to get an ellipsoid With a little experimentation and research, it will be possible to find some funkier shapes (I suppose).

Edit: a little experimentation on wolframalpha.com gave me this. (created with the command 'plot abs((x+sin(x)*y/3)^3)+y^2<=7'). I have no idea if this is anything like what you want, but it's just to give you an idea.

share|improve this answer

Aside from the other answers, you could use a Perlin noise with a round falloff, if you tweak the settings a little, you could easily create some nice varying shapes.

If you want your code to be fast, you could just use a noise-generation library like libnoise(Assuming you are using c++), which is a noise-generation library, that makes similar tasks very simple, as it provides you with a node-based approach on noise-based procedural generation. It has bindings to other languages too.

share|improve this answer

Another straightforward approach is by using your own low-frequency noise to draw (or define) a figure in polar coordinates.

Suppose you want a blob centered at the origin, of average radius 1; this can easily be scaled and translated to other positions and sizes. Imagine with the simple equation r=1 — this would define a circle of radius one at the origin. To add a little variation to it, you can change the radius sinusoidally - add a term of the form w1*sin(θ+θ1), where w1 and θ1 are constants I'll get back to in a bit. One sin term won't make a whole lot of difference, but having several different sines of different frequencies will start to add exactly the sort of 'soft' variation I suspect you're after. The overall form would be along the lines of r=1+w1*sin(θ+θ1)+w2*sin(2θ+θ2)+w3*sin(3θ+θ3)+w4*sin(4θ+θ4)+w5*sin(5θ+θ5) - or more terms if you want, of course.

So how do we pick the values for wi and θi? Well, the θs should just be picked randomly from (0,2π) - in other words, each 'wave' on the surface's shape should start at a different point around the shape. As for the w's, there are several different choices. Choosing wi at random from (0, w) (for some fixed w that represents the 'overall variation' to give the shape; I might start with w=0.25 but experiment with w=0.1) for every i will lead to so-called white noise, where all the frequencies have equal weight — this will be by far the 'blobbiest', with wide variations at all frequencies. Choosing wi at random from (0, w*(1/i)) — in other words, dividing each random weight by i — gives pink noise, where the weight trails off, but slowly. This is also known as 1/f noise, and it's the most famous 'fractal' noise. Finally, choosing the weights randomly from (0, w*(1/i^2)) (in other words, dividing each random weight by i^2) gives brownian noise - this is the 'softest' of the three, with the least variation from a circle - it'll generally be an oval-ish shape.

Here are examples of the three, using a 'total weight' of w=0.25, and using the same set of random values for the wi and θi pulled from random.org:

"White Noise" blob: A blob made with white noise

"Pink Noise" blob: A blob made with pink noise

"Brownian Noise" blob: A blob made with brownian noise

Note that these blobs won't be perfect; in particular, it's impossible for them to curl back on themselves (since for every θ — in other words, for every angle from the origin — there's a single r value), and if you don't choose your weights right they might self-intersect (if r is allowed to go negative). But they do a decent job of being convincingly blobby, and for most games applications users won't notice any issues.

share|improve this answer
    
(Also note: the fact that these shapes are so close to symmetric is an artifact of (a) the coefficients of the second and fourth harmonics being so small, and (b) the phases of the first, third and fifth harmonics - how much we displace the theta values - being so close, at .468, .464 and .443; most 'blobs' won't have nearly this much symmetry about them.) –  Steven Stadnicki Oct 31 '13 at 19:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.