// // sample2View.m // sample2 // // Created by ?? ?? on 05/06/18. // Copyright (c) 2005, __MyCompanyName__. All rights reserved. // #import "sample2View.h" @implementation sample2View - (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview { self = [super initWithFrame:frame isPreview:isPreview]; if (self) { [self setAnimationTimeInterval:2/30.0]; } return self; } - (void)startAnimation { [super startAnimation]; } - (void)stopAnimation { [super stopAnimation]; } - (void)drawRect:(NSRect)rect { [super drawRect:rect]; } - (NSPoint)rand_point//ランダムなポイントを返す { int width = [self frame].size.width; int height = [self frame].size.height; NSPoint point = NSMakePoint(SSRandomFloatBetween(0.0, width),SSRandomFloatBetween(0.0, height));//ランダム座標 return point; } - (NSColor*)rand_color//ランダムなカラーを作成 { 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];//先ほどのパラメタを使用して色を作る return r_color; } - (NSBezierPath*)makePoly:(NSPoint)pt polynum:(int)num angle:(int)ang r:(float)r { int i; if(num==0){ num=SSRandomIntBetween(3, 8); } if(r==0.0){ r=SSRandomFloatBetween(10, 64); } NSBezierPath* bezierPath = [NSBezierPath bezierPath]; ang+=90; for(i = 0; i <= num; i++) { NSPoint tmpPoint = pt; tmpPoint.x += r * cos(2 * M_PI * (i / (float)num)-(M_PI_2/90.0)*ang);//floatで割らないとずっと0になってしまう。 tmpPoint.y += r * sin(2 * M_PI * (i / (float)num)-(M_PI_2/90.0)*ang);//0以下の桁が四捨五入される、切り捨てかも。 if(i == 0) { [bezierPath moveToPoint:tmpPoint]; } else { [bezierPath lineToPoint:tmpPoint]; } } [bezierPath closePath];//始点と終点を繋ぐ。 return bezierPath; } - (void)animateOneFrame { //フェードアウトさせる 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); [[self rand_color] set]; [ [self makePoly: [self rand_point] polynum:0 angle:0 r:0] stroke]; [fade_c set]; [NSBezierPath fillRect:fade_s]; return; } - (BOOL)hasConfigureSheet { return NO; } - (NSWindow*)configureSheet { return nil; } @end