June 2009

Quartz 2Dのテストプログラム


- source by Xcode


- drawRect:実装部 :

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextBeginPath(context);
    CGContextAddRect(context, CGRectMake(0, 0, 500, 500));
    float bg=(white)?1:0;
    CGContextSetRGBFillColor(context,bg, bg,  bg ,1);
    CGContextDrawPath(context, kCGPathFill);
    CGContextSetBlendMode(context, blendMode);
    for(int i=0;i<totalCount;i++){       
        Line *line=(Line *)[lines objectAtIndex:i];
        [line update];
        CGContextMoveToPoint(context, centerX,centerY);
        float brightness=grayscale?1:1;
        float saturation=grayscale?0:1;
        float hue=(float)i/totalCount*0.2+colorFlag;
        if(white)brightness=grayscale?0:1;
        UIColor *color=[UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
        CGContextSetStrokeColorWithColor(context, color.CGColor);
        CGContextSetLineWidth(context, [line getWeight]/8+0.1);
        CGContextAddCurveToPoint(context, line.c1.x, line.c1.y, line.c2.x, line.c2.y, line.c3.x, line.c3.y);
        CGContextDrawPath(context, kCGPathStroke);
    }