Skip to content

Commit

Permalink
SwiftUI PIXs
Browse files Browse the repository at this point in the history
  • Loading branch information
heestand-xyz committed Jun 28, 2020
1 parent f8b9268 commit 2a7a83c
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 2 deletions.
116 changes: 116 additions & 0 deletions Source/PIX/PIXs/Content/Generator/NoisePIX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,122 @@

import LiveValues
import RenderKit
#if canImport(SwiftUI)
import SwiftUI
#endif

@available(iOS 13.0.0, *)
@available(OSX 10.15, *)
@available(tvOS 13.0.0, *)
public struct PixNoise: View, PIXUI {
public var node: NODE { pix }

public let pix: PIX
let noisepix: NoisePIX
public var body: some View {
NODERepView(node: pix)
}

public init(octaves: Binding<Int> = .constant(10),
colored: Binding<Bool> = .constant(false),
random: Binding<Bool> = .constant(false),
zPosition: Binding<CGFloat> = .constant(0.0),
zoom: Binding<CGFloat> = .constant(1.0),
position: Binding<CGPoint> = .constant(.zero),
resolution: Resolution = .auto(render: PixelKit.main.render)) {
noisepix = NoisePIX(at: resolution)
noisepix.octaves = LiveInt({ octaves.wrappedValue })
noisepix.colored = LiveBool({ colored.wrappedValue })
noisepix.random = LiveBool({ random.wrappedValue })
noisepix.zPosition = LiveFloat({ zPosition.wrappedValue })
noisepix.zoom = LiveFloat({ zoom.wrappedValue })
noisepix.position = LivePoint({ position.wrappedValue })
pix = noisepix
}
// Parent Property Funcs
public func bgColor(_ bgColor: Binding<_Color>) -> PixNoise {
noisepix.bgColor = LiveColor({ bgColor.wrappedValue })
return self
}
public func bgColor(_ bgColor: LiveColor) -> PixNoise {
noisepix.bgColor = bgColor
return self
}
public func color(_ color: Binding<_Color>) -> PixNoise {
noisepix.color = LiveColor({ color.wrappedValue })
return self
}
public func color(_ color: LiveColor) -> PixNoise {
noisepix.color = color
return self
}
// General Property Funcs
public func colored(_ colored: Binding<Bool>) -> PixNoise {
noisepix.colored = LiveBool({ colored.wrappedValue })
return self
}
public func colored(_ colored: LiveBool) -> PixNoise {
noisepix.colored = colored
return self
}
public func random(_ random: Binding<Bool>) -> PixNoise {
noisepix.random = LiveBool({ random.wrappedValue })
return self
}
public func random(_ random: LiveBool) -> PixNoise {
noisepix.random = random
return self
}
public func includeAlpha(_ includeAlpha: Binding<Bool>) -> PixNoise {
noisepix.includeAlpha = LiveBool({ includeAlpha.wrappedValue })
return self
}
public func includeAlpha(_ includeAlpha: LiveBool) -> PixNoise {
noisepix.includeAlpha = includeAlpha
return self
}
public func zPosition(_ zPosition: Binding<CGFloat>) -> PixNoise {
noisepix.zPosition = LiveFloat({ zPosition.wrappedValue })
return self
}
public func zPosition(_ zPosition: LiveFloat) -> PixNoise {
noisepix.zPosition = zPosition
return self
}
public func zoom(_ zoom: Binding<CGFloat>) -> PixNoise {
noisepix.zoom = LiveFloat({ zoom.wrappedValue })
return self
}
public func zoom(_ zoom: LiveFloat) -> PixNoise {
noisepix.zoom = zoom
return self
}
public func seed(_ seed: Binding<Int>) -> PixNoise {
noisepix.seed = LiveInt({ seed.wrappedValue })
return self
}
public func seed(_ seed: LiveInt) -> PixNoise {
noisepix.seed = seed
return self
}
public func octaves(_ octaves: Binding<Int>) -> PixNoise {
noisepix.octaves = LiveInt({ octaves.wrappedValue })
return self
}
public func octaves(_ octaves: LiveInt) -> PixNoise {
noisepix.octaves = octaves
return self
}
public func position(_ position: Binding<CGPoint>) -> PixNoise {
noisepix.position = LivePoint({ position.wrappedValue })
return self
}
public func position(_ position: LivePoint) -> PixNoise {
noisepix.position = position
return self
}
// Enum Property Funcs
}

public class NoisePIX: PIXGenerator, PIXAuto {

Expand Down
28 changes: 26 additions & 2 deletions Source/PIX/PIXs/Effects/Merger/BlendPIX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,38 @@ import MetalKit
//#if !os(tvOS) && !targetEnvironment(simulator)
//import MetalPerformanceShaders
//#endif
#if canImport(SwiftUI)
import SwiftUI
#endif

@available(iOS 13.0.0, *)
@available(OSX 10.15, *)
@available(tvOS 13.0.0, *)
public struct PixBlend: View, PIXUI {
public var node: NODE { pix }

public let pix: PIX
let blendpix: BlendPIX
public var body: some View {
NODERepView(node: pix)
}

public init(mode: RenderKit.BlendMode, _ uiPixA: () -> (PIXUI), with uiPixB: () -> (PIXUI)) {
blendpix = BlendPIX()
blendpix.blendMode = mode
pix = blendpix
blendpix.inputA = uiPixA().pix as? (PIX & NODEOut)
blendpix.inputB = uiPixB().pix as? (PIX & NODEOut)
}
}

public class BlendPIX: PIXMergerEffect, Layoutable, PIXAuto/*, PixelCustomMergerRenderDelegate*/ {

override open var shaderName: String { return "effectMergerBlendPIX" }

// MARK: - Public Properties

public var blendMode: BlendMode = .add { didSet { setNeedsRender() } }
public var blendMode: RenderKit.BlendMode = .add { didSet { setNeedsRender() } }
public var bypassTransform: LiveBool = false
public var position: LivePoint = .zero
public var rotation: LiveFloat = LiveFloat(0.0, min: -0.5, max: 0.5)
Expand Down Expand Up @@ -140,7 +164,7 @@ public class BlendPIX: PIXMergerEffect, Layoutable, PIXAuto/*, PixelCustomMerger

}

public func blend(_ mode: BlendMode, _ pixA: PIX & NODEOut, _ pixB: PIX & NODEOut) -> BlendPIX {
public func blend(_ mode: RenderKit.BlendMode, _ pixA: PIX & NODEOut, _ pixB: PIX & NODEOut) -> BlendPIX {
let blendPix = BlendPIX()
blendPix.inputA = pixA
blendPix.inputB = pixB
Expand Down

0 comments on commit 2a7a83c

Please sign in to comment.