第9回 カオスの音楽
import jm.JMC;
import jm.util.*;
import jm.music.data.*;
import jm.midi.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.applet.Applet;
/*<applet code = "Chaos_Applet3" archive="./jmusic.jar" width=500 height=300></applet>*/
public final class Chaos_Applet3 extends Applet implements JMC, ActionListener {
private Button playBtn; // 後から付加
Score score = new Score("JMDemo - Chaos", 300);
Part inst = new Part("Piano", PIANO, 0);
Phrase phr = new Phrase(0.0);
double xold = 0.0; // initial x position
double x, y; // temp variables
double yold = 0.0; // initial y position
double a = 1.4; // first constant. For oscillation try 1.04
double b = 0.3; //second constant. For oscillation try 0.3
public static void main(String[] args){
Applet applet = new Chaos_Applet3();
Frame frame = new Frame("Chaos_Applet3");
// frame.add("Center", applet);
frame.add(applet);
// ウインドウを閉じた時にアプリケーションが終了するための仕掛け。
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setSize(600,500);
frame.setVisible(true);
// frame.show();
applet.init();
applet.start();
}
public void init() {
setBackground(Color.orange);
playBtn = new Button("Play");
playBtn.addActionListener(this); // addActionListenerメソッドの引数には、
// このイベントを処理するリスナーのクラスを指定
this.add(playBtn);
}
// playBtnが押された時に、compose()メソッドを実行する。
public void actionPerformed( ActionEvent e ) {
if ( e.getSource() == playBtn) {
compose();
}
}
/**
* Create a new score.
*/
private void compose() {
inst.addPhrase(phr);
score.addPart(inst);
// Write.midi(score, "Chaos_Applet3.mid");
View.notate(score); // 後から付加 ボタンを押すとスコアが表示される
}
public void paint(Graphics g) {
g.setColor(Color.blue);
// create a phrase of chaotically pitched quavers over a limited MIDI range.
for(short i=0;i<100;i++){
x = 1 + yold - a * xold * xold;
y = b * xold;
// map the x value across a few octaves
Note note = new Note((int)(x*36)+48, Q);
phr.addNote(note);
Dimension d = getSize();
g.fillRect((int)(100*x+d.width/2),(int)(100*y+d.height/2),3,3);
xold = x;
yold = y;
}
}
}
第10回 カオスの音楽2
例題
import jm.JMC;
import jm.util.*;
import jm.music.data.*;
import jm.midi.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.applet.Applet;
/*<applet code = "ChaosAttractor1" archive="./jmusic.jar" width=500 height=700></applet>*/
public final class ChaosAttractor1 extends Applet implements JMC, ActionListener {
private Button playBtn; // 後から付加
Score score = new Score("JMDemo - Chaos", 300);
Part inst = new Part("Piano", PIANO, 0);
Phrase phr = new Phrase(0.0);
double xold = 0.1; // initial x position
double x, y; // temp variables
double yold = 0.1; // initial y position
double a = 0.6; // first constant. For oscillation try 1.04
double b = 4.5; //second constant. For oscillation try 0.3
public static void main(String[] args){
Applet applet = new ChaosAttractor1();
Frame frame = new Frame("ChaosAttractor1");
frame.add("Center", applet);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setSize(600,1000);
frame.setVisible(true);
// frame.show();
applet.init();
applet.start();
}
public void init() {
setBackground(Color.orange);
playBtn = new Button("Play");
playBtn.addActionListener(this);
this.add(playBtn);
}
public void actionPerformed( ActionEvent e ) {
if ( e.getSource() == playBtn) {
compose();
}
}
/**
* Create a new score.
*/
private void compose() {
inst.addPhrase(phr);
score.addPart(inst);
// Write.midi(score, "ChaosAttractor1.mid");
View.notate(score); // 後から付加 ボタンを押すとスコアが表示される
}
public void paint(Graphics g) {
g.setColor(Color.blue);
// create a phrase of chaotically pitched quavers over a limited MIDI range.
for(short i=0;i<500;i++){
// x = a*xold - xold*yold;
// y = b*yold + xold*xold;
x = yold + a*xold +b/(1+xold*xold) ;
y = -xold;
// map the x value across a few octaves
Note note = new Note((int)(x)+60, Q);
System.out.println(" x= " +x);
System.out.println(" y= " +y);
System.out.println(" note= " +note);
phr.addNote(note);
Dimension d = getSize();
g.fillRect((int)(10*x+d.width/2),(int)(10*y+d.height/2),3,3);
xold = x;
yold = y;
}
}
}
*********************************************************************************************************************************
import jm.JMC;
import jm.util.*;
import jm.music.data.*;
import jm.midi.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.applet.Applet;
/*<applet code = "ChaosAttractor3" archive="./jmusic.jar" width=500 height=700></applet>*/
public final class ChaosAttractor3 extends Applet implements JMC, ActionListener {
private Button playBtn; // 後から付加
Score score = new Score("JMDemo - Chaos", 300);
Part inst = new Part("Piano", PIANO, 0);
Phrase phr = new Phrase(0.0);
double xold = 0.1; // initial x position
double x, y; // temp variables
double yold = 0.1; // initial y position
double a = -0.5; // first constant. For oscillation try 1.04
double b = 0.9; //second constant. For oscillation try 0.3
double c = 10.0; //second constant. For oscillation try 0.3
public static void main(String[] args){
Applet applet = new ChaosAttractor3();
Frame frame = new Frame("ChaosAttractor3");
frame.add("Center", applet);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setSize(600,1000);
frame.setVisible(true);
// frame.show();
applet.init();
applet.start();
}
public void init() {
setBackground(Color.orange);
playBtn = new Button("Play");
playBtn.addActionListener(this);
this.add(playBtn);
}
public void actionPerformed( ActionEvent e ) {
if ( e.getSource() == playBtn) {
compose();
}
}
/**
* Create a new score.
*/
private void compose() {
inst.addPhrase(phr);
score.addPart(inst);
// Write.midi(score, "ChaosAttractor3.mid");
View.notate(score); // 後から付加 ボタンを押すとスコアが表示される
}
public void paint(Graphics g) {
g.setColor(Color.blue);
// create a phrase of chaotically pitched quavers over a limited MIDI range.
for(short i=0;i<500;i++){
// x = a*xold - xold*yold;
// y = b*yold + xold*xold;
// x = yold + a*xold +b/(1+xold*xold) ;
// y = -xold;
x =a*xold + b*yold +c/(1+xold*xold) ;
y = -xold;
// map the x value across a few octaves
Note note = new Note((int)(x*2)+60, Q);
System.out.println(" x= " +x);
System.out.println(" y= " +y);
System.out.println(" note= " +note);
phr.addNote(note);
Dimension d = getSize();
g.fillRect((int)(20*x+d.width/2),(int)(20*y+d.height/2),3,3);
xold = x;
yold = y;
}
}
}
*********************************************************************************************************************************
import jm.JMC;
import jm.util.*;
import jm.music.data.*;
import jm.midi.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
/*<applet code = "Chaos_test" archive="./jmusic.jar" archive="./inst.jar" width=500 height=300></applet>*/
public final class Chaos_test extends Applet implements JMC{
Score score = new Score("JMDemo - Chaos", 300);
Part inst = new Part("Piano", PIANO, 0);
Phrase phr = new Phrase(0.0);
double xold; // initial x position
double w1, w2, x, y, xmax, ymax, xmin, ymin; // temp variables
double yold; // initial y position
double k; //-1と1の間の数
public static void main(String[] args){
Applet applet = new Chaos_test();
Frame frame = new Frame("Chaos_test");
frame.add("Center", applet);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setSize(600,500);
frame.setVisible(true);
applet.init();
applet.start();
}
public void init() {
setBackground(Color.lightGray);
xold = 0.1; // initial x position
yold = 0.1; // initial y position
k = -0.85;
}
public void start() {
// System.out.println(" start() is called.");
inst.addPhrase(phr);
score.addPart(inst);
// Write.midi(score, "Chaos_AppletTest2");
View.notate(score); // 後から付加
}
public void paint(Graphics g) {
g.setColor(Color.blue);
xmax = 0.0;
ymax = 0.0;
xmin = 0.0;
ymin = 0.0;
// create a phrase of chaotically pitched quavers over a limited MIDI range.
for(short i=0;i<1000;i++){
//
w1 = k*xold+2*(1-k)*xold*xold/(1+xold*xold) ;
x = yold+ 0.008*(1-0.05*yold*yold)*yold+ w1;
w2 = k*x+2*(1-k)*x*x/(1+x*x) ;
y = -xold +w2;
if(x>xmax) xmax = x;
if(y>ymax) ymax = y;
if(x<xmin) xmin = x;
if(y<ymin) ymin = y;
System.out.println(" x+60= "+ (x+60));
System.out.println(" y+60= "+ (y+60));
// map the x value across a few octaves
Note note = new Note((int)(x+60), Q);
phr.addNote(note);
Dimension d = getSize();
// g.fillRect((int)(80*x+d.width/2),(int)(80*y+d.height/2),3,3);
g.fillRect((int)(10*x+d.width/2),(int)(10*y+d.height/2),3,3);
xold = x;
yold = y;
}
System.out.println(" xmax= "+ xmax);
System.out.println(" ymax= "+ ymax);
System.out.println(" xmin= "+ xmin);
System.out.println(" ymin= "+ ymin);
}
}