From 8ea40bbb4f8bada1fbedba898ed4495f506c558e Mon Sep 17 00:00:00 2001 From: Kenneth Date: Mon, 29 Jul 2024 22:28:13 +0100 Subject: [PATCH] fix: make dot scale effect much more gradual --- InfinifiIOS/DottedBackground.swift | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/InfinifiIOS/DottedBackground.swift b/InfinifiIOS/DottedBackground.swift index 3ddd172..7fe2dc5 100644 --- a/InfinifiIOS/DottedBackground.swift +++ b/InfinifiIOS/DottedBackground.swift @@ -2,8 +2,8 @@ import Combine import Foundation import SwiftUI -let effectRadius = 100 -let minDotRadius = 1 +let effectRadius: Float = 100 +let minDotRadius: Float = 1 struct DottedBackground: View { @State private var isDragging = false @@ -34,16 +34,17 @@ struct DottedBackground: View { Canvas { ctx, size in for y in stride(from: 0, to: Int(size.height), by: 10) { for x in stride(from: 0, to: Int(size.width), by: 10) { - let radius: Int + let radius: CGFloat if isDragging { - let distanceFromTouch = Int(sqrt(pow(Float(x) - touchX, 2) + pow(Float(y) - touchY, 2))) - radius = minDotRadius + minDotRadius * 4 * (effectRadius - min(effectRadius, distanceFromTouch)) / 100 + let distanceFromTouch = sqrt(pow(Float(x) - touchX, 2) + pow(Float(y) - touchY, 2)) + let howCloseToOrigin: Float = (effectRadius - min(effectRadius, distanceFromTouch)) / 100 + radius = CGFloat(minDotRadius + minDotRadius * 2 * howCloseToOrigin) } else { - radius = minDotRadius + radius = CGFloat(minDotRadius) } 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) ) }