package org.nusco.swimmers.creature.pns;

import java.util.LinkedList;
import java.util.List;

import org.nusco.swimmers.physics.Vector;

/**
 * Given an input V, generates an output that goes from -V to V and back in a sinusoidal wave.
 */
public class WaveNerve extends Nerve {

	private final double frequency;

	private double cosWave = 0;
	private List<DelayNerve> children = new LinkedList<>();

	public WaveNerve(double frequency) {
		this.frequency = frequency;
	}
	
	@Override
	public Vector process(Vector inputSignal) {
		double amplitude = Math.cos(cosWave);
		updateCosWave();
		return inputSignal.by(amplitude);
	}

	private void updateCosWave() {
		cosWave = (cosWave + Math.PI * 2 * frequency) % (Math.PI * 2);
	}

	public void connectTo(DelayNerve box) {
		children.add(box);
	}
}

@@ -39,61 +39,8 @@
 s;%0A%0A
-import java.util.LinkedList;%0Aimport java.util.List;%0A%0A
 impo
@@ -77,16 +77,16 @@
 Vector;%0A
+
 %0A/**%0A * 
@@ -287,65 +287,8 @@
 = 0;
-%0A%09private List%3CDelayNerve%3E children = new LinkedList%3C%3E();
 %0A%0A%09p
@@ -545,16 +545,16 @@
 ave() %7B%0A
+
 %09%09cosWav
@@ -616,73 +616,7 @@
 ;%0A%09%7D
-%0A%0A%09public void connectTo(DelayNerve box) %7B%0A%09%09children.add(box);%0A%09%7D
 %0A%7D%0A

Clean up WaveNerve