I have implemented game application in which i want to draw line between two object.I have drawn line between two objects.But i want to draw with animation.can u advise me which animation i have to used between two points.
Edit:My excatly question is that:
Suppose there is two point like start point(100,100) and endpoint(300,300).I can draw line between this two point but i want to draw line with animation.I mean i can see line start from start point to end point with 2 secon duration.please help me about this question.
+1 for Brad's answer—it'll work—but it looks like you can accomplish the same thing in a more straightforward fashion by animating the strokeStart and strokeEnd properties on CAPathLayer.
See http://oleb.net/blog/2010/12/animating-drawing-of-cgpath-with-cashapelayer/
If you're looking to animate the extension of a line from point A to between points A and B, my recommendation would be to use a CAShapeLayer for this. CAShapeLayer lets you animate the interpolation between two paths with the same number of control points. For an example of this in action, see Joe Ricioppo's post on the subject.
In your case, you'd start with a path that has two control points, both the same point, and use as the final path one that has a control point at the start of the line and one at the end. The line will then animate out as if it were being drawn in a single brush stroke.
Related
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/
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.
When I'm using a UIBezierPath to draw where the user is touching if the user moves to fast sometimes I get really hard points like the tip of a triangle. Any clue what might be causing this? Or how I can fix it?
I am capturing the points using touchesBegan/Moved/Ended and placing them into an NSArray of UIBezierPaths.
Despite the name, UIBezierPath doesn't just draw curves. In fact, by default it won't - presumably you're simply passing the coordinates returned by touchesBegan etc, into the addLineToPoint method.
Instead of simply passing all the touch coordinates directly into a UIBezierPath you should first interpolate them to avoid these sharp lines that occur when you rapidly move your finger across the screen. This is not too difficult, although does require some knowledge of how bezier curves work and spline interpolation.
If you are looking for a slightly easier way out, there are a couple of open source libraries that will do this for you, like this one: http://cocoacontrols.com/platforms/ios/controls/smooth-line-view
I'm trying to implement "hand draw tool".
At the moment algorythm looks like that (I don't insert any code because methods are quite big, will try to explain an idea):
Drawing
In touchesStarted: method I create NSMutableArray *pointsArray and add point into it. Call setNeedsDisplay: method.
In touchesMoved: method I calculate points between last added point from the pointsArray and current point. Add all points to the pointsArray. Call setNeedsDisplay: method.
In touchesFinished: event I calculate points between last added point from the array and current point. Set flag touchesWereFinished. Call setNeedsDisplay:.
Render:
drawRect: method checks is pointsArray != nil and is there any data in it. If there is - it starts to traw circles in each point of this array. If flag touchesWereFinished is set - save current context to the UIImage, release pointsArray, set it to nil and reset the flag.
There are a lot disadvantages of this method:
It is slow
It becomes extremely slow when user touches and move finger for long time. Array becomes enormous
"Lines" composed by circles are ugly
I would like to change my algorithm to make it bit faster and line smoother.
In result I would like to have lines like on the picture at following URL (sorry, not enough reputation to insert an image): http://2.bp.blogspot.com/_r5VzEAUYXJ4/SrOYp8tJCPI/AAAAAAAAAMw/ZwDKXiHlhV0/s320/SketchBook+Mobile(4).png
Can you advice me, ho I can draw lines this way (smooth and slim on the edges)? I thought to draw circles with alpha gradient on the edges (to make lines smoother), but it will be extremely slowly IMHO.
Thanks for help
Update
I changed draw algorithm. Now every event I save UITouch and in the drawRect: method I draw path from prev. point to the current one. And dump UIImage from context every drawRect: invocation.
But I still have 2 questions:
Is it possible to draw more smooth. I mean if I draw quite fast, I easily can see that path path is a set of straight lines. But I want to draw curves, to make path smooth. Probably Bezier curves will help but I don't understand how they can help in this.
situation.
I want to start path with thiner line and finish with thiner line too. How I can do this line transform?
Thanks!
I have a NSArray of points that make up a path. I can detect when it self-intersects. When this happens, I try to fill the path.
First I used CoreGraphics, now I'm using openGl to draw a triangle array. Doesn't work well as you can see in the image.
How do I fill only the circular area while leaving the "tail" alone? I was thinking of a reverse flood fill but don't think CG has any API functions for this...
Maybe instead of actually drawing the path you can just approximate the diameter of the path and draw a circle with your approximation.
Here is some code to detect a circle gesture on the iPhone:
http://www.mobileorchard.com/iphone-circle-gesture-detection/
Record all of the points in a doubly-linked list. When it comes time to fill, walk the list from the start and find the point that's closest to the end. Then, lineto that point, then lineto each point in reverse order, stopping with the second point in the list. The fill will implicitly close the path, which will jump from where you left off (the second point) back to the start (first) point.
This is just off the top of my head; you can play with a couple of variations on this to see what works best. You might record the closest previous node in each node, but this could get expensive for many nodes.