fix: make dot scale effect much more gradual

This commit is contained in:
2024-07-29 22:28:13 +01:00
parent b3ce340774
commit 8ea40bbb4f

View File

@@ -2,8 +2,8 @@ import Combine
import Foundation import Foundation
import SwiftUI import SwiftUI
let effectRadius = 100 let effectRadius: Float = 100
let minDotRadius = 1 let minDotRadius: Float = 1
struct DottedBackground: View { struct DottedBackground: View {
@State private var isDragging = false @State private var isDragging = false
@@ -34,16 +34,17 @@ struct DottedBackground: View {
Canvas { ctx, size in Canvas { ctx, size in
for y in stride(from: 0, to: Int(size.height), by: 10) { for y in stride(from: 0, to: Int(size.height), by: 10) {
for x in stride(from: 0, to: Int(size.width), by: 10) { for x in stride(from: 0, to: Int(size.width), by: 10) {
let radius: Int let radius: CGFloat
if isDragging { if isDragging {
let distanceFromTouch = Int(sqrt(pow(Float(x) - touchX, 2) + pow(Float(y) - touchY, 2))) let distanceFromTouch = sqrt(pow(Float(x) - touchX, 2) + pow(Float(y) - touchY, 2))
radius = minDotRadius + minDotRadius * 4 * (effectRadius - min(effectRadius, distanceFromTouch)) / 100 let howCloseToOrigin: Float = (effectRadius - min(effectRadius, distanceFromTouch)) / 100
radius = CGFloat(minDotRadius + minDotRadius * 2 * howCloseToOrigin)
} else { } else {
radius = minDotRadius radius = CGFloat(minDotRadius)
} }
ctx.fill( ctx.fill(
Path(ellipseIn: CGRect(x: x, y: y, width: radius * 2, height: radius * 2)), Path(ellipseIn: CGRect(origin: CGPoint(x: x, y: y), size: CGSizeMake(radius * 2, radius * 2))),
with: .color(.surface1) with: .color(.surface1)
) )
} }