public
Last active

Demonstration of using Core Graphics to draw a sine wave at an arbitrary frequency

  • Download Gist
SPPlotView.m
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
[[UIColor colorWithRed:0 green:192/255.0 blue:255/255.0 alpha:1] set];
 
CGContextSetLineWidth(context, 1);
CGContextSetLineJoin(context, kCGLineJoinRound);
 
const CGFloat amplitude = halfHeight / 4;
for(CGFloat x = 0; x < width; x += 0.5)
{
CGFloat y = amplitude * sinf(2 * M_PI * (x / width) * frequency) + halfHeight;
 
if(x == 0)
CGContextMoveToPoint(context, x, y);
else
CGContextAddLineToPoint(context, x, y);
}
 
CGContextStrokePath(context);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.