works on iOS, tvOS, watchOS and macOS
.package(url: "https://github.com/hexagons/Trails.git", from: "1.1.1")
import SwiftUI
import Trails
struct 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.0
duration is in seconds
.duration
can be changed while running
values added longer ago than the duration will be removed
trailer.circlesActive = true
.circlesActive
default isfalse
trailer.circleBorder = false
trailer.circleRadius = 2.0
.circleBorder
default istrue
.circleRadius
default is3.0
trailer.lineWidth = 3.0
.lineWidth
default is1.0
trailer.colorsActive = false
when count is
1
,.colorsActive
isfalse
by default
when count is
2
or more,.colorsActive
istrue
by default
trailer.hues = [0.0, 0.1, 0.2]
the number of hues must match the count passed to
Trailer
.hues
is "rainbow" by default
a hue is a value between
0.0
and1.0
, low values: red to green, middle values: green to blue, high values: blue to red
trailer.colorBlend = false
when
.colorBlend
isfalse
the lines will not be blended. this option is visible when a lot of lines overlap
when
.colorBlend
istrue
, light mode blends with.multiply
, dark mode blends with.lighten
.colorBlend
istrue
by default
trailer.drawValueEndLines = false
.drawValueEndLines
istrue
by default
trailer.drawValueBackground = false
.drawValueBackground
istrue
by default on iOS and watchOS can be useful to turn tofalse
if your background is transparent
trailer.drawDefaultTextBackground = false
.drawValueBackground
istrue
by default on iOS and watchOS can be useful to turn tofalse
if your background is transparent
trailer.fontSize = 12.0
.fontSize
is8.0
by default
trailer.leftSpacing = 10.0
trailer.rightSpacing = 10.0
.leftSpacing
and.rightSpacing
is20.0
by 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