Skip to content

Instantly share code, notes, and snippets.

@CodeSlicing
Last active August 3, 2021 23:15
Show Gist options
  • Save CodeSlicing/046a291bedde175d4de96220aa56a1ee to your computer and use it in GitHub Desktop.
Save CodeSlicing/046a291bedde175d4de96220aa56a1ee to your computer and use it in GitHub Desktop.
Native source code for advanced design in SwiftUI - HomePod
//
// HomePodTopViewNative.swift
//
// 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 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.
//
// Created by Adam Fordyce on 03/07/2021.
// Copyright © 2021 Adam Fordyce. All rights reserved.
//
import SwiftUI
struct HomePodTopViewNative: View {
var body: some View {
let mesh = ZStack {
ForEach(0..<130) { index in
Circle()
.strokeBorder(Color(white: 0.15), lineWidth: 1.25)
.frame(width: 160, height: 160)
.offset(x: 120)
.rotationEffect(.degrees(2.7692 * Double(index)))
}
}
ZStack {
//base
Circle()
.scale(0.95)
.shadow(color: Color(white: 0.15), radius: 10, y: 18)
Circle()
.fill(Color.black)
//mesh
mesh
Circle()
.scale(0.88)
.fill(Color(white: 0.35))
.blur(radius: 15)
.mask(mesh)
.blendMode(.screen)
// user interface
Group {
Circle()
.scale(1.01)
.fill(Color.black)
.blur(radius: 5)
Circle()
.fill(LinearGradient(gradient: Gradient(colors: [Color(white: 0.2), .black, .black]), startPoint: .top, endPoint: .bottom))
Circle()
.strokeBorder(AngularGradient(gradient: Gradient(colors: [.white, .black, .white, .black, .white, .black, .white]), center: .center, startAngle: .degrees(-100), endAngle: .degrees(260)), lineWidth: 2)
.blur(radius: 1)
}
.scaleEffect(0.63)
// siri circle
Group {
Circle()
.fill(AngularGradient(gradient: Gradient(colors: [.blue, .blue, /*Color.cgCyan.opacity(0.8), */.purple, .purple, .purple, .blue]), center: .center, startAngle: .degrees(-100), endAngle: .degrees(260)))
.scaleEffect(0.17)
.blur(radius: 10)
.saturation(1.4)
.brightness(0.3)
.drawingGroup()
Circle()
.scale(0.16)
.stroke(AngularGradient(gradient: Gradient(colors: [.blue, .green, .red, .blue]), center: .center, startAngle: .degrees(-100), endAngle: .degrees(260)), lineWidth: 3)
.blur(radius: 6)
.saturation(2)
Circle().scale(0.075).fill(Color.white).blur(radius: 12)
}
.blur(radius: 4)
.mask(Circle().scale(0.22).blur(radius: 7))
}
}
}
struct HomePodTopViewNative_Previews: PreviewProvider {
struct HomePodTopViewNative_Harness: View {
var body: some View {
HomePodTopViewNative()
.frame(width: 400, height: 400)
.padding(50)
}
}
static var previews: some View {
HomePodTopViewNative_Harness()
.previewLayout(.sizeThatFits)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment