Gold Challenge Solution


#1

I simply reused the fact that a line is really two points and the points could be used as the bounding box corners. So the coding was really minimal.
I also show the logic used for the colored lines based on the angle. I basically tried to map the angular space to the RGB space which is 255255255

- (void) drawRect:(CGRect)rect
{

    
    for (BNRLine *line in self.finishedLines)
    {

        float lineSlope = (line.end.y - line.begin.y)/(line.end.x - line.begin.x);
        float angle = atan(lineSlope);
        
        float colorVal = angle/M_PI * 255 * 255 * 255;

        float redVal = fabsf (fmodf (colorVal, 255) / 255);
        float greenVal = fabsf  (fmodf (colorVal/255, 255) / 255);
        float blueVal = fabsf (fmodf (colorVal/(255*255), 255) / 255);
        [[UIColor colorWithRed:redVal green:greenVal blue:blueVal alpha:1.0] set];
        
        UIBezierPath *bp = [UIBezierPath bezierPath];
        
        CGPoint circleCenter = CGPointMake((line.begin.x+line.end.x)/2, (line.begin.y+line.end.y)/2);
        int circleRadius = MAX(abs(line.begin.x - line.end.x), abs(line.end.y - line.end.y))/2;

        [bp addArcWithCenter:circleCenter radius:circleRadius startAngle:0.0 endAngle:2*M_PI clockwise:YES];
        [bp stroke];
        
        NSLog(@"lineSlope=%f, no radians= %f, angle=%f, color red = %f, blue = %f, green = %f", lineSlope, angle/M_PI, angle, redVal, blueVal, greenVal);
    }