//
//  FunView.m
//  FunView
//
//  Created by Rich on 2/3/11.
//  Copyright 2011 Swarthmore College. All rights reserved.
//

#import "FunView.h"


@implementation FunView

@synthesize delegate;

- (id)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code.
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
	CGRect bounds = [self bounds];
	
	CGContextRef context = UIGraphicsGetCurrentContext();
	
	CGFloat border = 10.0;
	CGContextSetLineWidth(context, 2);
	
	[[UIColor redColor] setFill];
	
	CGContextBeginPath(context);
	
	//move to bottom left
	CGContextMoveToPoint(context, bounds.origin.x + border, 
						 bounds.origin.y + bounds.size.height - border);
	
	//draw across the bottom
	CGContextAddLineToPoint(context, bounds.origin.x + bounds.size.width - border, 
							bounds.origin.y + bounds.size.height - border);
	
	//draw up the appropriate amount
	float angle = [self.delegate angleForFunView:self];
	CGFloat height = tan(angle) * (bounds.size.width - 2 * border);
	CGContextAddLineToPoint(context, bounds.origin.x + bounds.size.width - border, 
							bounds.origin.y + bounds.size.height - height - border);

	//close off the triangle
	CGContextClosePath(context);
	
	//draw it
	CGContextStrokePath(context);

}

- (void)dealloc {
    [super dealloc];
}


@end
