Giter VIP home page Giter VIP logo

rainbowcolors-with-swift's Introduction

Rainbow Colors with Swift

Generate rainbow colors with Swift. 用Swift语言生成���彩虹色。

There is only one function to generate the color: 通过一个函数来实现:

  • func rainbowColor(x: Float) -> UIColor

parameter range: 参数取值范围:

x : 0 ~ 256 * 5 - 1

Exsample of creating all rainbow colors: 生成所有彩虹色的例子:

class ViewController: UIViewController {
                        
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    
        let viewHeight:Float = Float(self.view.frame.size.height)
        let viewWidth:Float = Float(self.view.frame.size.width)
    
        //Create all Rainbow Colors
        let inc:Float = 256 * 5 / viewHeight;
    
        for (var i:Float = 0.0; i < 256 * 5; i += inc) {
            let view = UIView();
            view.frame = CGRectMake(0, 0 + i / inc, viewWidth, 1);
            view.backgroundColor = rainbowColor(Float(i));
            self.view.addSubview(view);
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

image

License

(c) 2014 杜子兮(duzixi). Released under the terms of the MIT license.

rainbowcolors-with-swift's People

Contributors

duzixi avatar

Watchers

James Cloos avatar Brian Harper avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.