Skip to content

Instantly share code, notes, and snippets.

@H2CO3
Last active August 29, 2015 14:23
Show Gist options
  • Save H2CO3/436d756506ac1cfae8b4 to your computer and use it in GitHub Desktop.
Save H2CO3/436d756506ac1cfae8b4 to your computer and use it in GitHub Desktop.
function drawShape(ctx, xoff, yoff) {
ctx.beginPath();
ctx.moveTo(206 + xoff, 86 + yoff);
ctx.bezierCurveTo(263 + xoff, 33 + yoff, 381 + xoff, 65 + yoff, 348 + xoff, 160 + yoff);
ctx.bezierCurveTo(328 + xoff, 218 + yoff, 251 + xoff, 194 + yoff, 206 + xoff, 279 + yoff);
ctx.bezierCurveTo(161 + xoff, 194 + yoff, 84 + xoff, 218 + yoff, 64 + xoff, 160 + yoff);
ctx.bezierCurveTo(31 + xoff, 65 + yoff, 149 + xoff, 33 + yoff, 206 + xoff, 86 + yoff);
ctx.stroke();
}
import UIKit
UIGraphicsBeginImageContext(CGSize(width: 450, height: 300))
UIColor.whiteColor().setFill()
UIBezierPath(rect: CGRectMake(0, 0, 450, 300)).fill()
// ennek a valtozonak az allitasaval tudod valtoztatni a kitoltes merteket
let ratio = 0.5 as CGFloat
var bp = UIBezierPath()
bp.moveToPoint(CGPoint(x: 206, y: 86))
// jobb oldal
bp.addCurveToPoint(CGPoint(x: 348, y: 160), controlPoint1: CGPoint(x: 263, y: 33), controlPoint2: CGPoint(x: 381, y: 65))
bp.addCurveToPoint(CGPoint(x: 206, y: 279), controlPoint1: CGPoint(x: 328, y: 218), controlPoint2: CGPoint(x: 251, y: 194))
// bal oldal
bp.addCurveToPoint(CGPoint(x: 64, y: 160), controlPoint1: CGPoint(x: 161, y: 194), controlPoint2: CGPoint(x: 84, y: 218))
bp.addCurveToPoint(CGPoint(x: 206, y: 86), controlPoint1: CGPoint(x: 31, y: 65), controlPoint2: CGPoint(x: 149, y: 33))
var bp_filled = bp.copy() as UIBezierPath
UIColor.redColor().setFill()
bp_filled.fill()
UIColor.whiteColor().setFill()
UIBezierPath(rect: CGRectMake(0, 0, 450, 300.0 * ratio)).fill()
UIColor.blueColor().setStroke()
bp.lineWidth = 2
bp.stroke()
let img = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment