CGContext drawing all objects with the color of the last object
===

I have the following problem: I have two touch sensors giving me coordinates that I want to draw on screen. Each sensor should draw with a different color - red or blue. This works, however, in case a number of gestures are done one after the other on the same sensor I want them do be drawn with a different nuance of blue reps. red. My code follows below but the problem is that for a given sensor all gestures are drawn with the same color and I believe it's the one of the last gesture.


- (void)drawRect:(NSRect)dirtyRect
{
    // Drawing code here.
   
    ILFTPAppDelegate *appDelegate = (ILFTPAppDelegate *)[[NSApplication sharedApplication] delegate];
    
    for (NSDictionary *dict in appDelegate.separatedGestureArray) {
        
        CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
        CGContextSetLineWidth(context, 3.0f);
        
        if ([dict objectForKey:@"rightGesture"]) {
            
            TouchLocation *starttl = [[dict objectForKey:@"rightGesture"] objectAtIndex:0];
                        
            float color = (arc4random() % 100) / 100.0;
            CGContextSetRGBStrokeColor(context, 0.0f, 0.0f, color, 1.0f);
            NSLog(@"%f", color);
            
            CGContextBeginPath(context);
            
            CGContextMoveToPoint(context, (100 - starttl.Xcoord) * 8, starttl.Ycoord * 8);
            
            BOOL shouldMove = YES;
            
            for (TouchLocation *tl in [[dict objectForKey:@"rightGesture"] subarrayWithRange:NSMakeRange(10, [[dict objectForKey:@"rightGesture"] count] - 20)]) {
                if (tl.TNT == 1.0) {
                    if (shouldMove) {
                        //current gesture continuing
                        CGContextMoveToPoint(context, (100 - tl.Xcoord) * 8, tl.Ycoord * 8);
                    } else {
                        //current gesture continuing
                        CGContextAddLineToPoint(context, (100 - tl.Xcoord) * 8, tl.Ycoord * 8);
                    }
                    shouldMove = NO;
                } else {
                    CGContextMoveToPoint(context, (100 - tl.Xcoord) * 8, tl.Ycoord * 8);
                    shouldMove = YES;
                }
            }
            CGContextStrokePath(context);
            CGContextFlush(context);
            
        } else if ([dict objectForKey:@"leftGesture"]) {
            
            TouchLocation *starttl = [[dict objectForKey:@"leftGesture"] objectAtIndex:0];
            
            float color = (arc4random() % 100) / 100.0;
            CGContextSetRGBStrokeColor(context, 0.0f, color, 0.0f, 1.0f);
            
            CGContextBeginPath(context);
            
            CGContextMoveToPoint(context, (100 - starttl.Xcoord) * 8, starttl.Ycoord * 8);
            
            BOOL shouldMove = YES;
            
            for (TouchLocation *tl in [[dict objectForKey:@"leftGesture"] subarrayWithRange:NSMakeRange(4, [[dict objectForKey:@"leftGesture"] count] - 15)]) {
                if (tl.TNT == 1.0) {
                    if (shouldMove) {
                        //current gesture continuing
                        CGContextMoveToPoint(context, (100 - tl.Xcoord) * 8, tl.Ycoord * 8);
                    } else {
                        //current gesture continuing
                        CGContextAddLineToPoint(context, (100 - tl.Xcoord) * 8, tl.Ycoord * 8);
                    }
                    shouldMove = NO;
                } else {
                    CGContextMoveToPoint(context, (100 - tl.Xcoord) * 8, tl.Ycoord * 8);
                    shouldMove = YES;
                }
            }
            CGContextStrokePath(context);
        }
    }
}

My gestures are arrays of touch objects, each gesture is put in a dictionary with key pointing to one sensor or the other and all such dictionaries are put in one array in app delegate.

Please help :)