import java.lang.Math; import java.applet.*; import java.awt.*; import java.awt.event.*; import com.softsynth.jsyn.*; public class plasma2 extends Applet implements Runnable, MouseMotionListener { Panel panel; int Anzahl = 32; SineOscillator[] sineOsc = new SineOscillator[Anzahl]; SynthEnvelope envData; EnvelopePlayer[] envPlayer = new EnvelopePlayer[Anzahl]; BusWriter[] mixIn = new BusWriter[Anzahl]; BusReader mixOut; LineOut lineOut; double frq = 50.0; int ph = 1050; // Anzahl Einzelflächen horizontal int pv = 700; // Anzahl Einzelflächen vertikal int i = 300, j = 300, ci, cj; // Koordinaten Einzelfläche int mouseMovedX, mouseMovedY; // Mauskoordinaten double z; // Zähler double r; // Radius int l = 3; // Seitnlänge Einzelfläche int k; // Index sineOsc int bereich = 64; // Größe Zufallsbereich int grenze = 0; // untere Grenze Zufallsbereich Dimension Size; // Gesamtgröße int rot = 0, grün = 0, blau = 0; // Farbwerte int farbpegel; // Farbänderung Thread animator; // Thread int SleepTime = 12; // Animationspuls in ms boolean please_stop; // stop-Anforderung double[] data = { 0.005, 0.1, 0.005, 0.01, 0.275, 0.0 }; // init public void init () { setSize( ph, pv ); setBackground( new Color( 0, 0, 0 ) ); ci = i; cj = j; addMouseListener( new MouseAdapter() { public void mousePressed( MouseEvent e ) { if ( animator != null ) { please_stop = true; } else { start(); } } }); addMouseMotionListener( this ); setCursor( new Cursor( Cursor.CROSSHAIR_CURSOR ) ); // Klang einrichten Synth.startEngine( 0 ); envData = new SynthEnvelope( data ); mixOut = new BusReader(); lineOut = new LineOut(); mixOut.output.connect( 0, lineOut.input, 0 ); mixOut.output.connect( 0, lineOut.input, 1 ); for ( int k = 0; k < Anzahl; k++ ) { sineOsc[k] = new SineOscillator(); sineOsc[k].frequency.set( frq ); envPlayer[k] = new EnvelopePlayer(); mixIn[k] = new BusWriter(); envPlayer[k].output.connect( sineOsc[k].amplitude ); sineOsc[k].output.connect( mixIn[k].input ); mixIn[k].busOutput.connect( mixOut.busInput ); sineOsc[k].start(); envPlayer[k].start(); mixIn[k].start(); } mixOut.start(); lineOut.start(); getParent().validate(); getToolkit().sync(); } public void mouseMoved( MouseEvent e ) { mouseMovedX = e.getX(); mouseMovedY = e.getY(); i = mouseMovedX; j = mouseMovedY; } public void mouseDragged( MouseEvent e ) {} public void paint( Graphics g ) { g.setColor( new Color( rot, grün, blau ) ); g.fillRect( ci, cj, l, l ); } // start public void start() { if ( animator == null ) { please_stop = false; // Thread erzeugen animator = new Thread( this ); animator.start(); } } // stop public void stop() { please_stop = true; removeAll(); Synth.stopEngine(); } // run -> Runnable public void run() { // solange, bis stop gewuenscht while ( !please_stop ) { z = Math.random() * 2.0 - 1.0; r = Math.random() * ph; r = Math.pow( ( Math.random() * 8.4 ), 3.0 ); ci = i - ( int )( r * ( Math.sin( z * 6.283185307 ) ) ); cj = j - ( int )( r * ( Math.cos( z * 6.283185307 ) ) ); k = ( int )( Math.random() * ( Anzahl - 1 ) ); l = ( int )( Math.random() * 4 + 1 ); farbpegel = ( int )( Math.random() * bereich + grenze ); rot = farbpegel * 4; grün = farbpegel * 3; blau = farbpegel * 2; repaint( ci, cj, l, l ); frq = Math.random() * ( 8.0 * i + 200 ) + ( j + 50.0 ); sineOsc[k].frequency.set( frq ); data[0] = i * 0.0005 + 0.1; data[1] = 0.0; envData.write( 2, data, 0, 1 ); envPlayer[k].envelopePort.clear(); envPlayer[k].envelopePort.queue( envData ); try { Thread.sleep( SleepTime ); } catch ( InterruptedException e ) {} } animator = null; } }