Creating ellipses with the Chipmunk Physics Engine - iphone

I need to create an ellipse with a width of 52 pixels and a height of 47 pixels. Using the Chipmunk engine, I've found that you can create circles with a certain radius, as well as polygons. I'm new to working with Chipmunk, and the documentation for the engine is quite brief.
How do I create ellipses in Chipmunk? I'm currently working with iPhones, using Objective-c and cocos2d.
I know it may seem useless to go in these details but I need to create it as precise as possible.
Thank you!

The recommendation from Chipmunk's author, slembcke, seems to be “approximate it using a polygon”. See this forum post.
If a polygon approximation isn't good enough, you will have to modify Chipmunk to add a new ellipse shape type, because it doesn't have support for ellipses. And adding support for ellipses is probably a significant amount of work.

You can also use PhysicsEditor to design any shape.
If you already have an image of an ellipse, then you can use that image to allow PhysicsEditor to trace the borders of the image. Either way this is a lot easier than actually programming the shape.

Related

Get bounds of PKDrawing / individual strokes in PencilKit

I need access to the coordinates of individual strokes of a PKDrawing in PencilKit. Is there any way I can get access to that? Currently, my only idea is to try and decode the opaque data representation we get from PKDrawing.
As Ben has said, there doesn't seem to be any way to access stroke-level data in PencilKit at this time. This seems like a pretty rudimentary feature so hopefully Apple will add it next WWDC. Fingers crossed.
LetsBuildThatApp's YouTube tutorial is a good starting point if you just want basic drawing capabilities and are not too concerned about drawing quality or latency. I ran into issues when I tried to add the ability to vary the stroke width with pen pressure. I was never able to get it to transition smoothly between stroke segments of different widths - it always 'jumped' jarringly from one width to the next. Maybe there's a way to fix that, but I wasn't able to.
I suspect that currently, the only way to draw low-latency high-quality images with Apple Pencil is to write a drawing engine from scratch in Metal or OpenCL. It's strange it has taken Apple so long since the release of Apple Pencil to get a comprehensive drawing framework out. Fingers crossed that changes at WWDC 2020.
Edit: Apple announced substantial updates to PencilKit at WWDC20, including access to stroke data and functions to programatically draw strokes.
I was was looking for the same thing and from this comment https://stackoverflow.com/a/57565661/8891611 and my own searching of the documentation, it seems what you're asking for doesn't exist. If you do discover a way to decode the opaque data please update this thread on how so.
If you aren't necessarily set on PencilKit, you could manually code your drawing functions which is easier than it sounds. In this tutorial: https://youtu.be/E2NTCmEsdSE?t=504 I have timestamped where he shows that he has access to all the points on the lines he is creating.
And another potential solution could be to use both, by have a mapping between your PencilKit drawing and the points found from the technique in this tutorial.
For the strokes, you can access the property .renderBounds that gives you the dimensions of the rectangle where the stroke is into.

How to draw number into circle shape?

I am trying to draw the numbers into circle shape.
But I did not succeed. I have tried some tutorials which are available but could not succeed.
We haven't fixed the numbers to show in circle. Numbers are dynamic.
I am attaching snapshot below so that I could clear what I am really trying to do.
Help would be appreciated.
You could use David's suggestion of placing labels by translating and rotating them. That would be easiest, but would involve a fair amount of overhead.
Alternatively you could use CoreText to draw your text along a CGPath that's a circle. Erica Sadun's excellent "iOS Developer Cookbook" series includes a recipe that shows how to wrap text along a curved path using Core Text. I don't remember which volume it's in however.
A third option would be to use Nick Lockwood's excellent iCarousel framework to create a circular carousel out of the numbers you're using. It is very flexible and you should be able to adjust the settings to get a look very similar to the control you've posted.

Shape recognition (recognizes hand drawn basic shapes - rectangles, ellipses, triangles etc.)?

I want to detect hand drawn basic shapes - rectangles, ellipses, triangles etc.
Does anybody have an idea how to implement this?
Maybe you can try the OpenCV library. Actually this library has the focus of computer vision, i.e. analyzing pixeldata of images and video and might be too heavy for your task. But on the other hand it is very powerfull and available on many plattforms (even on iOS). And a hand drawn image with shapes is also just a set of pixels, isn't it ;-)
You might have a look at the manual:
http://www.sciweavers.org/books/opencv-open-source-computer-vision-reference-manual
There is plenty of information about OpenCV here on stackoverflow as well. Some hints on stackoverflow are here:
DETECT the Edge of a Document in iPhoneSDK
and here
iPhone and OpenCV

Dynamically create sprite images for Cocos2d-iPhone

I'm working on a platformer, and looking for a way to create a sprite for an arbitrarily sized platform. For example, I may know I have a platform that should appear 200 pixels wide by 32 pixels high, and, say, I have a texture of bricks that I can tile to fill that area. I may also want to draw a black border around the platform. Is this possible at all? Anyone have any ideas for how I might go about doing this? I could always try generating the image on the fly and building a sprite with that image, but I sincerely doubt (hope) that this isn't the most efficient way of doing something like this.
Cheers,
Alex
You can use tiled maps for the platform. It will require you to plan your textures a bit differently, but it will probably yield better results.
You can read more about tiled maps here.

Can this type of wiggle image deformation be done on iPhone without using openGL

I have a straight image and I want to deform it in a wave-like manner.
Original image:
straight texture http://img145.imageshack.us/img145/107/woodstraight.png
and I want it to look like this (except animated):
bent texture http://img145.imageshack.us/img145/8496/woodbent.png
I haven't tackled the learning curve of openGL yet so if I can do this with Core Animation it would be great.
Is this possible?
Unfortunately, I think this is a job for OpenGL. You could achieve the same affect in Quartz by slicing the image up vertically and drawing segments with different vertical offsets... but I don't think you'd be able to achieve good enough performance to animate it. (At least, with 1px or 2px wide slices)
You could also leave the image stationary, and use Quartz to animate a masking path that would create the waving edges. That probably wouldn't look too natural, though.
As far as I know, Core Animation on the iPhone isn't capable of doing this, either. On the Mac it comes with some more advanced filters, but I think you'd probably see a lot more stuff like this if the iPhone filters could do it :-)
OpenGL does have quite a learning curve, but here's what you'd want to do to achieve the effect: Create a flat rectangle in OpenGL with several verticies along it's length. Point the camera at the rectangle so that it appears flat. Then, use a sine() function of some sort to animate the verticies back and forth in place.
This approach is also used to achieve the rippling-water effect, and you might be able find an example or two of it.
Sorry to bring bad news :-) Hope that helps!