I made a button to match the style of the rest of my application, however it's too bulky. I tried a few things, but this is as small as I've been able to get it.
class ButtonPath {
private let wiggle: Int = 3
func points(height: Int) ->
((Int,Int),(Int,Int),(Int,Int),
(Int,Int),(Int,Int),(Int,Int),
(Int,Int),(Int,Int),(Int,Int),
(Int,Int),(Int,Int),(Int,Int))
{
func rand() -> Int { Int.random(in: -wiggle...wiggle) }
func r2(x: Int) -> Int { Int.random(in: -x...x) }
let screen: CGRect = UIScreen.main.bounds
let widthMx = CGFloat(0.9)
let origin = (x:15, y:15)
let width = Int(screen.width * widthMx)
// Corner points
let tl = (x: origin.x + rand(), y: origin.x + rand()) // tl = Top Left, etc.
let tr = (x: origin.x + width + rand(), y: origin.y + rand())
let bl = (x: origin.x + rand(), y: origin.y + height + rand())
let br = (x: origin.x + width + rand(), y: origin.y + height + rand())
// Arc controls, we're drawing a rectangle counter-clockwise from the top left
let a1c1 = (x: origin.x + rand(), y: Int(Double(origin.y+height+rand()) * 0.3)) // a1c1 = Arc 1 Control 1
let a1c2 = (x: origin.x + rand(), y: Int(Double(origin.y+height+rand()) * 0.6))
let a2c1 = (x: Int(Double(origin.x+width+rand()) * 0.3), y: origin.y + height + rand())
let a2c2 = (x: Int(Double(origin.x+width+rand()) * 0.6), y: origin.y + height + rand())
let a3c1 = (x: origin.x + width + rand(), y: Int(Double(origin.y + height+rand()) * 0.6))
let a3c2 = (x: origin.x + width + rand(), y: Int(Double(origin.y + height+rand()) * 0.3))
let a4c1 = (x: Int(Double(origin.x+width+rand()) * 0.6), y: origin.y + rand())
let a4c2 = (x: Int(Double(origin.x+width+rand()) * 0.6), y: origin.y + rand())
return (
t1: tl, tr: tr, b1: bl, br: br,
a1c1: a1c1, a1c2: a1c2, a2c1: a2c1,
a2c2:a2c2, a3c1:a3c1, a3c2:a3c2, a4c1:a4c1, a4c2:a4c2
)
}
func path (height:Int) -> Path {
let (tl, tr, bl, br, a1c1, a1c2, a2c1, a2c2, a3c1, a3c2, a4c1, a4c2) = points(height: height)
return Path { path in
path.move( to: CGPoint(x: tl.0, y: tl.1) )
path.addCurve( to: CGPoint(x: bl.0, y: bl.1), control1: CGPoint(x: a1c1.0, y: a1c1.1), control2: CGPoint(x: a1c2.0, y: a1c2.1))
path.addCurve( to: CGPoint(x: br.0, y: br.1), control1: CGPoint(x: a2c1.0, y: a2c1.1), control2: CGPoint(x: a2c2.0, y: a2c2.1))
path.addCurve( to: CGPoint(x: tr.0, y: tr.1), control1: CGPoint(x: a3c1.0, y: a3c1.1), control2: CGPoint(x: a3c2.0, y: a3c2.1))
path.addCurve( to: CGPoint(x: tl.0-2, y: tl.1), control1: CGPoint(x: a4c1.0, y: a4c1.1), control2: CGPoint(x: a4c2.0, y: a4c2.1))
}
}
}
Is there a function I could write to output the value of the corners, arcs, paths, etc?