Very similar to some of the answers of the topic I've seen.
I posted this, just because it has a nested function to calculate the angle, and that the return value only gives positive angles from 0 to 2 * pi...
Code:
override func drawRect(rect: CGRect) {
...
func angleOfLine(line: Line) -> CGFloat {
let xdiff = Double(line.begin.x - line.end.x)
let ydiff = Double(line.begin.y - line.end.y)
let result = CGFloat(atan2(xdiff, ydiff))
return result >= 0 ? result : 2 * CGFloat(M_PI) + result
}
for (_, line) in currentLines {
let cgfloat2pi = CGFloat(2 * M_PI)
let angle = angleOfLine(line)
let hue = angle / cgfloat2pi
currentLineColor = UIColor(hue: hue, saturation: 1, brightness: 1, alpha: 1)
currentLineColor.setStroke()
strokeLine(line)
}
}
Statistics: Posted by gotfried — Mon May 09, 2016 4:21 pm