Skip to content

Instantly share code, notes, and snippets.

@AgtLucas
Forked from CastIrony/ContentView.swift
Created June 28, 2019 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AgtLucas/2e1f909e6df810135aceda53d6cb8f35 to your computer and use it in GitHub Desktop.
Save AgtLucas/2e1f909e6df810135aceda53d6cb8f35 to your computer and use it in GitHub Desktop.
//
// ContentView.swift
// BreatheUI WatchKit Extension
//
// Created by Joel Bernstein on 6/24/19.
// Copyright © 2019 Joel Bernstein. All rights reserved.
//
import SwiftUI
struct ContentView : View {
@State var minutes = 1.0
var circleCount: Double { minutes + 5 }
var roundedCircleCount: Int { Int(ceil(circleCount)) }
var body: some View {
GeometryReader { proxy in
ZStack {
ForEach(1...self.roundedCircleCount) { index in
Circle()
.rotation(self.calculateAngle(index), anchor: UnitPoint(x: 0.5, y: 1))
.scale(0.57)
.position(CGPoint(x: proxy.size.width * 0.5, y: proxy.size.width * 0.25))
.foregroundColor(Color.white.opacity(self.calculateOpacity(index)))
}
}
}
.focusable(true)
.digitalCrownRotation($minutes, from: 1, through: 5, by: 1, sensitivity: .low, isContinuous: false, isHapticFeedbackEnabled: true)
}
func calculateAngle(_ index: Int) -> Angle
{
return .degrees(-((Double(index) - 0.5) * (360.0 / self.circleCount)))
}
func calculateOpacity(_ index: Int) -> Double
{
let fadeThreshold = floor(circleCount)
return index <= Int(fadeThreshold) ? 0.5 : 0.5 * ( circleCount - fadeThreshold )
}
}
#if DEBUG
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment