Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Demonstration of using Core Graphics to draw a sine wave at an arbitrary frequency
[[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);
CGContextAddLineToPoint(context, x, y);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment