Silver Challenge Solution


Below is my simplistic solution to this challenge. I only modify the drawRect method of BNRDrawView.

Essentially I use math learned on the internet to get something approaching the angle of the line. In order to use colorWithHue you have to select a number between 0-1. The math from there is my embarrassing attempt to generally convert the angle to a number between 0-1…

    for (BNRLine *line in self.finishedLines)
        float xDiff = line.end.x - line.begin.x;
        float yDiff = line.end.y - line.begin.y;
        float angle = fabs(atan2(yDiff,xDiff) * (180 / M_PI));
        float colorSet = fabs((angle-100.0)/100.0);
        [[UIColor colorWithHue:colorSet saturation:1.0 brightness:1.0 alpha:1.0]set];
        [self strokeLine:line];
    [[UIColor redColor]set];
    for (NSValue *key in self.linesInProgress)
        [self strokeLine:self.linesInProgress[key]];