|
import java.awt.*; import javax.swing.*; /** * A graphic algortihm sonification program based on Fractal math * @author Natalie Rouillon and Andrew Brown */ public class SpiralWindow extends JFrame { public static void main(String[] args) { // create a new frame JFrame f = new JFrame("Natalie's Fractal Window"); // create a panel to put canvases onto JPanel pan = new JPanel(); // create multiple canvases and add to the panel for(int i=0; i<1;i++) { SpiralCanvas fc = new SpiralCanvas(); pan.add(fc); } // add the panel to the frame and display it f.setContentPane(pan); f.pack(); f.setVisible(true); // do music new SpiralMusic(); } } |
Spiral Graphics
import java.awt.*; // Draws a spiral - the simplest fractal interation class SpiralCanvas extends Canvas { public SpiralCanvas() { super(); this.setSize(200,200); } public void paint(Graphics g) { double r; int x; int y; int centreOffset = 100; int oldx = centreOffset; int oldy = centreOffset; double PI = 3.141593; double scaleFactor = 2.0; // colour g.setColor(Color.red); for(double i=0; i<16*PI; i += 0.1) { r = scaleFactor * i; x = (int)(r * Math.cos(i)) + centreOffset; y = (int)(r * Math.sin(i)) + centreOffset; g.drawLine(oldx,oldy,x,y); // update previous location oldx = x; oldy = y; } } } |
Spiral Music
import java.awt.Point; import jm.music.data.*; import qt.*; import jm.util.*; class SpiralMusic { public SpiralMusic() { Score s = new Score(); Part p = new Part(); int x; int y; int centreOffset = 100; int oldx = centreOffset; int oldy = centreOffset; double r; double PI = 3.141593; double scaleFactor = 2.0; for(double i=0; i<16*PI; i += 0.1) { r = scaleFactor * i; x = (int)(r * Math.cos(i)) + centreOffset; y = (int)(r * Math.sin(i)) + centreOffset; // do music Phrase phr = new Phrase(); phr.setStartTime((double)x / 16.0); Note n = new Note(127-y/2, 0.125, 100); n.setDuration(1.0/(double)y); phr.addNote(n); p.addPhrase(phr); // update previous location oldx = x; oldy = y; } s.addPart(p); View.show(s, 250,0); // play back with QuickTime immediatly QTUtil qtu = new QTUtil(); qtu.playback(s); // save MIDI file also Write.midi(s, "SpiralMusic.mid"); } } |
Try changing the tempo and instrument to get different effects.
|
|
|
© 2002 Andrew R Brown |
|
|