0

I tried to create a water wave that will gradually increase and decrease depending with the amplitude. I am a little bit confused by this method from https://stackoverflow.com/a/60763612/1271826

func f(_ x: Double) -> CGFloat {
        let elapsed = CGFloat(elapsed)
        let amplitude = maxAmplitude * abs(fmod(CGFloat(elapsed/2), 3) - 1.5)
        let variation = sin((elapsed + amplitudeOffset) / amplitudeChangeSpeedFactor) * maxTidalVariation
        let value = sin((elapsed / saveSpeedFactor + CGFloat(x)) * 4 * .pi)
        return value * amplitude / 2 * bounds.height + (defaultTidalHeight + variation) * bounds.height
    }

I tried to change maxAmplitude to be dynamically changing on a certain range, but the waves wont change gradually but the code works fine. (Scenario case:: when amplitude is 1.0 and it falls suddenly to 0.0)

func f(_ x: Double) -> CGFloat {
        let elapsed = CGFloat(elapsed)
        let amplitude = //my dynamic amplitude here
        let variation = sin((elapsed + amplitudeOffset) / amplitudeChangeSpeedFactor) * maxTidalVariation
        let value = sin((elapsed / saveSpeedFactor + CGFloat(x)) * 4 * .pi)
        return value * amplitude / 2 * bounds.height + (defaultTidalHeight + variation) * bounds.height
    }

What I want is to create a gradually increasing and decrease wave depending with the amplitude as shown below. https://www.dropbox.com/s/gq8pu4t7xq2dzii/RPReplay_Final1668576978%202.mov?dl=0 Any suggestions and help will be highly appreciated.

Wykee N
  • 1
  • 3

0 Answers0