Swiftpack.co - Pyroh/HSBShading as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Pyroh.
Pyroh/HSBShading 0.2.0
Draw HSB shadings in CGContext
⭐️ 0
🕓 1 year ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/Pyroh/HSBShading.git", from: "0.2.0")

HSBShading draws hue, saturation and brightness shadings to a CGContext. Those shadings can be axial or radial.

Installation

As a Swift Package you can add HSBShading as a dependency in your project's Package.swift file :

dependencies: [
// Dependencies declare other packages that this package depends on.
...
    .package(url: "https://github.com/Pyroh/HSBShading", .upToNextMajor(from: "0.1.0")),
...
],

Then import HSBShading wherever needed.

Or copy the code into your own code. Whatever suits you. Don't forget about the license and to wash your hands.

Usage

Drawing an axial hue shading

class AxialHueShadingView: NSView {
    override func draw(_ dirtyRect: NSRect) {
        ...
        
        let cs = /* An RGB color space */
        let ctx = /* The CGContext */
        let start = /* The starting point of the shading */
        let end = /* The ending point of the shading */
        
        HSBShading.drawAxialHueShading(to: ctx, colorSpace: cs, start: start, end: end)
        
        ...
    }
}

Result:

Drawing an axial saturation shading

class AxialSaturationShadingView: NSView {
    override func draw(_ dirtyRect: NSRect) {
        ...
        
        /* Set variables */
        
        HSBShading.drawAxialSaturationShading(to: ctx, colorSpace: cs, start: start, end: end)
        
        ...
    }
}

Result:

Drawing an axial brightness shading

class AxialBrightnessShadingView: NSView {
    override func draw(_ dirtyRect: NSRect) {
        ...
        
        /* Set variables */
        
        HSBShading.drawAxialBrightnessShading(to: ctx, colorSpace: cs, start: start, end: end)
        
        ...
    }
}

Result:

Drawing a radial hue shading

class RadialHueShadingView: NSView {
    override func draw(_ dirtyRect: NSRect) {
        ...
    
        let cs = /* An RGB color space */
        let ctx = /* The CGContext */
        let start = /* The center of the starting circle */
        let end = /* The center of the ending circle */
        let startRadius = /* The radius of the starting circle */
        let endRadius = /* The radius of the ending circle */
        
        HSBShading.drawRadialHueShading(to: ctx, colorSpace: cs, start: end, startRadius: endRadius, end: start, endRadius: startRadius)
        
        ...
    }
}

Result:

Drawing a radial saturation shading

class RadialSaturationShadingView: NSView {
    override func draw(_ dirtyRect: NSRect) {
        ...
    
        /* Set variables */
        
        HSBShading.drawRadialSaturationShading(to: ctx, colorSpace: cs, start: end, startRadius: endRadius, end: start, endRadius: startRadius)
        
        ...
    }
}

Result:

Drawing a radial brightness shading

class RadialBrightnessShadingView: NSView {
    override func draw(_ dirtyRect: NSRect) {
        ...
    
        /* Set variables */
        
        HSBShading.drawRadialBrightnessShading(to: ctx, colorSpace: cs, start: end, startRadius: endRadius, end: start, endRadius: startRadius)
        
        ...
    }
}

Result:

License

Copyright (c) 2022 Pierre Tacchi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

GitHub

link
Stars: 0
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics