With the help of various code snippets from this forum, I have managed to create a working metaball simulaton. I used a threshhold to get a clean border between the metaballs and the background.
Now, I would like to draw just the outlines of the metaballs. I tried using a min. and max. treshholds to achieve this, and allthough the result (shown below) does show something aking to an outline, it's still not quite what I am looking for. Especially the thicker parts of the line is what I want to get rid of.
As far as I understand it, the above image doesn't actually contain any lines, but just neighbouring white pixels which give the impression of a line.
I am thinking that it should be possible to find coordinates on these "outlines" and use them to create a bézier curve, wich would then creat a clean, continuously thick line around the metaballs. The problem: I have no idea how to start doing this.
Is this actually possible?
Am I overthinking this using metaballs and there is in fact a better solution?
Does this have something to do with blob-detection?
I'm not trying to create moving metaballs. I just want to draw the metaballs once and then create the clean outlines. So performance isn't an issue for once.
Following the fabulous
Nature of Code tutorials by Dan Shiffman, I've replicated following simple sketch:
A single object is repulsed by the mouse pointer. Currently the object can move freely around the stage, but what I'm trying to achieve, is to have the object move away from the cursor, but at the same time be fixed to a "rail" (the red ring in the sketch).
But I have no clue how to achieve this. I'm thinking it may become quite complex, because I apply the repulsion force to the object, but since it only can move on a curved path, said force may act upon the object in ways I can't yet see. (Or lack the essential math for).
Any pointers to how I could tackle this problem would be greatly appreciated.
// if object reaches edge, "warp" to opposite side
void warpEdge() {
if (loc.x > width) {
loc.x = 0;
}
else if (loc.x < 0) {
loc.x = width;
}
if (loc.y > height) {
loc.y = 0;
}
else if (loc.y < 0) {
loc.y = height;
}
}
}
Slightly off-topic addendum: Dan has
kickstarted his NoC tutorials into a book! Currently he has outlined all chapters and is finalizing the layout and design. I am a project backer and have read some draft chapters. This thing will be awesome! So, if you are into this kind of programming, I highly recommend you keep an eye out for the final release.
This is one of those problems, where theres a simple task, yet the operation in the opposite direction just doesn't seem to be as easy.
It's simple to find a character at a specific position within a string: string.charAt(index)
I'm imagining, that it should be just as simple to replace a character at a specific position in said string with another character, but I can't for the life of me find a simple solution. The best I can come up with is to dissect the whole string into single chars, replace one and then join everything together again. But this seems very inelegant.
Basically I'm looking for the PImage.set(x,y,color) equivalent for Strings. Something like string.replace(index, char). Is this possible?
I'm not sure how this topic should best be called, so let me try to illustrate my problem.
Say I have a collection of points (the white ones), randomly scattered across the stage. Now I take one point (the red one) and try to find the one white point that is closest to it. Until now, I'd just check the distance to EVERY single point in the stage (all saved as objects in an Arraylist), and eventually find the one that is closest to my red point. This works quite fine for 1000 points, like in the image to the right. But this is only a very simplified version of what I'm trying to do, and eventually I'm expecting on having many 10k or even several 100k points in the sketch. That's where the calculations are starting to become quite resource hungry.
Is it possible to limit the "distance-checking" between the red point and it's white neighbors to a certain area (e.g. all points within the red circle)? This way I would only have to check a fraction of the total points, thus saving processing power. Is this possible? No idea if I can limit the search to an elliptical area or if it would be rectangular. How can I know if a point is near to my reference point, WITHOUT having to calculate it's position anyways?
I'd be grateful for any pointers! (See what I did there?)
Thanks!
cheers.
UPDATE: Would it perhaps make things easier, if the points where not randomly scattered, but set up on a grid? I'm guessing that it might be easier to reference the points, since they are written to the ArrayList in a more "orderly" fashion.
I have no idea, if what I'm thinking should be possible, actually IS possible, but let me try to explain:
I want to add new methods (behaviors) to initially "dumb" objects. In my sketch, all objects can have several, very different behaviors, but only one of them at a time. So up until now, I'd just create one kind of object "preloaded" with all methods it could eventually use. And then the object would await certain conditions, switch to the method it's told to use and go with it from there.
But... since I'm expecting my final behaviors/methods to become quite complex at some point, I'm wondering if there is another approach to what I'm planning to do. As mentioned above, I would create initially dumb objects, which don't have any behavior/methods and are completely oblivious of any behaviors they might receive. Then, when needed, a "controlling function" will select one of the objects and add one specific method to it. This way, every object only uses one method at a time and isn't cluttered with the other heavy methods it's not using.
Obviously, the script won't be able to write the method as new lines of code into the object. So I'm thinking there might be some way to tell an object to look for it's behavior with an other object. Some kind of "cross-referencing" of two objects. Sorry if this sounds abstract, but I really have no idea IF this is possible (or if it actually makes sense to try to do it in the first place). And I have no idea what this kind of technique might be called (if it even exists).
Again, I have no clue if my thinking is completely off track. But I'd really appreciate any kind of input on where I could start looking more into this.
what I first believed to be a more or less easy task turned out to tie knots in my brain.
Basically, I want to create an orthogonal grid, where it's possible to manipulate the position of every single vertice in a 2D space. So when one vertice is moved, all the lines connecting that vertice to it's neighbours move accordingly.
I believe such a thing is called a mesh?
I know that there is a mesh–library out there somewhere, but I'd like to try and build the mesh from ground up.
I know how to generate the original positions of the vertices on a grid.
But I have no clue as how to best tell every vertice who his neighbours are and to remain connected to them all the time. Because not all vertices have the same amount of connections:
- in the corners they have two
- on the edges they have three
- everywhere else they have four
And how do I prevent two vertices to connect themselves twice? (Once in ever direction)
Finally, the whole construct should not be to intense to compute, since I'd want it to be dynamic.
Is such a task feasible for a beginner/intermediate user?
Or are we talking about a rather complex problem here?
If anyone has some pointers as to how I should approach this task I'd be really thankful.