//
//  sampleView.m
//  sample
//
//  Created by ?? ?? on 05/06/15.
//  Copyright (c) 2005, __MyCompanyName__. All rights reserved.
//

#import "sampleView.h"


@implementation sampleView

- (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview
{
    self = [super initWithFrame:frame isPreview:isPreview];
    if (self) {
        [self setAnimationTimeInterval:5/30.0];
    }
    return self;
}

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

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

- (void)drawRect:(NSRect)rect
{
    [super drawRect:rect];
}


- (void)animateOneFrame
{

NSPoint point = NSMakePoint(SSRandomFloatBetween(0.0, [self frame].size.width), 
SSRandomFloatBetween(0.0, [self frame].size.height));//描く座標を決める


NSBezierPath *circle = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(point.y, point.x, 30, 30)];//円を描く
NSBezierPath *bpath = [NSBezierPath bezierPathWithRect:NSMakeRect(point.x, point.y, 30, 30)];//四角を描く
NSBezierPath *circle2 = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(point.x+point.y, point.x, 30, 30)];//円を描く
NSBezierPath *bpath2 = [NSBezierPath bezierPathWithRect:NSMakeRect(point.y, point.y+point.x, 30, 30)];//四角を描く


//色を作るための要素のパラメタを作成
float red = SSRandomFloatBetween(0.0, 1.0);
float blue = SSRandomFloatBetween(0.0, 1.0);
float green = SSRandomFloatBetween(0.0, 1.0);
float alpha = SSRandomFloatBetween(0.0, 1.0);
//先ほどのパラメタを利用して色を作る
NSColor* r_color = [NSColor colorWithCalibratedRed:red green:green blue:blue alpha:alpha];
//フェードアウトさせる
NSColor* fade_c = [NSColor colorWithCalibratedRed:0.0 green:0.0 blue:0.0 alpha:0.05];
NSRect fade_s = NSMakeRect(0, 0, [self frame].size.width, [self frame].size.height);


[r_color set];//色を設定
[circle2 fill];
[bpath2 fill];
[circle stroke];
[bpath stroke];
[fade_c set];
[NSBezierPath fillRect:fade_s];

    return;
}

- (BOOL)hasConfigureSheet
{
    return NO;
}

- (NSWindow*)configureSheet
{
    return nil;
}

@end
