Quartz 2D -Drawing a point - iphone

I know that drawing a point by using drawing a line method in Quartz 2D is
CGContextMoveToPoint(context,x,y-0.5f);
CGContextAddLineToPoint(context,x,y+0.5f);
Is there any other possible way to draw a point using Quartz?
I meant, some direct way of doing so?

CGContextFillRect(context, CGRectMake(x,y,1,1));

if you want it to look like a circular point try this:
CGContextStrokeEllipseInRect(context, CGRectMake(x, y, 4, 4));
it will draw for you you a an ellipse inside a rectangle (above case is apparently a square). i prefer you to choose a square as it will look like a real circle and not oval one. however, this circle will be empty from the inside, you can fill it by a stroke. (but it looks cool like a donut!) :)

Related

How to draw a circle using arcs in createjs?

How to draw an arc in createJS. I have gone through arcTo function but its not what i want. I want to be able to draw several arcs which when put together resembles a circle.
for Ex: I want to be able to draw a circle using 8 arcs. not able to do it using ArcTo function. Please some one suggest me a way to do it.
The arcTo function draws directly from the specified point. The arc() function is what you are looking for.
Here is a quick sample that draws random segments.
http://jsfiddle.net/lannymcnie/nJKHk/
shape.graphics.arc(0,0,50,startAngle,endAngle);
here is another sample with random color fills.
http://jsfiddle.net/lannymcnie/nJKHk/1/

iOS Quartz 2D: draw an image simulating y axis rotation?

I want to do this:
draw an image using Quartz 2D, the image look like rotated according to its y axis in a 3D space, like this:
Is Quartz 2D capable to do this?
No, you cannot do this directly with Quartz 2D. It supports only affine transformations, which always preserve parallel lines.
(It's clear that you want the parallel lines on the top and bottom edges of your figure to become non-parallel.)
The term you're looking for is "perspective transformation", if you want to search for other ways to achieve this result.
I don't know how to do it in 2d, but its really easy to do it with quartz using this kind of call:
yourView.layer.transform = CATransform3DMakeRotation(M_PI/4, 0.0, 0.0, 1.0);
You should look into using the CATransform3D's. They are pretty powerful and easy to call.

I used CGPath to make a picture with 4 CALayers, how can I zoom in and out?

I used CGPath to make a picture with 4 CALayers, how can I zoom in and out?
The picture contained a four different circles, a rectangle, and a more complicated shape.However, I want to make it zoom in and out like UIRefreshControl.
It's unrealistic to control every shape at the same time to make it look like the original.
If you need it:
in your drawInRect: method you can add CGContextScaleCTM (yourContext,scaleX,scaleY); when scaleX and scaleY are CGFloat. Experiment with it. For example you can set scale with a UISlider.

clear part of UIImage

I've been doing some research on online for a project I'm doing but so far haven't been able to quite get it working. I want to be able to slide my finger over a UIImage and delete part of it, kind of like an eraser. I'm able to draw lines on the screen but can't figure out how to do this. Any help would be greatly appreciated.
Can you mask the image and when you draw on it, it adds the lines to the mask (in white, rest of mask is black) and then it should make those spots transparent
http://iosdevelopertips.com/cocoa/how-to-mask-an-image.html
There are two parts to this problem-
a) Determining the curve along which the finger was moved
b) Drawing the curve (which is really a combination of short lines) with the white color
For part (a), have a look at UIPanGestureRecognizer. Using the touchesBegan: & touchesMoved methods, you will be notified every time the finger moves even the smallest distance, and the source and destination co-ordinates, say (x1, y1) & (x2, y2).
Part (b), As you know how to draw a line, now you need to draw a line from the source to the destination with the line's width (thickness) equal to the finger's. For that you can set the line's width using CGContextSetLineWidth.

CGPath masked off CGPoints

I'm trying to build this:
Where the white background is in fact transparent. I know how to clip a CGPath to a set region, but this seems to be to other way around, since I need to substract regions from a filled CGPath.
I guess the right way to go would be to substract the whole outer-circles from the CGPath and then to draw smaller circles at my CGPoints, but I'm not sure how to execute the former. Can anyone point me in the right direction?
That's what I would do :
1) Draw your general line
2) CGContextSetBlendMode(context, kCGBlendModeClear) to "clear the context" when you draw.
3) Draw you bigger circles
4) CGContextSetBlendMode(context, kCGBlendModeNormal) to return to normal drawing
5) Draw your little circles.
You could instead start a transparency layer, draw the lines, then draw the larger transparent circles using the clear color, then draw the smaller black circles. Then when you finish the transparency layer, it will composite exactly what you want back onto the context.