We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I'm quite new to Processing. I know how to use for loops to add elements, but I don't know how to go about creating an element, which expand from a center.
Answers
You can post your example image here. I cannot see it without signing up for a Dropbox account.
Ah, sorry. Here it is.
@kasperrubin -- re:
What, precisely, are you trying to do?
For a related discussion, see: https://forum.processing.org/two/discussion/comment/75708/#Comment_75708
That does seem like a possible solution. The question is what do I truly want with my grid, other than making it work with a sound input? I don't know. Maybe tomorrow I will.
But thanks for your help. I will write again when I understand this a little better :)
If you are trying to do simple radial sound visualizations that are nested like rings, then instead of a grid consider simply:
Okay, I found out what I want with the shapes. I need some way of adding copies of 1 hexagon in random order, as long as the next shape is adjacent to one of the already created shapes.
Like this:
Are you adding them one at a time, or are they growing in many places at once?
Does it matter if the space where you were going to add a new hexagon is already filled with a hexagon -- do you need to check if it is empty first?
Actually they will be growing from up to three different places at once. The idea is that they will be formed by trebble, midrange and bass frequencies, starting from one center and growing outwards, while still appearing like one structure, other than three arms.
I'm not sure I understand what you mean. If there is already a hexagon, it will place it on top of that?
But yes, I think it matters. Because a user is going to be able to decide how many elements the figure will consist of and if it's drawing new elements on top of already existing ones, how will you know if the numbers are right?
Forget about growing it for now. Can you just draw a bunch of hexagons in a grid that covers the entire sketch (with the center one being in the center). That would be a great start...
I can.
Please edit your post (gear icon in the top right corner of your post), select your code and hit ctrl+o to format your code. Make sure there is an empty line above and below your code.
This problem consist of mapping all hexagon's centers in he sketch area. Then you randomly place an hexagon applying two conditions to the next placement:
This condition doesn't apply to the first placement.
Kf
This is not how the code formatter should look like, but it's the closest I could get. I tried putting an empty line above and below, but then it wouldn't format anything at all.
So to make random hexagons map out from a centered element, all I need to do is add an if else statement. How do I write those conditions?
(code formatted)
One obvious thing
The second condition there is unnecessary - the else is already the opposite of the if, no need for another check
This is enough.
Also width and height are both 0 in lines 1 and 2 because they only get set after setup has run.
Does your code run? The above suggests you either see nothing or will get an array index out of bounds exception
Whoa there, hold on. Back up and slow down. You are drawing hexagons, yes, but not in a way that is at all useful. You want a grid of hexagons, right? If you think about it, a grid of hexagons is still a plain old 2D grid of rectangles - it's just that the even numbered columns are shifted down a bit. So let's back up even more and start with a grid of rectangles:
Now, let's shift the even columns down half way:
Alright. Looks hexagon-y already!
In fact, it looks so hexagon-grid-like already, why don't we just try drawing hexagons now?!?
Hey - not bad!
Let's adjust the spacing now, back to what your grid had. Let's also fix the bug my previous posts had where I had wide and tall swapped as the bounds for my for loop (Whoops! Test your code better, TF!):
This is where I wanted to make sure you were STARTING from. This is what I had in mind when I asked you if you could just draw a grid of hexagons.
A few more minor changes now. For one, they are Hexagons, so let's rename things a bit. We're going to shift the even columns up instead of down now, and we've meddled with the limits for how many hexagons wide and tall we're going to do.
Oh, and each hexagon can now be active, and we try to activate the middle one when we do a mouse click - try it!
Software development is a process of making small changes and making sure they work. Did you try to click like I suggested? Were you totally underwhelmed when the middle hexagon DIDN'T light up? Can you SPOT THE BUG???
No seriously, this is a good one. Why doesn't the hexagon light up?
Last chance to try to work it out yourself.
Answer in next post...
AH HA!
You don't get any fill when you only draw lines!
And now that we have the central hexagon lighting up, and we know which one it is, so we know its position, we might consider drawing things so that that specific hexagon is ACTUALLY in the center of the sketch:
Also note the change to the wide variable now as well - we might need an extra column to fully cover the grid.
Dang, that is a sweet honeycomb! Take that, bees!
Can we activate them at random? Yep! But the bottom row wouldn't light up - turns out we might actually need a +3 on the tall! Here's random lighting up:
Clicking also does it.
And with a little more effort, each frame a random hexagon is looked for until an active one is found. Then a random direction away from that hexagon is picked and that adjacent hexagon also activates. Due to randomness, this might take a while for the active area to expand, so it's going to happen automatically now in draw:
So now you have hexagons spreading out from a central point. You can fiddle with this a bit more yourself to have it activate based on music or whatever. Send beer money via paypal to tfguy44 at gmail dot com (so thirsty!).
So, uh, yeah... the spreading is a little wrong. Fixes:
And:
And also:
Basically anywhere I was checking rand_Y%2 should be rand_X%2....
@TfGuy44 Thank you so much for explaining this is such humorous detail and steps!
There is quite a number of things I will need to read up upon, but perhaps you could enlighten me on this one: What does it do?
A hexagon has six hexagons that surround it. If you give each hexagon a row number and a column number, how do you have to change the row and column number of a given hexagons to get to those other six surrounding hexagons' row and column numbers? The two above and below are easy: -1 and 1 in the column number, no change in the row number. The four in other columns are a little trickier: you change the column number by -1 or 1, but you might either stay in the same row (0) or move up a row (-1) or down a row(1), depending on if you're dealing with a hexagon in an even numbered column or not.
Here on the forum, to post code properly, select the code in your post and hit Ctrl + o.
Still a little hard to comprehend :) I'm going to rewrite your example and see what everything means.
Okay, so I did some modifications and it kinda works alright now.
So I thought I would replace the created hexagons with an SVG hexagon, to get some more detail into the shape. That though is causing some issues.
Inside my projects folder I have a folder called Data and the "hexagon-three-sides.svg" is placed there.
I'm also getting a lengthy error concerning the PShape:
Can you just draw the hexagon SVG shape without the rest of the sketch? That is:
You know, scrap that SVG for now. It's not absolutely necessary for my project.
As of now the hexagon structure is build automatically in a random way with random colors from an array.
What I'm aiming at is a little more structured:
STEP 1:
I have an array with 10 colors:
I have 5 arrays with 3 values each:
Before the hexagon figure is being built, I want to press a button, which:
is connected with 1 array
collects all 3 percentage values from that array
add 3 random colors from the color array to the percentage values in random order
distribute those values into the hexagon figure by percentages, so guitar[0] will be 30 % represented, guitar[1] will be 60 % represented etc.
Place colors next to same colored neighbors with a percentage of 80 %
STEP 2:
Whenever I press another button connected with another array, I want it to override the color percentages with the new ones. So the created structures remains, but the colors change.
So, how do I do that? ;)
The button is connected with 1 array? Or with one hexagon?
With 1 array. But it will distribute values to all available hexagons.