Who can provide sample code written in Swift language for drawing multiple custom paths

I want to use Swift language to write code for drawing multiple polygons. I would like to find some examples as references. Can anyone provide example code or tell me where I can see such examples? Thank you!

It’s hard to answer this without know more about your goals. Are you trying to do this in 2D or 3D? Presumably you’re using SwiftUI for your UI framework? Do you want to use it as your graphics framework as well? If not, which graphics framework are you using?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

So, assuming by polygons you mean like a square:

Rectangle()

If you mean like a custom shape, I’d suggest using Vertices.

I’ve linked my repository that deals with this somewhat. I didn’t like Apple’s example in their documentation so I did this instead. https://github.com/ibapps39/helloTriangle

It’s hard to give you concrete answer because there’s many ways of doing it, from Metal to SceneKit to Swift/SwiftUI‘s various shapes to UIKit, and etc.

I was a bit tired last night but this is another way I meant to send:

//
//  PolicyView.swift
//  poliAlpha
//
//  Created by Ian Brown on 10/17/24.
//

import SwiftUI

struct Polygon: View {
    let cornerRad: CGFloat = 12
    var body: some View {
        VStack {
            let polygonWidth: CGFloat = 100
            let polygonHeight: CGFloat = 100
            let path = Path { path in
                path.move(to: CGPoint(x: 0, y: 0))
                
                path.addLine(to: CGPoint(x: 0, y: polygonHeight))
                path.addLine(to: CGPoint(x: polygonWidth, y: polygonHeight))
                path.addLine(to: CGPoint(x: polygonWidth, y: 0))
                
                path.closeSubpath()
            }
            path.fill()

        }
    }
}

#Preview {
    Polygon()
}

Thank you for providing the code, but it seems that it cannot be placed in a for loop as it will prompt:closure containing control flow statement cannot be used with result builder"ViewBuilder"

Who can provide sample code written in Swift language for drawing multiple custom paths
 
 
Q