1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JApplet;
public class projet extends JApplet{
static List<point> T=new ArrayList<point>();
static double angle;
static char carCourant;
Image img;
static void avancerCar() {
try {
carCourant = (char) System.in.read();
} catch (java.io.IOException e) {
}
}
static void lireExpression() throws InterruptedException{
if (carCourant=='f'){avancerCar();lireDeplacement();}
else if (carCourant=='r'){avancerCar();lireRotation();}
else throw new Error (" Carac inattendu : ");
}
static void lireDeplacement() throws InterruptedException{
if (Character.isDigit(carCourant)){T.add(new point(Integer.parseInt(carCourant+"")*Math.cos(angle),Integer.parseInt(carCourant+"")*Math.sin(angle)));avancerCar();}
else throw new Error (" Carac inattendu : ");
}
static void lireRotation() throws InterruptedException{
if(Character.isDigit(carCourant)){angle+=Integer.parseInt(carCourant+"");avancerCar();}
else throw new Error (" Carac inattendu : ");
}
public void init(){
img = new BufferedImage(500, 500, BufferedImage.TYPE_INT_RGB);
Graphics g = img.getGraphics();
g.drawString("bonjour", 100, 100);
if (T.size()>1){g.setColor(Color.blue);
for (int i=0;i<T.size()-1;i++){
g.drawLine(T.get(i).abs, T.get(i).ord, T.get(i+1).abs-T.get(i).abs, T.get(i+1).ord-T.get(i).ord);
}
}
paint (g);
}
public void paint(Graphics g){
if (img != null)g.drawImage(img, 0, 0, this);
}
public static void main(String[] args) throws InterruptedException {
avancerCar() ; // initialisation du car courant
T.add(new point(0,0));
while (carCourant != ';'){
lireExpression();
}
for (int i=0;i<T.size();i++){
System.out.println(T.get(i).abs+".."+T.get(i).ord);
}
}
}
class point{
int abs,ord;
public point(double a,double o){abs=(int) (250+a);ord=(int) (250+o);}
} |
Partager