From Sodawiki
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
import javax.swing.event.*;
import java.applet.*;
import java.awt.event.*;
import java.math.*;
import java.util.Hashtable;
import java.lang.Math;
/*********************************************/
/** Author: Colin Stanfill */
/** Inspired by Sodaconstructor by Ed Burton */
/*********************************************/
public class Soda extends JApplet implements MouseListener, Runnable, ActionListener, ChangeListener, MouseMotionListener, KeyListener{
Thread t;
public double[][] masses=new double[1000][7];
public double[][] springs=new double[1000][7];
public MVector vectora, vectorb;
public String mode="Construct", mamode="Free Mass", spmode="Normal";
public int spd=24, Tempi, foundm, founds, mx, my, numberofsprings=0, numberofmasses=0, width, height, MASS, disp, mou , mouseY;
public double g=4.0, f=41, k=40, v=50, Tempd, fbounce=1.7;
public boolean MassFound=false, MakingSpring=false, SpringFound=false, QQ=false;
public JRadioButton Simulate, Construct, Delete, New, FreeMass, FixedMass, Normal, Barspring;
public JMenu ModeMenu, MassMenu, SpringMenu;
public JMenuBar Bar, Bar2;
public JFrame Sliders;
public JSlider gravity, friction, springiness, fps, velocity;
public SinePanel Panel1;
public static void main(String[] args) {
}
public void init() {
this.setVisible(true);
addMouseListener(this);
addMouseMotionListener(this);
addKeyListener(this);
setBackground(Color.white);
width=getSize().width;
height=getSize().height;
t=new Thread(this);
t.start();
this.setJMenuBar(MakeMenuBar());
Sliders=new JFrame("Sliders");
Sliders.setJMenuBar(MakeMenuBar2());
Sliders.setVisible(true);
Sliders.setSize(150, 400);
Panel1=new SinePanel();
Panel1.setVisible(true);
Panel1.setSize(150, 400);
Panel1.addMouseListener(Panel1);
Panel1.addMouseMotionListener(Panel1);
Panel1.setLocation(width, 0);
Sliders.setLocation(width+150, 0);
}
public JMenuBar MakeMenuBar() {
JRadioButton Simulate=new JRadioButton("Simulate");
JRadioButton Construct=new JRadioButton("Construct");
JRadioButton Delete=new JRadioButton("Delete");
JRadioButton New=new JRadioButton("New");
JRadioButton FreeMass=new JRadioButton("Free Mass");
JRadioButton FixedMass=new JRadioButton("Fixed Mass");
JRadioButton Normal=new JRadioButton("Normal");
JRadioButton Barspring=new JRadioButton("Barspring");
ButtonGroup Mode=new ButtonGroup();
ButtonGroup Masses=new ButtonGroup();
ButtonGroup Springs=new ButtonGroup();
JMenu ModeMenu=new JMenu("Mode");
JMenu MassMenu=new JMenu("Masses");
JMenu SpringMenu=new JMenu("Springs");
JMenuBar Bar=new JMenuBar();
Bar.add(ModeMenu);
Bar.add(MassMenu);
Bar.add(SpringMenu);
ModeMenu.add(Simulate);
ModeMenu.add(Construct);
ModeMenu.add(Delete);
ModeMenu.add(New);
MassMenu.add(FreeMass);
MassMenu.add(FixedMass);
SpringMenu.add(Normal);
SpringMenu.add(Barspring);
Mode.add(Simulate);
Mode.add(Construct);
Mode.add(Delete);
Mode.add(New);
Masses.add(FreeMass);
Masses.add(FixedMass);
Springs.add(Normal);
Springs.add(Barspring);
Construct.setSelected(true);
FreeMass.setSelected(true);
Normal.setSelected(true);
Simulate.addActionListener(this);
Construct.addActionListener(this);
Delete.addActionListener(this);
New.addActionListener(this);
FreeMass.addActionListener(this);
FixedMass.addActionListener(this);
Normal.addActionListener(this);
Barspring.addActionListener(this);
ModeMenu.addActionListener(this);
Simulate.setActionCommand("Simulate");
Construct.setActionCommand("Construct");
Delete.setActionCommand("Delete");
FreeMass.setActionCommand("Free Mass");
FixedMass.setActionCommand("Fixed Mass");
Normal.setActionCommand("Normal");
Barspring.setActionCommand("Barspring");
return Bar;
}
public JMenuBar MakeMenuBar2() {
Hashtable<Integer, JLabel> lT1 = new Hashtable<Integer, JLabel>();
Hashtable<Integer, JLabel> lT2 = new Hashtable<Integer, JLabel>();
Hashtable<Integer, JLabel> lT3 = new Hashtable<Integer, JLabel>();
Hashtable<Integer, JLabel> lT4 = new Hashtable<Integer, JLabel>();
Hashtable<Integer, JLabel> lT5 = new Hashtable<Integer, JLabel>();
lT1.put(new Integer (0),new JLabel("G"));
lT2.put(new Integer (0),new JLabel("F"));
lT3.put(new Integer (0),new JLabel("K"));
lT4.put(new Integer (0),new JLabel("Speed"));
lT5.put(new Integer (0),new JLabel("V"));
JSlider gravity=new JSlider(JSlider.VERTICAL, 0, 102, 40);
JSlider friction=new JSlider(JSlider.VERTICAL, 0, 100, 41);
JSlider springiness=new JSlider(JSlider.VERTICAL, 0, 99, 40);
JSlider fps=new JSlider(JSlider.VERTICAL, 0, 300, 124);
JSlider velocity=new JSlider(JSlider.VERTICAL, 0, 101, 50);
gravity.setLabelTable(lT1);
gravity.setPaintLabels(true);
friction.setLabelTable(lT2);
friction.setPaintLabels(true);
springiness.setLabelTable(lT3);
springiness.setPaintLabels(true);
fps.setLabelTable(lT4);
fps.setPaintLabels(true);
velocity.setLabelTable(lT5);
velocity.setPaintLabels(true);
JMenuBar Bar2=new JMenuBar();
Bar2.add(gravity);
Bar2.add(friction);
Bar2.add(springiness);
Bar2.add(velocity);
Bar2.add(fps);
gravity.addChangeListener(this);
friction.addChangeListener(this);
springiness.addChangeListener(this);
fps.addChangeListener(this);
velocity.addChangeListener(this);
return Bar2;
}
public void mouseClicked (MouseEvent me) {
mx=me.getX();
my=me.getY();
MassFound=false;
for(int i=0; i<numberofmasses+1;i++) {
if(mx>masses[i][0]) {
if(mx-10<masses[i][0]) {
if(my>masses[i][1]) {
if(my-10<masses[i][1]) {
foundm=i;
MassFound=true;
}
}
}
}
}
SpringFound=false;
for(int i=0;i<numberofsprings;i++) {
double a=((masses[(int)springs[i][0]][1]-masses[(int)springs[i][1]][1])/(masses[(int)springs[i][0]][0]-masses[(int)springs[i][1]][0]));
double b=((masses[(int)springs[i][0]][1]-masses[(int)springs[i][0]][0]*a));
double q=0;
double u=0;
double w=0;
double m=0;
if(masses[(int)springs[i][0]][0]>masses[(int)springs[i][1]][0]) {
q=masses[(int)springs[i][0]][0];
u=masses[(int)springs[i][1]][0];
} else {
q=masses[(int)springs[i][1]][0];
u=masses[(int)springs[i][0]][0];
}
if(masses[(int)springs[i][0]][1]>masses[(int)springs[i][1]][1]) {
w=masses[(int)springs[i][0]][1];
m=masses[(int)springs[i][1]][1];
} else {
w=masses[(int)springs[i][1]][1];
m=masses[(int)springs[i][0]][1];
}
if(my-5<a*mx+b) {
if(my+5>a*mx+b) {
if(mx<q) {
if(mx>u) {
if(my<w) {
if(my>m) {
if(MakingSpring==false) {
founds=i;
SpringFound=true;
}
}
}
}
}
}
}
}
if(MassFound==true) {
SpringFound=false;
}
if(SpringFound==false) {
if(MassFound==false) {
if(mode=="Construct"){
masses[numberofmasses][0]=mx;
masses[numberofmasses][1]=my;
masses[numberofmasses][6]=1;
int Tempi=0;
if(mamode=="Fixed Mass") {
Tempi=1;
}
masses[numberofmasses][4]=Tempi;
numberofmasses++;
if(MakingSpring==true) {
springs[numberofsprings][1]=numberofmasses-1;
double Tempd=Math.sqrt((masses[(int)springs[numberofsprings][0]][0]-masses[(int)springs[numberofsprings][1]][0])*(masses[(int)springs[numberofsprings][0]][0]-masses[(int)springs[numberofsprings][1]][0])+(masses[(int)springs[numberofsprings][0]][1]- masses[(int)springs[numberofsprings][1]][1])*(masses[(int)springs[numberofsprings][0]][1]- masses[(int)springs[numberofsprings][1]][1]));
springs[numberofsprings][2]=Tempd;
springs[numberofsprings][3]=Tempd;
springs[numberofsprings][6]=1;
if(spmode=="Barspring") {
if(masses[(int)springs[numberofsprings][0]][4]*masses[(int)springs[numberofsprings][1]][4]==1) {
springs[numberofsprings][4]=1;
}
}
numberofsprings++;
MakingSpring=false;
}
}
}
} else {
if(mode=="Delete") {
springs[founds][6]=0;
} else if(mode=="Construct") {
boolean MF=false;
for(int i=0;i<Panel1.numberofmuscles;i++) {
if(Panel1.muscles[i][0]==founds) {
MF=true;
}
}
if(MF==false) {
Panel1.NewMuscle(founds);
}
} else if(mode=="Simulate") {
boolean MF=false;
for(int i=0;i<Panel1.numberofmuscles;i++) {
if(Panel1.muscles[i][0]==founds) {
MF=true;
}
}
if(MF==false) {
Panel1.NewMuscle(founds);
}
}
}
if(MassFound==true) {
if(mode=="Construct") {
if(MakingSpring==false) {
springs[numberofsprings][0]=foundm;
MakingSpring=true;
} else {
springs[numberofsprings][1]=foundm;
MakingSpring=false;
double Tempd=Math.sqrt((masses[(int)springs[numberofsprings][0]][0]-masses[(int)springs[numberofsprings][1]][0])*(masses[(int)springs[numberofsprings][0]][0]-masses[(int)springs[numberofsprings][1]][0])+(masses[(int)springs[numberofsprings][0]][1]- masses[(int)springs[numberofsprings][1]][1])*(masses[(int)springs[numberofsprings][0]][1]- masses[(int)springs[numberofsprings][1]][1]));
springs[numberofsprings][2]=Tempd;
springs[numberofsprings][3]=Tempd;
if(spmode=="Barspring") {
if(masses[(int)springs[numberofsprings][0]][4]*masses[(int)springs[numberofsprings][1]][4]==1) {
springs[numberofsprings][4]=1;
}
}
springs[numberofsprings][6]=1;
numberofsprings++;
}
} else if(mode=="Delete") {
masses[foundm][6]=0;
for(int i=0;i<numberofsprings;i++) {
if(springs[i][0]==foundm) {
springs[i][6]=0;
}
if(springs[i][1]==foundm) {
springs[i][6]=0;
}
}
}
MassFound=false;
}
repaint();
}
public void mouseEntered (MouseEvent me) {}
public void mousePressed (MouseEvent me) {
mx=me.getX();
my=me.getY();
MassFound=false;
MASS=0-1;
for(int i=0; i<numberofmasses+1;i++) {
if(mx+10>masses[i][0]) {
if(mx-10<masses[i][0]) {
if(my+10>masses[i][1]) {
if(my-10<masses[i][1]) {
MASS=i;
MassFound=true;
}
}
}
}
}
}
public void mouseReleased (MouseEvent me) {
masses[MASS][5]=0;
MASS=0-1;
}
public void mouseExited (MouseEvent me) {}
public void mouseMoved (MouseEvent me) {
mou =me.getX();
mouseY=me.getY();
}
public void keyPressed (KeyEvent ke) {}
public void keyReleased (KeyEvent ke) {}
public void mouseDragged (MouseEvent me) {
if(!(MASS==0-1)) {
masses[MASS][0]=me.getX()-5;
masses[MASS][1]=me.getY()-5;
masses[MASS][2]=0;
masses[MASS][3]=0;
masses[MASS][5]=1;
repaint();
}
}
public void stateChanged(ChangeEvent ce){
JSlider source=(JSlider)ce.getSource();
if(source.getMaximum()==102) {
g=source.getValue()/10 ;
} else if(source.getMaximum()==100) {
f=source.getValue();
} else if(source.getMaximum()==99) {
k=source.getValue();
} else if(source.getMaximum()==300) {
if(!(source.getValue()==0)) {
spd=(3000/source.getValue());
}
} else if(source.getMaximum()==101) {
v=source.getValue()-1;
}
}
public void keyTyped(KeyEvent ke) {
char c=ke.getKeyChar();
if(c=='s') {
mode="Simulate";
} else if(c=='c') {
mode="Construct";
} else if(c=='d') {
mode="Delete";
} else if(c=='q') {
mamode="Free Mass";
} else if(c=='w') {
mamode="Fixed Mass";
} else if(c=='e') {
spmode="Normal";
} else if(c=='r') {
spmode="Barspring";
}
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand()=="Free Mass") {
mamode="Free Mass";
} else if(e.getActionCommand()=="Fixed Mass") {
mamode="Fixed Mass";
} else if(e.getActionCommand()=="Normal") {
spmode="Normal";
} else if(e.getActionCommand()=="Barspring") {
spmode="Barspring";
} else {
mode=e.getActionCommand();
}
if(mode=="New") {
for(int i=0;i<numberofmasses;i++) {
for(int j=0;j<6;j++) {
masses[i][j]=0;
}
}
for(int i=0;i<numberofsprings;i++) {
for(int j=0;j<6;j++) {
springs[i][j]=0;
}
}
numberofmasses=0;
numberofsprings=0;
mode="Construct";
}
}
public void UpdatePhysics() {
MakingSpring=false;
for(int i=0;i<Panel1.numberofmuscles;i++) {
springs[(int)Panel1.muscles[i][0]][2]=springs[(int)Panel1.muscles[i][0]][3]+springs[(int)Panel1.muscles[i][0]][3]*((double)Panel1.muscles[i][2]/60)*(.5+Math.sin((Math.PI/180)*(Panel1.disp+Panel1.muscles[i][1])));
}
for(int i=0;i<numberofsprings;i++) {
if(springs[i][6]==1) {
if((masses[(int)springs[i][0]][4])+(masses[(int)springs[i][0]][5])>0) {
double a=masses[(int)springs[i][1]][0];
double b=masses[(int)springs[i][1]][1];
double c=masses[(int)springs[i][0]][0];
double d=masses[(int)springs[i][0]][1];
double m=Math.sqrt((a-c)*(a-c)+(b-d)*(b-d));
double n=springs[i][2];
double o=m-n;
o=0-k*o/198;
masses[(int)springs[i][1]][2]=((masses[(int)springs[i][1]][2]+(a-c)*o/m))*(1-f/100);
masses[(int)springs[i][1]][3]=((masses[(int)springs[i][1]][3]+(b-d)*o/m))*(1-f/100);
}
if((masses[(int)springs[i][1]][4])+(masses[(int)springs[i][1]][5])>0) {
double a=masses[(int)springs[i][0]][0];
double b=masses[(int)springs[i][0]][1];
double c=masses[(int)springs[i][1]][0];
double d=masses[(int)springs[i][1]][1];
double m=Math.sqrt((a-c)*(a-c)+(b-d)*(b-d));
double n=springs[i][2];
double o=m-n;
o=0-k*o/198;
masses[(int)springs[i][0]][2]=((masses[(int)springs[i][0]][2]+(a-c)*o/m))*(1-f/100);
masses[(int)springs[i][0]][3]=((masses[(int)springs[i][0]][3]+(b-d)*o/m))*(1-f/100);
}
if(masses[(int)springs[i][1]][4]*masses[(int)springs[i][0]][4]*masses[(int)springs[i][1]][5]*masses[(int)springs[i][0]][5]==0) {
double a=masses[(int)springs[i][0]][0];
double b=masses[(int)springs[i][0]][1];
double c=masses[(int)springs[i][1]][0];
double d=masses[(int)springs[i][1]][1];
double m=Math.sqrt((a-c)*(a-c)+(b-d)*(b-d));
double n=springs[i][2];
double o=m-n;
o=0-k*o/396;
masses[(int)springs[i][0]][2]=(masses[(int)springs[i][0]][2]+(a-c)*o/m)*(1-f/100);
masses[(int)springs[i][0]][3]=(masses[(int)springs[i][0]][3]+(b-d)*o/m)*(1-f/100);
masses[(int)springs[i][1]][2]=(masses[(int)springs[i][1]][2]-(a-c)*o/m)*(1-f/100);
masses[(int)springs[i][1]][3]=(masses[(int)springs[i][1]][3]-(b-d)*o/m)*(1-f/100);
}
}
}
for(int i=0;i<numberofmasses;i++) {
if(masses[i][4]==0) {
if(masses[i][5]==0) {
if(masses[i][6]==1) {
double mmmx=masses[i][0];
double mmmy=masses[i][1];
masses[i][3]+=g;
double mmx=masses[i][0]+masses[i][2];
double mmy=masses[i][1]+masses[i][3];
for(int j=0;j<numberofsprings;j++) {
if(masses[(int)springs[j][0]][0]-masses[(int)springs[j][1]][0]==0) {
QQ=true;
masses[(int)springs[j][0]][0]+=0.0001;
}
double a=(masses[(int)springs[j][0]][1]-masses[(int)springs[j][1]][1])/(masses[(int)springs[j][0]][0]-masses[(int)springs[j][1]][0]);
double b=masses[(int)springs[j][0]][1]-masses[(int)springs[j][0]][0]*a;
double q=0;
double u=0;
double w=0;
double m=0;
if(masses[(int)springs[j][0]][0]>masses[(int)springs[j][1]][0]) {
q=masses[(int)springs[j][0]][0];
u=masses[(int)springs[j][1]][0];
} else {
q=masses[(int)springs[j][1]][0];
u=masses[(int)springs[j][0]][0];
}
if(masses[(int)springs[j][0]][1]>masses[(int)springs[j][1]][1]) {
w=masses[(int)springs[j][0]][1];
m=masses[(int)springs[j][1]][1];
} else {
w=masses[(int)springs[j][1]][1];
m=masses[(int)springs[j][0]][1];
}
if(QQ==true) {
masses[(int)springs[j][0]][0]-=0.0001;
}
QQ=false;
if(mmmy<mmmx*a+b) {
if(mmy>mmx*a+b) {
QQ=true;
}
}
if(mmmy>mmmx*a+b) {
if(mmy<mmx*a+b) {
QQ=true;
}
}
SpringFound=false;
if(QQ==true) {
if(mmx<q) {
if(mmx>u) {
if(mmy<w) {
if(mmy>m) {
if(springs[j][4]==1) {
founds=i;
SpringFound=true;
}
}
}
}
}
}
if(SpringFound==true) {
vectora=new MVector(masses[i][2], masses[i][3], fbounce);
vectorb=new MVector(masses[(int)springs[j][0]][0]-masses[(int)springs[j][1]][0], masses[(int)springs[j][0]][1]-masses[(int)springs[j][1]][1], fbounce);
vectorb.Bounce(vectora);
masses[i][2]=vectora.VX;
masses[i][3]=vectora.VY;
}
}
}
}
}
}
for(int i=0;i<numberofmasses;i++) {
if(masses[i][4]==0) {
if(masses[i][5]==0) {
masses[i][2]=masses[i][2]*(1-f/100);
masses[i][3]=masses[i][3]*(1-f/100);
masses[i][0]=masses[i][0]+masses[i][2];
masses[i][1]=masses[i][1]+masses[i][3];
if(masses[i][1]>height-30) {
masses[i][1]=height-30;
masses[i][3]=0-masses[i][3];
} else if(masses[i][1]<30) {
masses[i][1]=30;
masses[i][3]=0-masses[i][3];
}
if(masses[i][0]>width-30) {
masses[i][0]=width-30;
masses[i][2]=0-masses[i][2];
} else if(masses[i][0]<30) {
masses[i][0]=30;
masses[i][2]=0-masses[i][2];
}
}
}
}
repaint();
disp+=(v/10);
if(disp>360) {
disp-=360;
}
Panel1.disp=disp;
Panel1.repaint();
}
public void paint(Graphics g) {
super.paint(g);
if(MakingSpring==true) {
g.drawLine(mou , mouseY, (int)masses[(int)springs[numberofsprings][0]][0]+5, (int)masses[(int)springs[numberofsprings][0]][1]+5);
}
for(int i=0; i<numberofmasses; i++) {
if(masses[i][6]==1) {
if(masses[i][4]==0) {
g.fillOval((int)masses[i][0],(int)masses[i][1], 10, 10 );
}
if(masses[i][4]==1) {
g.fillRect((int)masses[i][0],(int)masses[i][1], 10, 10 );
}
}
}
for(int i=0;i<numberofsprings;i++) {
if(springs[i][6]==1) {
if(springs[i][4]==1) {
g.setColor(Color.blue);
}
g.drawLine((int)masses[(int)springs[i][0]][0]+5, (int)masses[(int)springs[i][0]][1]+5, (int)masses[(int)springs[i][1]][0]+5, (int)masses[(int)springs[i][1]][1]+5);
g.setColor(Color.black);
}
}
for(int i=0; i<Panel1.numberofmuscles;i++) {
g.setColor(Color.red);
double XA=masses[(int)springs[(int)Panel1.muscles[i][0]][0]][0]+2;
double XB=masses[(int)springs[(int)Panel1.muscles[i][0]][1]][0]+2;
double YA=masses[(int)springs[(int)Panel1.muscles[i][0]][0]][1]+2;
double YB=masses[(int)springs[(int)Panel1.muscles[i][0]][1]][1]+2;
g.fillOval((int)(XA+XB)/2, (int)(YA+YB)/2, 6, 6);
g.setColor(Color.black);
}
if(!(Panel1.MUSCL==0-1)) {
int i=Panel1.MUSCL;
g.setColor(Color.green);
double XA=masses[(int)springs[(int)Panel1.muscles[i][0]][0]][0]+2;
double XB=masses[(int)springs[(int)Panel1.muscles[i][0]][1]][0]+2;
double YA=masses[(int)springs[(int)Panel1.muscles[i][0]][0]][1]+2;
double YB=masses[(int)springs[(int)Panel1.muscles[i][0]][1]][1]+2;
g.fillOval((int)(XA+XB)/2, (int)(YA+YB)/2, 6, 6);
g.setColor(Color.black);
}
}
public void run() {
while(true){
if(mode=="Simulate") {
UpdatePhysics();
}
repaint();
try{
t.sleep(spd);
}
catch(InterruptedException e) {
}
}
}
}
class MVector {
double VX, VY, Length, NVY, NVX, dot, fbounce;
public MVector(double x, double y, double f) {
VX=x;
VY=y;
Length=Math.sqrt(Math.pow(x,2)+Math.pow(y,2));
NVX=x/Length;
NVY=y/Length;
fbounce=f;
}
public double Dot(MVector Q) {
return Q.VX*this.VX+Q.VY*this.VY;
}
public double NDot(MVector Q) {
return Q.VX*this.NVX+Q.VY*this.NVY;
}
public void Bounce(MVector Q) {
dot=this.NDot(Q);
Q.VX=fbounce*dot*NVX-Q.VX;
Q.VY=fbounce*dot*NVY-Q.VY;
}
}
class SinePanel extends JFrame implements MouseListener, MouseMotionListener{
public int width, height, disp, MUSCLE=0-1, MUSCL=0-1, mx, my, numberofmuscles=0;
public int[][] muscles=new int[1000][4];
public boolean MuscleFound, MuscleMade;
public void init() {
this.addMouseListener(this);
this.addMouseMotionListener(this);
setBackground(Color.white);
width=getSize().width;
height=getSize().height;
}
public void NewMuscle(int s) {
muscles[numberofmuscles][0]=s;
muscles[numberofmuscles][1]=150;
muscles[numberofmuscles][2]=50;
muscles[numberofmuscles][3]=1;
numberofmuscles++;
}
public void mouseClicked(MouseEvent me) {
}
public void mouseExited(MouseEvent me) {}
public void mouseEntered(MouseEvent me) {}
public void mousePressed(MouseEvent me) {
mx=me.getX();
my=me.getY();
MuscleFound=false;
MUSCLE=0-1;
for(int i=0; i<numberofmuscles+1;i++) {
if(my+10>muscles[i][1]) {
if(my-10<muscles[i][1]) {
MUSCLE=i;
MuscleFound=true;
}
}
}
}
public void mouseMoved(MouseEvent me) {
mx=me.getX();
my=me.getY();
MuscleFound=false;
MUSCL=0-1;
for(int i=0; i<numberofmuscles+1;i++) {
if(my+10>muscles[i][1]) {
if(my-10<muscles[i][1]) {
MUSCL=i;
MuscleFound=true;
}
}
}
}
public void mouseDragged(MouseEvent me) {
if(!(MUSCLE==0-1)) {
muscles[MUSCLE][1]=me.getY();
muscles[MUSCLE][2]=me.getX();
if(muscles[MUSCLE][2]>60) {
muscles[MUSCLE][2]=60;
}
if(muscles[MUSCLE][2]<0) {
muscles[MUSCLE][2]=0;
}
repaint();
}
}
public void mouseReleased(MouseEvent me) {
MUSCLE=0-1;
}
public void paint(Graphics g) {
super.paint(g);
int oldX = 0;
int oldY = 0;
double radians;
double cvtDegToRad=Math.PI/180;
int x;
int axis=(int)width/2;
g.setColor(Color.red);
for (int y=0; y<720; y++) {
radians = (y+disp)*cvtDegToRad;
x = (int)(60*Math.sin(radians) );
g.drawLine(oldX/2+30, (int)((oldY+axis+20)/2), x/2+30, (int)((axis+y+20)/2));
oldY = y;
oldX = x;
}
for(int i=0;i<numberofmuscles+1;i++) {
g.drawLine(0, muscles[i][1], 60, muscles[i][1]);
g.fillOval(muscles[i][2], muscles[i][1]-2, 4, 4);
}
}
}