views:

582

answers:

4

I want to be able to draw using this as my stroke. How would I do this as efficient as possible, and on the fly drawing, I was thinking CGPatternRef, but I really don't know how to do that.

Edit: It does not need to warp to the path. I just coultn't fix that issue in Illustrator. alt text

A: 

This looks like a job for OpenGL. CoreGraphics doesn't offer any simple way that I know of to warp the stars according to their proximity to a path.

NSResponder
I don't need to warp the stars to the path I draw.
Jaba
+1  A: 

You could try importing your Illustrator document into this application: Opacity, and then doing an "Export as source code".

See here: http://likethought.com/opacity/workflow/ for more information.

Alan Rogers
+2  A: 
Pestilence
+1  A: 

Does the Apple doc help?

See the section in Quartz 2D Programming Guide, How Patterns Work, or Patterns in general.

Here is how to draw a start (from the above docs), PSIZE is the star size:

static void MyDrawStencilStar (void *info, CGContextRef myContext)
{
    int k;
    double r, theta;

    r = 0.8 * PSIZE / 2;
    theta = 2 * M_PI * (2.0 / 5.0); // 144 degrees

    CGContextTranslateCTM (myContext, PSIZE/2, PSIZE/2);

    CGContextMoveToPoint(myContext, 0, r);
    for (k = 1; k < 5; k++) {
        CGContextAddLineToPoint (myContext,
                    r * sin(k * theta),
                    r * cos(k * theta));
    }
    CGContextClosePath(myContext);
    CGContextFillPath(myContext);
}

Just add the curve transformation and at each point draw the star.

Here is a simple C code to calculate points on cubic bezier curve.

stefanB
I think Pestilence is right, I tried stroking with pattern but that uses the pattern as wallpaper, e.g. it works nicely stroking rectangle but when stroking curve it does not put the stars in the middle of stroke, it just tiles the stars within the stroke so you get bits and pieces of stars - as if you draw regular pattern on the wall and then cut out a curve, the stars don't fit nicely in the curve ...
stefanB