iphone quartz draw border around line - iphone

what's the best way to draw a (black) border around a line in quartz for iphone? I'm drawing lines on streets on map and if the line is yellow (which is a legit use case), it blends in with the street color. One thing I could do is lay my lines over a little thicker black line, but this doesn't sound very efficient.

One thing I could do is lay my lines over a little thicker black line, but this doesn't sound very efficient.
I'd say that's the best way to go, unless you have hard proof about it being inefficient. I doubt that though. Stroking and filling a custom shape is probably harder to implement, and likely less efficient stroking one path twice with two different stroke widths (and colors).

Related

How can I make part of a mesh transparent?

Is it possible to make some % of my mesh transparent?
For example, imagine I have a mesh that is a house. At first the mesh is transparent. As a person clicks on the house, it becomes opaque along the Y-axis so it looks like it's being built up.
Any ideas how to approach this problem?
"a house. At first the mesh is transparent. As a person clicks on the house, it becomes opaque along the Y-axis so it looks like it's being built up"
Literally in answer to your question, in general:
I would approach this by making a shader which was sensitive to the global Y value of the point in question. It would use that value, over time, to decide on alpha at a given point.
alternately
Imagine a second texture of the house, call it GUIDE, which is: imagine a monochrome house: at the ground it is black and it slowly becomes pure white at the tops. Additionally you could color it any way you want, for example, the window frames and quoining could be black and so on. Now, the shader would use the GUIDE texture as a key, to know at what time, that area, should become transparent.
That would actually look quite incredible and offer amazing control. You could fade in different parts in whatever order you wish.
It would be beyond the scope of an answer here to actually engineer this. But I believe the key here is, unfortunately for what you describe that is really all done in the shader, I'd say.
Note that if you just want "a clean hole", look in to approaches using a depth mask shader And indeed https://www.youtube.com/watch?v=s3RKGAj9Uzk
for 2D consider this, http://answers.unity3d.com/questions/449034/see-through-hole-via-shaders-on-a-2d-plane.html
in other cases you may literally want to cut a sharp hole in the mesh which is a "whole" different technology. https://gamedev.stackexchange.com/questions/72978/shader-that-cuts-hole-through-all-geometry
if you want this effect http://answers.unity3d.com/questions/622089/how-can-i-render-a-semi-transparent-texture-with-a.html (see mario image) that's totally different again - it's nothing more than a gray image with a hole!

iOS Quartz 2D Graphics Filled Irregular Shapes Blurry

I'm drawing irregular shapes using Core Graphics on a retina display. I do this by creating a UIBezierPath with 5 to 10 random points. In drawRect I stroke the path and fill it using solid red colour.
My problem is that diagonal lines in my drawing doesn't appear to be sharp.
I have tried anti aliasing but if anything this makes it appear worse. I have experimented with different line widths, not stroking, not filling, but I can not seem to get a really sharp diagonal line.
For comparison I created a similar shape in Photoshop (using similar size) and saved that as PNG. If I display that PNG on iOS it looks much sharper.
What can I do to make my shape that I create in code look sharp?
Make sure your CGPoint's are rounded to the nearest integer value.

Inner Shadow Effect for line drawn to screen?

I've made an iOS program that allows the user to draw a line on the screen with their finger. I used the touchesBegan, touchesMoved, and touchesEnded methods, along with creating a CGContext and drawing my line that way. I want the line to look as though it is beveled into the screen, almost as if it was carved. How would this be possible?
You can achieve a simple bevel by stroking your lines three times:
first, with a color brighter than the background at points p(x-1, y-1) relative to the actual line
then, your line color at the actual line position, points p(x, y)
then, brighter than the line color, but darker than the background at p(x+1, y+1)
You can think of this as a light shining onto your lines from above and to the left, making the lower coordinates brighter, passing over the bevel and having a little shadow cast on the higher coordinates.
Once you get the hang of thinking through the pseudo-3D geometry this way, you can create prettier bevels, including details inside the line. Those will take more strokes.

iPhone - Should I composite two images at runtime, or pre-render them at the cost of memory

I am building a cocos2d iPhone game.
There will be 6 'enemy spaceship sprites' that vary only by colour. I.e. all the sprites will have the same shape only some parts of the interior will have different colours.
My two options are:
1)
Create a template shape with a transparent interior.
At runtime, draw this shape on top of a small block of colour X.
The interior of the sprite will be colour X.
2)
Pre-render 6 different sprites
At run time, simply draw the sprite of a given colour.
What is the advantages and disadvantages of each method? Is there a best practice?
If I later wanted to animate the sprites, or dynamically change their colours, would this effect my choice of method?
Thanks!
I think first you need to figure out what it is that you're trying to do... Animation or a large number of color combinations make pre-rendering unfeasible. On the other hand, pre-rendering makes sense if you have a large number of ships on-screen at the same time, because you can use this technique to cut the number of drawing operations in half.

Line smoothing in Cocoa Touch

How would I smooth a line (UIBeizerPath) or a set of points? Right now it draws it jagged. I read about spline interpolation, could anyone point me to an implementation of this in cocoa or C or give me an alternate line smoothing algorithm.
I don't think you need to do Bezier paths with curves. You can keep drawing straight line segments but add more data points with interpolation. This is especially important because I'm assuming you want to smooth only on one axis so you don't end up with odd things like loops in your graph.
So you want to add more points to your source data, between the existing points, and use an interpolation algorithm that's more sophisticated than a linear interpolation. There are many to choose from. Quadratic? Sine-based? Many, and it depends on what kind of data you're using.
Quartz (which UIKit uses for drawing, and in many places makes you use directly for drawing) has anti-aliasing support built-in. Most contexts have it turned on already, so you should not have aliased (jagged) drawing unless you're turning anti-aliasing off. So, stop doing that. :-)
The contexts that don't have it turned on by default are mostly those where it isn't appropriate, such as PDF contexts and CGLayer contexts. The documentation implies that those contexts don't even support anti-aliasing, which makes some amount of sense.
CGContext provides a couple of functions for turning anti-aliasing on and off, but you should never need to call them except when you want aliasing, which you don't. You could try turning it on using those functions; if that works, then you should investigate why it was ever off in the first place.
Are you drawing the path from within a CALayer? That may be why it's off; there's an Info.plist key you have to turn on to get anti-aliasing turned on by default in such contexts.
I've found that if you draw a line or an image on the edge of your frame that it will appear jagged. Move the line in a few (or grow your frame) and it should appear nice and crisp. Again, not sure if that's your question or not but it has bit me a few times.
For instance if you are displaying an image inside a CALayer, make sure there is space between the image and the frame if you are doing anything but 90 degree angles.