zoukankan      html  css  js  c++  java
  • 使用圆参数方程平均分布图片在圆的周长上

    做图形界面开发的感觉是,可以运用到一些数学知识了,哈哈。需求是将若干小图片平均分布在圆的周长上。效果如下:

    imageimage

    用右侧图来表示,就是要求x和y的坐标。iPad的坐标系从左上开始。

    圆参数方程公式:

    x=R*cos(A)

    y=R*sin(A)

     

    这个公式的坐标系是按照圆心来的,如果按照屏幕的坐标系,还需要加上偏移量。

    具体到本例中,任意多个图,比如n个,就相当于对2PI个弧度取n分之一。

    实现代码:

    - (void)viewDidLoad { 
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation: UIStatusBarAnimationSlide]; 
        self.view=[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; 
        self.view.backgroundColor=[UIColor blueColor];

        NSArray *imageNames=[[NSArray alloc] initWithObjects:@"4.png",@"5.png",@"6.png",@"7.png",@"8.png",@"9.png",
                             @"10.png",@"11.png",@"12.png",@"13.png",@"14.png",@"15.png", 
                             nil]; 
        
        UIView *contentView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; 
        [self.view addSubview:contentView]; 
        
        int r=180; 
        
        for (int i=0; i<[imageNames count]; i++) { 
            UIImage *image=[UIImage imageNamed:[imageNames objectAtIndex:i]]; 
            int x=1024/2+r*cos(M_PI*2.0/[imageNames count]*i)-image.size.width/2; 
            int y=768/2+r*sin(M_PI*2.0/[imageNames count]*i)-image.size.height/2; 
            
            CGRect  viewRect = CGRectMake(x, y, image.size.width, image.size.height); 
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:viewRect]; 
            [imageView setImage:image]; 
            [contentView addSubview:imageView];

            [imageView release]; 
            [image release]; 
        } 
        
        NSLog(@">>>,%@",contentView.subviews); 
        
        [contentView release]; 
        [imageNames release]; 
    }

  • 相关阅读:
    struts2自定义拦截器之过滤不良言论---http500可能的问题所在
    bzoj4205[FJ2015集训] 卡牌配对
    bzoj1562[NOI2009] 变换序列
    bzoj1433[ZJOI2009] 假期的宿舍
    bzoj2150 部落战争
    从bzoj2463到bzoj1443和bzoj2437 博弈+二分图匹配
    bzoj4554[Tjoi2016&Heoi2016] 游戏
    bzoj1059[ZJOI2007] 矩阵游戏
    bzoj1143[CTSC2008] 祭祀river
    bzoj3175[Tjoi2013] 攻击装置
  • 原文地址:https://www.cnblogs.com/ibadcool/p/1958563.html
Copyright © 2011-2022 走看看