Skip to content

SwiftyCreatives Documents

Yuki Kuwashima edited this page Feb 4, 2024 · 4 revisions

Tutorial

  1. Create your sketch class
class MySketch: Sketch {
    override func draw(encoder: SCEncoder) {
        // write draw functions here
    }
}
  1. Display your sketch with SwiftUI View
struct ContentView: View {
    var body: some View {
        SketchView(MySketch())
    }
}

Data Types

f2, f3, f4, f4x4

  • typealias for simd_float2, simd_float3, simd_float4, simd_float4x4

Draw Functions

color

Set color. rgba in 0...1.

color(_ r: Float, _ g: Float, _ b: Float, _ a: Float)

boldline

Draw line with width. boldline is 2d plane geometry, so carefully use this in 3d space.

boldline(_ x1: Float, _ y1: Float, _ z1: Float, _ x2: Float, _ y2: Float, _ z2: Float, width: Float)

box

Draw 3d box.

box(_ x: Float, _ y: Float, _ z: Float, _ scaleX: Float, _ scaleY: Float, _ scaleZ: Float)

circle

Draw circle.

circle(_ x: Float, _ y: Float, _ z: Float, _ radX: Float, _ radY: Float)

fog

Set fog in the scene. density has to be 0...1.

setFog(color: f4, density: Float)
Clone this wiki locally