Back to project page candy-drop.
The source code is released under:
Copyright (c) 2014, Gregory Martin All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ...
If you think the Android project candy-drop listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.gregfmartin.facetapper.entities; /*from ww w . j av a 2 s .c om*/ /** * A sinusoidal wave that will trigger an action on amplitude. The wave does not operate on peak-to-peak * measurements. Amplitude and Frequency are not explicitly defined by the Pulse. These are left to the framework * to inject. The distance of the wave is fixed at 2*PI (or 360 degrees) and will loop. A Pulse also contains a * threshold that can be used for cases when the Frequency will not permit the measured value to reach peak * Amplitude. * * @author Gregory Martin */ public class Pulse { private float mAmplitude; private float mFrequency; private float mThreshold; private float mThresholdPercentage; private float mCurrentWavePoint; private float mCurrentWavePointValue; private float mWaveScope; public Pulse() {} public Pulse(float amplitude, float frequency, float thresholdPercentage, float scope) { mAmplitude = (float)Math.ceil(amplitude); mFrequency = (float)Math.ceil(frequency); mThreshold = 0.0F; mThresholdPercentage = thresholdPercentage; mWaveScope = scope; calculateThreshold(); } private void calculateThreshold() { mThreshold = mAmplitude * mThresholdPercentage; } public void update() { // Move to the next measurable point in the wave mCurrentWavePoint = (float)Math.floor((mCurrentWavePoint + mFrequency) % mWaveScope); // Calculate the value on the current point in the sine wave mCurrentWavePointValue = (float)Math.floor(mAmplitude * (float)Math.sin(Math.toRadians(mFrequency * mCurrentWavePoint))); } public boolean isCurrentPointWithinThreshold() { if(mCurrentWavePointValue >= mThreshold) { return true; } else { return false; } } }