SwiftyCreatives

Release Swift Compatibility Platform Compatibility License

Swift 的创意编码框架。
直接使用 Metal 进行渲染。灵感来自 Processing。支持 visionOS。

outputFinalfinal

AI 文档(问答)

https://chatgpt.com/g/g-67a4bd5b2f6c81918311ea49989be5d5-swifty-creatives-q-a

要求

支持的平台

主要功能

类 Processing 的语法

你可以使用 Swift 编程语言,并结合 Processing 的直观本质,轻松创建图形。
我喜欢 push()pop() 如何使用 Swift 的尾随闭包变得非常简单。

import SwiftyCreatives

final class MySketch: Sketch {
    override func draw(encoder: SCEncoder) {
        let count = 20
        for i in 0..<count {
            color(0.75, Float(i) / 40, 1, 0.5)
            push {
                rotateY(Float.pi * 2 / Float(count) * Float(i))
                translate(10, 0, 0)
                box(0, 0, 0, 1, 1, 1)
            }
        }
    }
}

struct ContentView: View {
    var body: some View {
        SketchView(MySketch())
    }
}

スクリーンショット 2024-02-04 5 38 56

Apple Vision Pro - 沉浸式空间

支持 visionOS! 你可以使用沉浸式空间渲染来沉浸在你的草图中!

ImmersiveSpace(id: "ImmersiveSpace") {
    CompositorLayer(configuration: ContentStageConfiguration()) { layerRenderer in
        let renderer = RendererBase.BlendMode.normalBlend.getRenderer(sketch: SampleSketch(), layerRenderer: layerRenderer)
        renderer.startRenderLoop()
    }
}

ddd

xib 到 3D 空间!

使用 xib 创建 UIView,并将其放置在 3D 场景中!
UIButton 可以与 IBAction 连接,并且可以在 3d 空间中点击。

outout

安装

使用 Swift Package Manager。

dependencies: [
    .package(url: "https://github.com/yukiny0811/swifty-creatives.git", branch: "main")
]
.product(name: "SwiftyCreatives", package: "swifty-creatives")

功能

事件

open func setupCamera(camera: MainCamera) {}
open func preProcess(commandBuffer: MTLCommandBuffer) {}
open func update(camera: MainCamera) {}
open func draw(encoder: SCEncoder) {}
open func afterCommit(texture: MTLTexture?) {}
open func postProcess(texture: MTLTexture, commandBuffer: MTLCommandBuffer) {}

#if os(macOS)
open func mouseMoved(camera: MainCamera, location: f2) {}
open func mouseDown(camera: MainCamera, location: f2) {}
open func mouseDragged(camera: MainCamera, location: f2) {}
open func mouseUp(camera: MainCamera, location: f2) {}
open func mouseEntered(camera: MainCamera, location: f2) {}
open func mouseExited(camera: MainCamera, location: f2) {}
open func keyDown(with event: NSEvent, camera: MainCamera, viewFrame: CGRect) {}
open func keyUp(with event: NSEvent, camera: MainCamera, viewFrame: CGRect) {}
open func viewWillStartLiveResize(camera: MainCamera, viewFrame: CGRect) {}
open func resize(withOldSuperviewSize oldSize: NSSize, camera: MainCamera, viewFrame: CGRect) {}
open func viewDidEndLiveResize(camera: MainCamera, viewFrame: CGRect) {}
open func scrollWheel(with event: NSEvent, camera: MainCamera, viewFrame: CGRect) {}
#endif

#if os(iOS)
open func onScroll(delta: CGPoint, camera: MainCamera, view: UIView, gestureRecognizer: UIPanGestureRecognizer) {}
open func touchesBegan(camera: MainCamera, touchLocations: [f2]) {}
open func touchesMoved(camera: MainCamera, touchLocations: [f2]) {}
open func touchesEnded(camera: MainCamera, touchLocations: [f2]) {}
open func touchesCancelled(camera: MainCamera, touchLocations: [f2]) {}
#endif

其他示例

ExampleMacOSApp 2023年-02月-24日 17 11 06

CheckMacOS 2023年-03月-01日 6 46 57

QuickTime Player - 画面収録 2023-02-10 1 53 14 mov 2023年-02月-10日 2 55 14

stable fluids

致谢