I have a group of sprites that are all the same in a loop. What would be the best way to offset each animation frame, so they all don't animate at the same frame.
I set an index on the sprites, then used modulus to target every second sprite, and then used:
sprite.animations.next(frameNumber);
to offset the frame
Related
Given a number of points on a 2d surface and radiuses for these points I can easily paint circles for them. What I need is an algorithm that only paints the envelope (right word for what I am looking for?) or outer bound of these combined circles. Additionally a second set of circles can 'encroach' on these circles, resulting in a kind of 'border'.
Image of what I am looking for
A quick way to draw the outline of the union of the disks is to
fill all disks in yellow, then
fill all disks in white with a smaller radius.
This can be adapted to the "encroached" circles, provided you only fill the remaining portions of the disks. Unfortunately, in a general setting finding the remaining portions can be an uneasy geometric problem.
There is an alternative approach which can work in all cases:
fill an image with zeroes, then for all disks fill every pixel with the value of the distance to the circumference (maximum at the center), but only keep the highest value so far.
while you do this, fill a second image with the color of the disk that achieved that highest value. (Initialize the image with the background color.)
At the end of this process, the first image will represent a "terrain" made of intersecting cones; and for every point of the terrain, you will know the color.
finally, color the pixels that have a height smaller than the desired stroke width, using the color map.
You can do the drawing in two steps.
1) Draw the outline using the following method: For each point, draw a circle using your favorite circle-drawing method, but before drawing a pixel, ensure that it is not contained inside any other circle. Do this for every point and you will get your outline.
2) Draw the borders between different sets using the following method: For each pair of points from different sets, calculate the two intersection points of the circles. If there is an intersection, the border can be drawn as a segment joining these two points. However, you have to make two lines, one for circle A, and another for circle B. To draw the line for circle A, slightly offset the segment towards point A. Then, use your favorite line-drawing method, but before drawing a pixel, ensure that it is closer to point A that any other point of the opposite set. After drawing the line, repeat the process for circle B. Note that both segment are not guaranteed to be the same length since the asymmetry of the points of the different sets. It will, however, always form a closed shape when all outlines and borders are drawn.
I'm building a paged scrollview for SceneKit, where i have a bunch of nodes under a main contentNode as seen below.
My problem is trying to figure out the width of the node - in 2D coordinates - so i can calculate the amount of padding as seen below.
Current (failed) plan
projecting one of the nodes' boundingBox. Got an unreasonably large value there for width.
calculate amount of horizontal padding by subtracting the width of my SCNSceneView by the width of one of the nodes. All nodes are the same width and height.
Use half of that value so the objects to the left and right "peek" in a bit.
Unproject that value so i can apply the spacing.
So i'm stumped at the crazy values for the bounding box if anyone understands my error.
I created a custom venn chart for two sets an their intersection in JavaFX.
Now I want to show the number of elements in this sets like in the following picture:
The sets are ellipses and I used masks to give the intersection a different color.
Now I want to show the number with size and position related to the available space so that the numbers are always inside the according area.
The width for the text element is easy to calculate, but I don't know how to get available height for the text elements.
Maybe it could be helpful to have the pixels of the ellipses as path, but I have no idea to how I can get this.
Does anyone know how to implement that?
Edit:
I developed an algorithm to find the size of a rectangle, which fits in the required areas of the ellipses. The text are scaled to the size of the rectangle and it works, but now I have another problem.
I need to center the scaled text in the rectangle an I used a StackPane for that. But I can't position the StackPane in the chart parent. If I set the layoutX and layoutY the bounds in parent are different.
For example: stackPane with text = sp;
sp.setLayoutY(122.1662320906945);
The Result for getBoundsInParent().getMinY() is 97.16622924804688;
How can I set the StackPane position, if I use it in a chart class as chart children?
How can I calculate object bottom position?
I created an object and a plane, both in (0,0,0) position, but the model geometrical center is placed in that point, not the bottom face of it, in result, the plane is clipping the half of it, see the demo: http://www.edar.com.pl/test-3d-3/
I'd like my models to have the same height when I place them on the screen. Also I want them all to intersect the shadow plane with their bottom parts, so I guess I have to calculate their heights and move them via object.position.y = obj_height/2; ?
Check Three.GeometryUtils.Center() - function which centers the geometry of an object.
So you could copy and modify the function to your liking to center the geometry at the bottom center.
Also you could also iterate over all vertices and just add or remove an offset-vector.
I'm trying to make a square move by rotating it sideways with its reference point set to the bottom side of the direction it is moving to.
For example: if I would move the square to the right, I would set its reference point to the bottom right of it and animate a rotation of 90 degrees, after the movement is done, I increase the square X by the width of it and centrally set its rotation to 90 degrees (so that I can keep track of its position)
The thing is, how should I proceed to keep repeating it? 'cause if I try to rotate by another 90 degrees using bottom right reference point, it won't be using the right position. What should I do to get the new bottom right relative position?
Thanks!
Create a transparent image twice as wide and high as the square.
Place the square in the top left corner.
Rotating the image around its center will now rotate the square in the way you describe.
You will need some maths to track where the new bottom is, using some simple formula for 2D rotation, so you calculate BEFORE rotating, where the point you wish to modify.
Then you use xReference and yReference variables :)