Skip to content

Commit

Permalink
粒子发射器修改
Browse files Browse the repository at this point in the history
  • Loading branch information
BigShow1949 committed Aug 26, 2016
1 parent e04ed71 commit ac2f6dc
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 48 deletions.
Binary file modified .svn/wc.db
Binary file not shown.
18 changes: 18 additions & 0 deletions BigShow1949.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
186E63641D6EE1BB0070A717 /* UINTViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 186E635C1D6EE1BB0070A717 /* UINTViewController.m */; };
186E63651D6EE1BB0070A717 /* UINTDraggableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 186E635D1D6EE1BB0070A717 /* UINTDraggableView.m */; };
186E63661D6EE1BB0070A717 /* UINTSpringAnimation.m in Sources */ = {isa = PBXBuildFile; fileRef = 186E63601D6EE1BB0070A717 /* UINTSpringAnimation.m */; };
186E636A1D6EED090070A717 /* YFStatisticalCodeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 186E63691D6EED090070A717 /* YFStatisticalCodeViewController.m */; };
186E636C1D701BD60070A717 /* rain.png in Resources */ = {isa = PBXBuildFile; fileRef = 186E636B1D701BD60070A717 /* rain.png */; };
189242651B99D065008AC1EB /* YFAuthorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 189242641B99D065008AC1EB /* YFAuthorViewController.m */; };
18C2D5331BAEDC98006CD3B2 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 18C2D5311BAEDC61006CD3B2 /* UIKit.framework */; };
18C2D5361BAEDCC8006CD3B2 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 18C2D5341BAEDCAC006CD3B2 /* Foundation.framework */; };
Expand Down Expand Up @@ -725,6 +727,9 @@
186E635F1D6EE1BB0070A717 /* UINTGeometryExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UINTGeometryExtras.h; sourceTree = "<group>"; };
186E63601D6EE1BB0070A717 /* UINTSpringAnimation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UINTSpringAnimation.m; sourceTree = "<group>"; };
186E63611D6EE1BB0070A717 /* UINTSpringAnimation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UINTSpringAnimation.h; sourceTree = "<group>"; };
186E63681D6EED090070A717 /* YFStatisticalCodeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YFStatisticalCodeViewController.h; sourceTree = "<group>"; };
186E63691D6EED090070A717 /* YFStatisticalCodeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YFStatisticalCodeViewController.m; sourceTree = "<group>"; };
186E636B1D701BD60070A717 /* rain.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = rain.png; sourceTree = "<group>"; };
189242631B99D065008AC1EB /* YFAuthorViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YFAuthorViewController.h; sourceTree = "<group>"; };
189242641B99D065008AC1EB /* YFAuthorViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YFAuthorViewController.m; sourceTree = "<group>"; };
18C2D5311BAEDC61006CD3B2 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -2077,6 +2082,15 @@
path = "弹簧效果(CADisplayLink)";
sourceTree = "<group>";
};
186E63671D6EEC780070A717 /* StatisticalCode */ = {
isa = PBXGroup;
children = (
186E63681D6EED090070A717 /* YFStatisticalCodeViewController.h */,
186E63691D6EED090070A717 /* YFStatisticalCodeViewController.m */,
);
path = StatisticalCode;
sourceTree = "<group>";
};
18C2D52F1BAEDC2C006CD3B2 /* Framework */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2203,6 +2217,7 @@
children = (
18CAD0301B95FD88001066FF /* YFKnowledgeViewController.h */,
18CAD0311B95FD88001066FF /* YFKnowledgeViewController.m */,
186E63671D6EEC780070A717 /* StatisticalCode */,
18D0A7F71D38B9000007B184 /* NotificationCenter */,
181F28921D2CEE1700FC2637 /* RunTime */,
B86B4A871CE1DAD900AD54AB /* GuideView */,
Expand Down Expand Up @@ -2421,6 +2436,7 @@
18CAD0D41B998D11001066FF /* RainCell */ = {
isa = PBXGroup;
children = (
186E636B1D701BD60070A717 /* rain.png */,
18CAD0D51B998F92001066FF /* YFEmitterRainCell.h */,
18CAD0D61B998F92001066FF /* YFEmitterRainCell.m */,
);
Expand Down Expand Up @@ -4412,6 +4428,7 @@
B891DA2F1CA0F8A0007F69AF /* photo_sample_04.png in Resources */,
B891DB071CA124DE007F69AF /* YFTagsCloudViewController.storyboard in Resources */,
B8729ECC1C9AA06700A18AA5 /* YFSlidingViewController.storyboard in Resources */,
186E636C1D701BD60070A717 /* rain.png in Resources */,
185C99191D67F0A500955C5F /* [email protected] in Resources */,
185C991B1D67F0A500955C5F /* [email protected] in Resources */,
B864C7CD1C995ED400D1E440 /* awcollectionviewdiallayout_2.jpg in Resources */,
Expand Down Expand Up @@ -4861,6 +4878,7 @@
B864C7A61C9945D500D1E440 /* SSStackedPageView.m in Sources */,
8BC4AD881B9682B00026B012 /* MJTypeEncoding.m in Sources */,
B891DABE1CA117CB007F69AF /* SKTag.m in Sources */,
186E636A1D6EED090070A717 /* YFStatisticalCodeViewController.m in Sources */,
B891DB4A1CA14661007F69AF /* YFMarqueeViewController.m in Sources */,
8BC4AD491B9681B70026B012 /* SDWebImageCompat.m in Sources */,
B852D51B1C51D60800454E7F /* CAAnimationGroupViewController.m in Sources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,12 @@ +(void)addSnowLayerInView:(UIView *)view

+(void)rainLayerInView:(UIView *)view atPosition:(CGPoint)position andDirection:(YFEmitterParticleCellDirection)direction andRadious:(CGFloat)radious andCellImg:(NSString *)cellImg
{
NSLog(@"调用了 - rainLayerInView");

//创建雪花所在图层layer
//创建雨点所在图层layer
YFEmitterCustomLayer *rainLayer=[self addCustomLayerInView:view atPosition:position inSize:CGSizeMake(view.frame.size.width, view.frame.size.height)];
rainLayer.emitterPosition = CGPointMake(320 / 2.0, -30);
rainLayer.emitterSize = CGSizeMake(320 * 2.0, 0);;
rainLayer.emitterSize = CGSizeMake(320 * 2.0, 0);

// Spawn points for the flakes are within on the outline of the line
rainLayer.emitterMode = kCAEmitterLayerOutline;
rainLayer.emitterMode = kCAEmitterLayerOutline;
rainLayer.emitterShape = kCAEmitterLayerLine;

rainLayer.shadowOpacity = 1.0;
Expand All @@ -115,7 +112,7 @@ +(void)rainLayerInView:(UIView *)view atPosition:(CGPoint)position andDirection:
rainLayer.seed = (arc4random()%100)+1;

//粒子
YFEmitterRainCell *emitterCell=[YFEmitterRainCell rainCellWithCellImg:cellImg andRadious:radious andVelocity:20 andDirection:direction];
YFEmitterRainCell *emitterCell = [YFEmitterRainCell rainCellWithCellImg:cellImg andRadious:radious andVelocity:20 andDirection:direction];

// emitterCell.contents = (id)[image CGImage];
emitterCell.color = [[UIColor colorWithRed:0.600 green:0.658 blue:0.743 alpha:1.000] CGColor];
Expand All @@ -126,14 +123,12 @@ +(void)rainLayerInView:(UIView *)view atPosition:(CGPoint)position andDirection:

+ (void)addRainLayerInView:(UIView *)view {

//树叶粒子所在view,发射树叶的位置,树叶飘向的方向,树叶粒子半径,树叶粒子图片
[YFEmitterCustomLayer rainLayerInView:view atPosition:CGPointMake(160,120) andDirection:YFEmitterParticleCellDirectionToBottom andRadious:19 andCellImg:nil];

// [YFEmitterCustomLayer rainLayerInView:view atPosition:CGPointMake(-60,-20) andDirection:YFEmitterParticleCellDirectionToBottom andRadious:9 andCellImg:nil];
//
// [YFEmitterCustomLayer rainLayerInView:view atPosition:CGPointMake(-60,view.frame.size.height*0.33) andDirection:YFEmitterParticleCellDirectionToBottom andRadious:14 andCellImg:nil];

[YFEmitterCustomLayer rainLayerInView:view atPosition:CGPointMake(-60,-20) andDirection:YFEmitterParticleCellDirectionToBottom andRadious:9 andCellImg:nil];

[YFEmitterCustomLayer rainLayerInView:view atPosition:CGPointMake(-60,view.frame.size.height*0.33) andDirection:YFEmitterParticleCellDirectionToBottom andRadious:14 andCellImg:nil];

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,58 +13,56 @@ @implementation YFEmitterRainCell
+(instancetype)rainCellWithCellImg:(NSString *)cellImg andRadious:(CGFloat)radious andVelocity:(CGFloat)velocity andDirection:(YFEmitterParticleCellDirection)direction
{

NSString * const leavesPic = @"leaves.png";//雪花图片样式
NSString * const rainPic = @"rain.png";// 这里没有雨水的默认图片

YFEmitterRainCell *cell=(YFEmitterRainCell *)[[self alloc] init];
cell.name = @"leaves";
cell.name = @"rain";
cell.birthRate = 40.0;
cell.lifetime = 120.0;

cell.velocity = 70; // falling down slowly
cell.velocityRange = 3;
cell.yAcceleration = 2;
cell.emissionRange = 0.5 * M_PI; // some variation in angle
cell.velocityRange = 3;
cell.yAcceleration = 2;
cell.emissionRange = 0.5 * M_PI; // some variation in angle
cell.spinRange = 0.25 * M_PI; // slow spin

//设置雪花图片
UIImage *img;
if (cellImg.length==0) {
img=[UIImage imageNamed:leavesPic];
img = [UIImage imageNamed:rainPic];
// UIColor *color = [UIColor colorWithRed:0.600 green:0.658 blue:0.743 alpha:1.000];
// img = [self imageWithColor:color];
}else{
img=[UIImage imageNamed:cellImg];
}
// 设置雪花半径大小
img=[UIImage image:img scaleToSize:CGSizeMake(radious, radious)];
// img=[UIImage image:img scaleToSize:CGSizeMake(radious, radious)];
img=[UIImage image:img scaleToSize:CGSizeMake(1, 50)];
cell.contents = (id)[img CGImage];

// //速率与半径大小正相关
// cell.velocity = radious*2;
//速率与半径大小正相关
cell.velocity = radious*2;

// //设置雪花飘向的方向
// switch (direction) {
// case YFEmitterParticleCellDirectionToLeft:
// //重力加速方向,y代表竖直,x为横向,数值越大,速度越快
// cell.xAcceleration=-1;
// //向周围发散的角度
// cell.emissionRange = -0.5* M_PI;
// break;
// case YFEmitterParticleCellDirectionToRight:
// cell.xAcceleration=1;
// cell.emissionRange = 0.25* M_PI;
// break;
// case YFEmitterParticleCellDirectionToTop:
// cell.yAcceleration=-1;
// cell.emissionRange = 0.5* M_PI;
// break;
// case YFEmitterParticleCellDirectionToBottom:
// cell.yAcceleration=1;
// cell.emissionRange = 0.5* M_PI;
// break;
// }
//重力加速方向,y代表竖直,x为横向,数值越大,速度越快
cell.yAcceleration = 4;
//向周围发散的角度
cell.emissionRange = 0.5* M_PI;


return cell;

}


+ (UIImage*)imageWithColor:(UIColor*)color {

CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
@end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ - (void)viewDidLoad {
self.title = @"飘浮的雪花";
self.view.backgroundColor = [UIColor lightGrayColor];

[[YFAnimationManager shareInstancetype] showAnimationInView:self.view withAnimationStyle:YFAnimationStyleOfSnow];
[[YFAnimationManager shareInstancetype] showAnimationInView:self.view withAnimationStyle:YFAnimationStyleOfSnow]; // 雨水有问题
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// YFStatisticalCodeViewController.h
// BigShow1949
//
// Created by apple on 16/8/25.
// Copyright © 2016年 BigShowCompany. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface YFStatisticalCodeViewController : UIViewController

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// YFStatisticalCodeViewController.m
// BigShow1949
//
// Created by apple on 16/8/25.
// Copyright © 2016年 BigShowCompany. All rights reserved.
//

#import "YFStatisticalCodeViewController.h"

@implementation YFStatisticalCodeViewController

- (void)viewDidLoad {

[super viewDidLoad];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ - (void)viewDidLoad {
@"响应者链条",
@"引导页",
@"运行时",
@"通知中心"];
@"通知中心",
@"统一代码行数"];

self.classNames = @[@"YFMasonryDemoViewController_UIStoryboard",
@"YFLifeCycleViewController",
@"YFResponderChainViewController",
@"YFGuideViewController",
@"YFRunTimeViewController",
@"YFNotificationCenterVC"];
@"YFNotificationCenterVC",
@"YFStatisticalCodeViewController"];
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ DBPoint DBPointMake(CGFloat x, CGFloat y, CGFloat z) {
return point;
}


#endif
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ - (void)setCloudTags:(NSArray *)array
tags = [NSMutableArray arrayWithArray:array];
coordinate = [[NSMutableArray alloc] initWithCapacity:0];

// 重置view的中心点,便于计算
for (NSInteger i = 0; i < tags.count; i ++) {
UIView *view = [tags objectAtIndex:i];
view.center = CGPointMake(self.frame.size.width / 2., self.frame.size.height / 2.);
}

CGFloat p1 = M_PI * (3 - sqrt(5));
CGFloat p2 = 2. / tags.count;

NSLog(@"p1:%f p2:%f", p1, p2);
for (NSInteger i = 0; i < tags.count; i ++) {

CGFloat y = i * p2 - 1 + (p2 / 2);
Expand All @@ -63,7 +64,7 @@ - (void)setCloudTags:(NSArray *)array
DBPoint point = DBPointMake(x, y, z);
NSValue *value = [NSValue value:&point withObjCType:@encode(DBPoint)];
[coordinate addObject:value];

NSLog(@"x:%f y:%f z:%f", point.x, point.y, point.z);
CGFloat time = (arc4random() % 10 + 10.) / 20.;
[UIView animateWithDuration:time delay:0. options:UIViewAnimationOptionCurveEaseOut animations:^{
[self setTagOfPoint:point andIndex:i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ - (void)viewDidLoad {
[sphereView addSubview:btn];
}
[sphereView setCloudTags:array];
sphereView.backgroundColor = [UIColor whiteColor];
sphereView.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:sphereView];

// Do any additional setup after loading the view, typically from a nib.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,19 @@ - (void)animationTick:(CFTimeInterval)dt finished:(BOOL *)finished
CGFloat time = (CGFloat) dt;

// friction force = velocity * friction constant
// 摩擦力 = 速度 * 摩擦系数
CGPoint frictionForce = CGPointMultiply(self.velocity, frictionConstant);
// spring force = (target point - current position) * spring constant
// 弹力= (目标位置 - 当前位置) * 弹簧劲度系数
CGPoint springForce = CGPointMultiply(CGPointSubtract(self.targetPoint, self.view.center), springConstant);
// force = spring force - friction force
// 力 = 弹力 - 摩擦力
CGPoint force = CGPointSubtract(springForce, frictionForce);
// velocity = current velocity + force * time / mass
// 速度 = 当前速度 + 力 * 时间 / 质量
self.velocity = CGPointAdd(self.velocity, CGPointMultiply(force, time));
// position = current position + velocity * time
// 位置 = 当前位置 + 速度 * 时间
self.view.center = CGPointAdd(self.view.center, CGPointMultiply(self.velocity, time));

CGFloat speed = CGPointLength(self.velocity);
Expand Down

0 comments on commit ac2f6dc

Please sign in to comment.