椭圆运动

来源:互联网 发布:java mvc模式的理解 编辑:程序博客网 时间:2024/04/29 12:37
////  YGJViewController.m//#define         PX              160#define         PY              240#define         TUOYUAN_A       100#define         TUOYUAN_B       100#define         TUOYUAN_A1       50#define         TUOYUAN_B1       50#define         JIAODU_2_HUDU(x)   (x)/180.0*M_PI)#define ZIZHUANJIAODU_2_HUDU    _angel1/180.0*M_PI#import "YGJViewController.h"#import "YGJTianQiViewController.h"#import "YGJAppDelegate.h"@interface YGJViewController (){    int _angel;    NSTimer *_timer;    int _count;}@property (weak, nonatomic) IBOutlet UIButton *btn1;@property (weak, nonatomic) IBOutlet UIButton *btn2;@property (weak, nonatomic) IBOutlet UIButton *btn3;@property (weak, nonatomic) IBOutlet UIButton *btn4;@end@implementation YGJViewController- (void)viewDidLoad{    [super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.}- (IBAction)btn1Click:(id)sender {    YGJTianQiViewController *vc=[[YGJTianQiViewController alloc]init];    YGJAppDelegate *app=[UIApplication sharedApplication].delegate;    UIWindow *window=app.window;    window.rootViewController=vc;            _timer=[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(gongZhuan) userInfo:nil repeats:YES];            }- (IBAction)btn2Click:(id)sender {        _timer=[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(gongZhuan) userInfo:nil repeats:YES];       }- (IBAction)btn3Click:(id)sender {       _timer=[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(gongZhuan) userInfo:nil repeats:YES];  }- (IBAction)btn4Click:(id)sender {     _timer=[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(gongZhuan) userInfo:nil repeats:YES];       }- (IBAction)yuanZhouyunDong:(id)sender {        }-(void)gongZhuan{    /*

          椭圆的标准方程:x^2/a^2 + y^2/b^2 = 1

*/

_angel++; if (_angel%90==0) { [_timer invalidate]; } float x=PX + TUOYUAN_A*cos(JIAODU_2_HUDU(_angel-90); float y=PY + TUOYUAN_B*sin(JIAODU_2_HUDU(_angel-90); _btn1.center=CGPointMake(x, y); float x4=PX + TUOYUAN_A*cos(JIAODU_2_HUDU(_angel); float y4=PY + TUOYUAN_B*sin(JIAODU_2_HUDU(_angel); _btn4.center=CGPointMake(x4, y4); float x3=PX + TUOYUAN_A*cos(JIAODU_2_HUDU(_angel+90); float y3=PY + TUOYUAN_B*sin(JIAODU_2_HUDU(_angel+90); _btn3.center=CGPointMake(x3, y3); float x2=PX + TUOYUAN_A*cos(JIAODU_2_HUDU(_angel+180); float y2=PY + TUOYUAN_B*sin(JIAODU_2_HUDU(_angel+180); _btn2.center=CGPointMake(x2, y2); }- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end

0 0
原创粉丝点击