美文网首页
滚动的贝塞尔曲线效果

滚动的贝塞尔曲线效果

作者: 海文_L | 来源:发表于2018-11-13 14:53 被阅读9次
动态效果

核心代码

- (void)drawRect:(CGRect)rect

{

    ref=UIGraphicsGetCurrentContext();

    t=t+0.02;

    CGFloatredColor[4]={1.0,1,1,1.0};

for(inti = 0; i 

        doubley1 = (480 / 2 - 10)*sin(2*M_PI*(1/width)*i*tem+t) +deviation;

        doubley2 = (480 / 2 - 10)*sin(2*M_PI*(1/width)*(width/ 2 + i *tem)+t) +deviation;

        doublex1 = i *tem;

        doublex2 = (width/ 2 + i *tem);

        CGContextBeginPath(ref);

        CGContextMoveToPoint(ref,x1, y1);

        CGContextSetAlpha(ref, 0.3);

        CGContextAddLineToPoint(ref, x2, y2);

        CGContextSetStrokeColor(ref, redColor);

        CGContextStrokePath(ref);

        [selfcircleX:x1Y:y1Rad:1];

    }

for(inti = 0; i 

        doubley1 = (480 / 2 - 10)*sin(2*M_PI*(1/width)*i*tem+t) +deviation;

        doubley2 = (480 / 2 - 10)*sin(2*M_PI*(1/width)*((i + 1) *tem)+t) +deviation;

        doublex1 = i *tem;

        doublex2 = (i + 1) *tem;

        [selfdrawLineWithX:x1Y:y1X2:x2Y2:y2];

    }

}

- (void)drawLineWithX:(float)x Y:(float)y X2:(float)x2 Y2:(float)y2

{

    CGContextBeginPath(ref);

    CGContextMoveToPoint(ref,x, y);

    CGContextAddLineToPoint(ref, x2, y2);

    CGContextStrokePath(ref);

}

- (void)circleX:(float)x Y:(float)y Rad:(float)rad

{    

    CGContextBeginPath(ref);

    CGContextAddArc(ref, x, y, rad, 0, 2 *M_PI, 0);

    CGContextSetRGBFillColor (ref, 1, 0, 0, 1.0);

    CGContextStrokePath(ref);

}

完整DEMO地址:https://github.com/havendev/FlowingBessel

相关文章

网友评论

      本文标题:滚动的贝塞尔曲线效果

      本文链接:https://www.haomeiwen.com/subject/itqlfqtx.html