iOS OpenGL or CoreGraphics smooth rectangle drawing - iphone

I'm trying to draw a filled rectangle in the drawRect and the rotate it by 5 degrees. The problem is that when I rotate this rectangle, the edges look very jagged. I have the feeling that this needs some anti-alising (or something similar), but I can't find any good sources of more information.
Does anyone have a good hint?

It really isn't possible to have a nice, natural curve on a computer because if you look closely you will always see that it really isn't a curve, it's a jagged line of squares.
More answering your question, if you want your line to be softer, you could blur it with a CIFilter. Remember that when you rotate something by anything other than 90, 180, 270, or 360 degrees you will lose quality. Your rectangle doesn't need anti-aliasing until it's rotated, and I'm sure apple has written a beautifully complicated way to blend/antialias your context.
Probably the easiest way to do this is to draw the individual lines in your rect at the slant instead of rotate the rect after you draw it.

Related

What is the best way in unity to draw 3D objects which are lines (axis, grids, wired surfaces)?

I want to make a 3d graph in unity and on that graph draw curves and surfaces etc. on surfaces I may have the grid texture applied on them, all of this is achievable. but there is one thing effect which I do not know how to achieve.
Many components in this app will be lines, Like the x-axis, y-axis, z-axis, & some grid on the surface, now I want these lines to have constant thickness, I may zoom into or zoom out of stuff but these lines should always be of constant thickness on the screen, a 1px line
should always be 1 pixel no matter I zoom close to it or I zoom away from it.
How can we do it? Is it an Image effect or a Shader or some other trick, I need to know what is the right approach for something like this.
If you need that for editor usage you can use UnityEditor.Handles but you would need Renderers (feg. LineRenderer) to draw it in build

SpriteKit - Draw Bezier Curve Gradually

I'm working on an iOS educational where kids are drawing letters. The game mechanism is pretty simple and works OK. What I want to do is to show a drawing progress by turning the elapsed part into green thick line. See the image:
There are couple of solution I have in mind.
Mask over hidden path which transforms according to users touch position
Creating a new path on touchesMoved: by taking the original and adding a point to the user touch position, then stripping the rest
What would you choose or is there some better solution?
Note: I want to draw the green path precisely as the dashed one. By just drawing a path following the user movement would result in ugly line.
Thanks.
I would say your choice depends on whether the dashed line is also drawn (or drawable in all of its parts) with bezier curves.
If the dashed line is an image you show, probably solution 1 with an also drawn thick line and an adapted mask is easiest to do.
If the dashed line is already drawn as a bezier curve (or drawn by drawing several connected bezier curves), then solution 2 seems best to me. The tricky part would be to ensure you exactly follow the dashed line in this case (but I suppose you figured that already :-).

Iphone/Ipad : What is the fastest way to draw an irregular polygon in a rectangle?

I have to draw the following shape in a rectangle. What is the best way to do it? The blue areas are the background color. The black is a border and the red is the interior color. I want to paint the black and red only.
Thanks
It totally depends on how you would use the shape; whether they will move, how many of them will be displayed, whether they will be scaled while being displayed, etc.
In general, OpenGL ES is considered to be the fastest way of drawing on iOS devices. However, if you have only a small number of those shape (say, <10~100?) and the other part of the application does not have a lot of fast animations Quart 2D is usually enough in terms of drawing, in order to, say, achieve a 30/60Hz drawing rate.
How you use Quartz2D still matters a lot. If you need to redraw the shapes frequently, you would need to draw the shape on CALayers, and rather than redrawing the shapes, you should move and transform the layers.
Comparing drawing as a bitmap and a vector shape, I believe both would work fine for this kind of shape (especially because you would not redraw the shape so often, but only work with the layer on which the image already is drawn). But if your shapes are scaled frequently, you would consider vector images for the quality of the image.
To summarize, learn (if you don't already know) how to draw into a graphics context first (see Drawing and Printing Guide for iOS). You should be able to draw a simple vector shape or a bitmap image by overriding drawRect or similar methods inside a UIView object. Then if you need to animate those shapes, learn how to create a CALayer and draw on the layer (see Core Animation Programming Guide). Finally, if you need to create many duplicates of the shape on the screen, learn how to use CGLayer to replicate an image (see Quartz 2D Programming Guide).

iPhone animation: how do I animate the filling up of an area?

Consider a circle. Now consider a radius of the circle, drawn from the center of the circle towards the right. Now imagine that the radius is rotating about the center of the circle, sweeping out an area as it rotates. My problem is: I want to use iPhone's animation techniques to fill up the swept out area with a different color from the background area of the circle, as the radius rotates from 0 degrees to any chosen number of degrees about the circle.
I've looked through the Core Animation API, KeyFrame Animations, etc. but I am not able to find out how to do this. Any hints will be most welcome.
Thanks,
Sandeep
Check out CAShapeLayer. It lets you animate between two Core Graphics paths, which can be as complex as you want. In this case, you might want to animate between a path which defines a thin filled wedge and a filled wedge that covers a larger angle of the circle. You may need to use a CAKeyframeAnimation to make sure that it is animated in the sweeping motion you desire, and in the direction you want.

CGPath curve from points (iPhone)

I'm looking for a way to draw a curve (perhaps a parametric function?) into a CGContext
The best example which I can think of is the Adobe Ideas iPad application. As the user drags their finger, the application draws lines for every touchesMoved: using CGContextAddLineToPoint. After the user picks up their finger at touchesEnded:, the application does some math and replaces all of the lines with a single, smoothed curve.
What I have is a list of CGPoints, and I am looking to draw a smooth curve which follows those CGPoints into the CGContext.
Any assistance?
I'd advise creating a CGPathRef and use the CGPathAddQuadCurveToPoint method.
Hope this helps!