How can I make a coordinate plane view controller in Xcode? I've tried to use OPENGL but it hasn't been working. Do I have to draw lines individually? Make it recursively called so that it keeps making a certain amount of lines?
You will want to take into account what you will be doing to the coordinate plan. Can you move the plane? Can you zoom in?
You will want to set up centerLocation and scale variables. centerLocation denotes your center and this is where you will draw a vertical and a horizontal bold line for the axes. scale denotes how many pixels per unit you want to have. You can the default to something like 10. You can use this variable to control zooming.
If you want to use the plane for something like graphing functions, the bare minimum you need is the axes. You can use the scale to find out where "points" are in your grid. Making functions for this is useful.
If you want to draw grid lines, what you can do is simply check the leftmost bound of the grid using the centerLocation.x as an offset and then iterate through the pixels by increments of scale and simply draw a vertical line at each point you come across until you get to the end. Same for horizontal lines, except you can start at the top, offset centerLocation.y, and add a horizontal line in increments of scale until your counter is greater than the height of the screen.
Related
I am using mapbox-gl and have point and line layers on the map. All layers are vector tiles. Some points lie on the lines, some not and I want to hide points that don't lie on the lines
Is it possible to do it only on the frontend side with writing something like a filter that checks if a point on any line or not? I really don't want to change the backend
Why don't you use turf.js in conjunction with mapbox-gl-js?
E.g. you could calculate the distance to the line with http://turfjs.org/docs/#pointToLineDistance for each point, then filter out any points with a distance bigger than 0.
I am making a side scrolling game.
What I want is that the layers distant view, middle distance view, near distance view zoom in and out at different ratios.
How do you do that?
You have to understand that if you're using an orthographic camera, the depth (i.e. transform.position.z) is used to decide which objects are rendered on top of others.
Any effect associated with perspective (i.e.: scaling) is lost.
So, in order to do what you want to do, a quick way is to group your objects based on distance (far, middle, near) and scale them accordingly via code (changing their transform.localScale X and Y values). Of course the objects on the far distance will change their localScale less than the middle, and the middle will change less than the near.
I am new to Iphone. I want to draw a circle with different colors in it. And all the colors should cover equal area. Like if I want to have 10 different colors in it. Then each color should cover 1/10th area of the circle. I am not trying to draw a pie chart here. Also not trying to use 10 different colors. Just want 10 equal parts of circle and each part can be filled with colors.
I am trying to build a fortune wheel. Such that a smaller wheel is above the larger wheel. And then I want to drag them separately.
Also is it possible to do this with help of Core Animation?
Ambiguous question. If you draw a piechart with 10 equal areas then each will cover 1/10th of the area, thus fulfilling your request, no?
There are 360° in a circle, so divide that by 10 and each wedge should have a 36°. Now you just have to draw 10 wedges, and this page should help you:
http://www.raywenderlich.com/2106/core-graphics-101-arcs-and-paths
Since you say you don't want pie slices, do you want concentric rings instead?
And are you sure you want equal AREA? That will make the rings different thicknesses. The innermost ring will be fairly thick, and each ring as you go outward will be thinner. Much thinner, on the outer rings.
Our eyes are used to a bulls-eye formation, where each ring is the same thickness.
In any case, you should look at CAShapeLayer objects. You can create a shape layer for each ring that defines a closed path with 2 circles. There is something called the "winding rule" that lets you determine what happens when paths overlap. I think you'd want even-odd path winding (kCAFillRuleEvenOdd).
To make the rings equal area, you could do this:
First calculate the area of the whole circle. Divide by the number of rings. That's the desired area for each ring Let's call that area "a". Start from the center. The radius of that ring (a circle) will be sqrt(pi/a).
For each following ring you'll need to calculate the thickness of the ring based on the area of the outer circle minus the area of the inner circle that makes up the ring. You'll need to write an equation that solves for the outer radius given the desired area and the radius or the previous circle.
I am successfully rendering a bezier curve in real-time as the user draws with a finger (I modified glpaint). I can adjust the width of the line just prior to drawing. This results in the whole line drawing at this new width, but remaining constant at this width over the course of the line. But I want a smooth variance of width across the course of this one line. I can also adjust the brush width dynamically as the user draws, however this results in a blotchy line for the following reasons.
The curve is rendered in points using glDrawArray(). As the user draws, for about every few touchpoints my bezier function calculates potentially hundreds of points to render, at which point it sends these points into the gldrawarray function to be rendered. The problem is that the width varyiance really needs to be plotted along these points dynamically and must be able to change brush width over the course of the drawing of these passed points, but because they are sent into the function as a whole group to be drawn at once via glDrawArray achieving smooth width varyiance across the overall line has proven elusive thus far.
Do you know of a way to achieve a varying brush width in real time, across one bezier curve drawn with points, and ideally drawn with glDrawArray(), and without resorting to using triangles, etc?
AFAIK the only way to achieve this is to create a filled polygon, where the skeleton is determined by your original path, and the width is varied along the length by displacing vertices for each side tangential to the path.
So you end up constructing a closed path around your bézier curve, thus:
The width at each control point is varied by the distance between each side, shown in green.
I hope this rough diagram clarifies the description above!
I am trying to figure out how can you drag an image while constraining its movement along a certain path.
I tried several tricks including animation along a path, but couldn't get the animation to play and pause and play backwards - so that seems out of the question.
Any ideas ? anyone ?
What you're basically trying to do is match finger movement to a 'translation' transition.
As the user touches down and starts to move their finger you want to use the current touch point value to create a translation transform which you apply to your UIImageView. Here's how you would do it:
On touch down, save the imageview's starting x,y position.
On move, calculate the delta from old point to new one. This is where you can clamp the values. So you can ignore, say, the y change and only use the x deltas. This means that the image will only move left to right. If you ignore the x and use y, then it only moves up and down.
Once you have the 'new' calculated/clamped x,y values, use it to create a new transform using CGAffineTransformMakeTranslation(x, y). Assign this transform to the UIImageView. The image moves to that place.
Once the finger lifts, figure out the delta from the original starting x,y, point and the lift-off point, then adjust the ImageView's bounds and reset the transform to CGAffineTransformIdentity. This doesn't move the object, but it sets it so subsequent accesses to the ImageView use the actual position and don't have to keep adjusting for transforms.
Moving along on a grid is easy too. Just round out the x,y values in step 2 so they're a multiple of the grid size (i.e. round out to every 10 pixel) before you pass it on to make the translation transform.
If you want to make it extra smooth, surround the code where you assign the transition with UIView animation blocks. Mess around with the easing and timing settings. The image should drag behind a bit but smoothly 'rubber-band' from one touch point to the next.
See this Sample Code : Move Me