Giter Club home page Giter Club logo

irregulargradient's Introduction

IrregularGradient Project logo


Twitter: @joogps

A SwiftUI library for rendering beautiful, animated and irregular gradient views.

Note

This project implements this effect using pure SwiftUI, which can be computationally expensive. If you want something more efficient, please consider switching to FluidGradient.

Installation

This repository is a Swift package, so just include it in your Xcode project and target under File > Add package dependencies. Then, import IrregularGradient to the Swift files where you'll be using it.

Usage

You can add an irregular gradient to your app with the following modifier:

RoundedRectangle(cornerRadius: 24.0, style: .continuous)
    .irregularGradient(colors: [.orange, .pink, .yellow, .orange, .pink, .yellow], backgroundColor: .orange)

The other parameters go as follow:

irregularGradient(colors: [Color], background: () -> View, shouldAnimate: Binding<Bool> = .constant(true), speed: Double = 10)
  • colors specifies the colors of each blob. Order and amount matters, so the colors will be stacked in the order of the array on the Z axis. Having two entries of the same color will create two completely distinct blobs of that color.
  • background defines the background of your gradient. It's a closure that returns a view. Not specifying this value it will make the background clear.
  • shouldAnimate is a boolean that specifies whether or not the gradient blobs should move. It can be enabled and disabled dinamically, and movement will always slow down to a stop. The default value is true.
  • speed accepts a Double and defines the speed of the movement โ€” a 0.5 speed means the blobs will update every 2 seconds. The default value is 1.

You can also use the IrregularGradient standalone view, which exists in its own container.

How it's done

The current implementation of this package is done through the creation of blobs (SwiftUI's Ellipse shape) of the specified colors that move and scale randomly in the container, and are then blurred to achieve the desired effect.

Questions

If you have any questions or suggestions, you can create an issue or pull request on this GitHub repository or even contact me via Twitter or email.

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.