代码之家  ›  专栏  ›  技术社区  ›  Jab

我如何在核心图形中绘制类似的内容

  •  6
  • Jab  · 技术社区  · 14 年前

    我想用这个作为我的笔划来画画。我如何才能尽可能高效地完成这项工作,在动态绘图时,我在考虑CGPatternRef,但我真的不知道如何做到这一点。

    编辑: alt text

    4 回复  |  直到 14 年前
        1
  •  2
  •   Alan Rogers    14 年前

    您可以尝试将Illustrator文档导入此应用程序: Opacity ,然后执行“导出为源代码”。

    http://likethought.com/opacity/workflow/ 更多信息。

        2
  •  4
  •   stefanB    14 年前

    请参阅中的部分 Quartz 2D Programming Guide, How Patterns Work ,或一般的模式。

    这里是如何绘制一个开始(从上面的文档),PSIZE是星星的大小:

    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);
    }
    

    只需添加曲线变换,并在每个点绘制星形。

    simple C code to calculate points on cubic bezier curve .

        3
  •  2
  •   pestilence669    14 年前

    bézier curve 问题只需求解曲线方程,并在每个顶点渲染一颗星星。

    没有什么内在的东西可以做到这一切。可以查询交点,但只有渲染才能解决曲线。这是由CoreGraphics封装的,因此您无法将其拉出或利用他们已有的功能。

        4
  •  0
  •   NSResponder    14 年前

    这看起来像是OpenGL的工作。CoreGraphics并没有提供我所知的任何简单方法,根据恒星与路径的接近程度来扭曲恒星。