MID GRAFIKA KOMPUTER


MID
GRAFIKA KOMPUTER

Soal :
1. Rotasi
      A(150,100)
      B(100,250)
     C(200,250)  terhadap titik X (200,200) dengan sudut putar 45

2. Translasi terhadap  T(50 & 100) dari kedua nomor tersebut :
a. Buat lisning programnya !
b. Tentukan titik hasil rotasi A translasinya



JAWAB
Lisning soal A

ROTASI

package rotasi;

import java.awt.*;
import java.awt.event.*;
public class Rotasi extends Frame implements ActionListener{
int x = 200;
int y = 200;
public static void main(String[] args) {
Frame frame = new Rotasi();
frame.setSize(200,200);
frame.setVisible(true);
}
public Rotasi() {
setTitle("AWT Demo");
// create menu
MenuBar mb = new MenuBar();
setMenuBar(mb);
Menu menu = new Menu("File");
mb.add(menu);
MenuItem mi = new MenuItem("Exit");
mi.addActionListener(this);
menu.add(mi);
// end program when window is closed
WindowListener l = new WindowAdapter()  {
public void windowClosing(WindowEvent ev) {
System.exit(0);
}
};
this.addWindowListener(l);
// mouse event handler
MouseListener mouseListener = new MouseAdapter() {
public void mouseClicked(MouseEvent ev) {
x = ev.getX();
y = ev.getY();
repaint();
}
};
addMouseListener(mouseListener);
}

public void paint(Graphics g) {
int xasalA = 150; int yasalA = 100;
int xasalB = 100; int yasalB = 250;
int xasalC = 200; int yasalC = 250;


int sudut = 45;

g.setColor(Color.blue);
g.drawLine(xasalA,yasalA, xasalB,yasalB);
g.drawLine(xasalB,yasalB,xasalC,yasalC);

long xA = Math.round(x+(xasalA-x)*Math.cos(sudut)-(yasalA-y)*Math.sin(sudut));
long yA = Math.round(x+(xasalA-x)*Math.sin(sudut)-(yasalA-y)*Math.cos(sudut));
long xB = Math.round(x+(xasalB-x)*Math.cos(sudut)-(yasalB-y)*Math.sin(sudut));
long yB = Math.round(x+(xasalB-x)*Math.sin(sudut)-(yasalB-y)*Math.cos(sudut));
long xC = Math.round(x+(xasalC-x)*Math.cos(sudut)-(yasalC-y)*Math.sin(sudut));
long yC = Math.round(x+(xasalC-x)*Math.sin(sudut)-(yasalC-y)*Math.cos(sudut));

int xA1 = (int)xA; int yA1 = (int)yA;
int xB1 = (int)xB; int yB1 = (int)yB;
int xC1 = (int)xC; int yC1 = (int)yC;

g.drawLine(xA1,yA1, xB1,yB1);
g.drawLine(xB1,yB1, xC1,yC1);



}
public void actionPerformed(ActionEvent ev) {
String command = ev.getActionCommand();
if ("Exit".equals(command)) {
System.exit(0);
}
}
}


                                                                    Hasil Outputnya










TRANSLASI :

package translasi_roswitha;

import java.awt.*;
import java.awt.event.*;
public class Translasi_roswitha extends Frame implements ActionListener{
int x = 50;
int y = 100;
public static void main(String[] args) {
Frame frame = new Translasi_roswitha();
frame.setSize(640, 480);
frame.setVisible(true);
}
public Translasi_roswitha() {
setTitle("AWT Demo");
// create menu
MenuBar mb = new MenuBar();
setMenuBar(mb);
Menu menu = new Menu("File");
mb.add(menu);
MenuItem mi = new MenuItem("Exit");
mi.addActionListener(this);
menu.add(mi);
// end program when window is closed
WindowListener l = new WindowAdapter()  {
public void windowClosing(WindowEvent ev) {
System.exit(0);
}
};
this.addWindowListener(l);
// mouse event handler
MouseListener mouseListener = new MouseAdapter() {
public void mouseClicked(MouseEvent ev) {
int x = 50;
int y = 100;
repaint();
}
};
addMouseListener(mouseListener);
}

public void paint(Graphics g) {

g.drawLine(30, 30, 200, 300);
g.drawLine(30+x, 30+y, 200+x, 300+y);



}
public void actionPerformed(ActionEvent ev) {
String command = ev.getActionCommand();
if ("Exit".equals(command)) {
System.exit(0);
}
}
}
                                                                               Hasil Outputnya





1 komentar:

Blashz mengatakan...

great blog!! Im very2 like this blog.. hope u visit back :)
jual madu hutan asli
citra indah

Posting Komentar