works on iOS, tvOS, watchOS and macOS
.package(url: "https://github.com/hexagons/Trails.git", from: "1.1.1")import SwiftUI
import Trailsstruct ContentView: View {
var main: Main = Main()
var body: some View {
TrailsView(trailer: main.trailer)
}
}class Main {
let trailer: Trailer
init() {
let trailCount: Int = 3
let seconds: Double = 10.0
trailer = Trailer(count: trailCount,
duration: seconds)
trailer.circlesActive = true
startTimer()
}
func startTimer() {
let startDate: Date = Date()
let timer: Timer = Timer(timeInterval: 0.5, repeats: true) { _ in
let time: Double = -startDate.timeIntervalSinceNow
let valueA: Double = cos(time)
let valueB: Double = cos(time + (.pi * 2) * (1.0 / 3.0))
let valueC: Double = cos(time + (.pi * 2) * (2.0 / 3.0))
self.trailer.add(valueA, at: 0)
self.trailer.add(valueB, at: 1)
self.trailer.add(valueC, at: 2)
}
RunLoop.current.add(timer, forMode: .common)
}
}trailer.duration = 10.0duration is in seconds
.durationcan be changed while running
values added longer ago than the duration will be removed
trailer.circlesActive = true
.circlesActivedefault isfalse
trailer.circleBorder = false
trailer.circleRadius = 2.0
.circleBorderdefault istrue
.circleRadiusdefault is3.0
trailer.lineWidth = 3.0
.lineWidthdefault is1.0
trailer.colorsActive = falsewhen count is
1,.colorsActiveisfalseby default
when count is
2or more,.colorsActiveistrueby default
trailer.hues = [0.0, 0.1, 0.2]the number of hues must match the count passed to
Trailer
.huesis "rainbow" by default
a hue is a value between
0.0and1.0, low values: red to green, middle values: green to blue, high values: blue to red
trailer.colorBlend = falsewhen
.colorBlendisfalsethe lines will not be blended. this option is visible when a lot of lines overlap
when
.colorBlendistrue, light mode blends with.multiply, dark mode blends with.lighten
.colorBlendistrueby default
trailer.drawValueEndLines = false
.drawValueEndLinesistrueby default
trailer.drawValueBackground = false
.drawValueBackgroundistrueby default on iOS and watchOS can be useful to turn tofalseif your background is transparent
trailer.drawDefaultTextBackground = false
.drawValueBackgroundistrueby default on iOS and watchOS can be useful to turn tofalseif your background is transparent
trailer.fontSize = 12.0
.fontSizeis8.0by default
trailer.leftSpacing = 10.0
trailer.rightSpacing = 10.0
.leftSpacingand.rightSpacingis20.0by default
To repilcate the randomness seen in the gifs in the top of this readme, use this code:
let trailer: Trailer = TrailerMock.make()provided by TrailerMock.swift





