核心代碼
- (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);
}