We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Dear all interested readers,
What would be a good method to do this? I guess the best way to start is to make a vertex and somehow turn it into an object. What should I do to change the values of the vertex, to get to this animated field?
Could you give me a start? I don't have much experience with these shapes.
Thanks in advance
Answers
Link please?
I can't see the Animation here
http://www.witregel.nl/blocks.gif
It is all the same repeating pattern that moves with offset in time. I would use shape to create a square with four verticies and just move them like on the gif.
Thank you. I agree. But how would I be able to create an offset in time?
There are basically two tricks to making this work:
You can draw any quadrilateral in Processing by calling beginShape(), calling vertex(x, y,) four times, and then calling endShape(CLOSE)
You animate one of four vertices so that a square becomes a triangle or a triangle becomes a square while doing some "trickery" with the vertices once the "square step" completes
In the codes below that "trickery" is the numbering of a square during each "square step". Originally, in clock-wise order, the square is numbered 0, 1, 2, 3 starting from the top-left position. The next time a square is formed the numbering is 1, 2, 3, 0 (again from the top-left in clockwise order). After that it is 2, 3, 0, 1. After that it is 3, 0, 1, 2. Finally it returns to 0, 1, 2, 3:
If you make sense of why this works then making several instances of this at different points in time should be no problem
Thank you very much.
I don't yet fully understand, how to use this in a for loop, but I might figure it out. Thank you for the explanation.
Note, I am just making this up, I am sure there are other ways to do it
Say you wanted a 10 x 10 grid of these things which is 100 things. You would have to count from 0 to 99 to place them (lets say you are using one for loop to simplify the explanation). For each iteration of i:
Divide i by 12.5 (because there are 8 possible states and 100.0 / 12.5 is 8.0)
Bin each value you get into being state 0, state 1, state 2, etc. by rounding down
Place the initial positions of each vertex based on the state (the 0, 1, 2, 3 from top-left, or 1, 2, 3, 0 from top-left, or 2, 3, 0, 1 from top-left, etc.). Note that you have both four kinds of square numbering and four kinds of triangle numbering
After having setup the initial positions of each vertex you are going to want to move one of them based on the state as well to get "progress" in that state
Lets say i had an original value of 42. 42 / 12.5 = 3.36 an so it is state 3 which is a triangle. In state 3 you have to figure out how much to move vertices[3] to the right. If you round 3.36 down you get 3.0 and 3.36 - 3.0 is 0.36 so vertices[3] needs to be placed 36% of the way to the right as its initial position
Thank you for your response. I still don't seem to understand how to write the functions in a loop, with the explanation above.
The code I posted only had one of these things instead of a grid of them so I hard-coded a lot of numbers because that was easy to do. The first step towards making a grid I think is turning these things into instances of a class, I'll call it BoxTriangle
All of the 100.0 I hard-coded have become this.left or this.top and the 300.0 have become this.left + blockWidth or this.top + blockWidth. That way tween() works regardless of where a BoxTriangle instance is placed
The code below is still incomplete because the floating point state I described above has not been calculated in the for loop in setup(). Additionally, when that is calculated the constructor for BoxTriangle will have to set the initial values of the vertices based on the floating point state. In the above example 3.36 was some floating point state value (based on i) and so this.state (for that instance) would be 3 and the vertices would have to be set appropriately for state 3 + 36% of the way to state 4
Thank you so much, but it wasn't clear for me how to solve it. How can I put in the animation? Hope you can advise me. Thank you very much
@joshuakoomen
Is this supposed to be the animation that you are asking how to create? You linked to it earlier, but it is gone now.
So this isn't an animated gif -- instead, each square is a moment in the animation?
One approach:
For more on how to interpolate a list of vectors, see LerpVectorsExample:
One thing to notice is that you could define your animation vector data on a unit square -- (0,0), (0,1), (1,1), (1,0). Then you can easily scale the output however you like by multiplying it by the target width and height.
the original was. an 8 x 8 grid where each square did the same thing but they were out of phase of each other. the posted image shows a range of those phases, it isn't a set of all frames.
...got it. And the grid is displayed in a back-and-forth, boustrophedon style?
edit
ah, no. It looks like the offset animations are running across the rows, maybe...? Based on the bottom corner I suspect that the animation states that aren't revealed in the still image would move the top two points (symmetrically to how the bottom two are shown moving).
Line starts between A and B and the right hand edge moves down until it's A to D. Then the other end moves until it's B to D. Then B to C, C to D, D to A, C to A, C to B, back to A to B
Except the posted example is rotating anti clockwise...
Here is a quick demo of an animated quad outline that is shifting counter-clockwise. It is based on a single animation path which is followed (at different time offsets) by four points -- two sliding points and two anchor points (which shift instantly).
The unit vectors of the path are all defined in setup, and they are scaled (with
mult()
) from 1.0 up to a screen size defined in the global variable SCALING.The series of vectors defines a looped animation path, which is why there are repeat entries (to create pauses in the animation) and why the last entry wraps to the first (to close the path).
One way to approach a problem like this is to describe the problem:
...and then break it down into parts:
This code could be refactored to make it more compact -- I left it loose and explicit (if a bit repetitive) to make it easier to play around individual timing values logics and colors, add / drop / reorder points, or add / substitute quad() or beginShape as an approach etc.