github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/pixel/flowers/math.go (about)

     1  package main
     2  
     3  import (
     4  	"math"
     5  
     6  	"github.com/faiface/pixel"
     7  )
     8  
     9  const TAU = 2 * math.Pi
    10  
    11  func Bounce(t, start, end, duration float64) float64 {
    12  	t = t / duration
    13  	ts := t * t
    14  	tc := ts * t
    15  	return start + end*(33*tc*ts+-106*ts*ts+126*tc+-67*ts+15*t)
    16  }
    17  
    18  func SegmentNormal(a, b pixel.Vec) pixel.Vec {
    19  	return Rotate(b.Sub(a))
    20  }
    21  
    22  func Rotate(a pixel.Vec) pixel.Vec {
    23  	return pixel.V(-a.Y, a.X)
    24  }
    25  
    26  func ScaleTo(a pixel.Vec, r float64) pixel.Vec {
    27  	x := a.Len()
    28  	return a.Scaled(r / x)
    29  }