Aziz Dima Putra - Tugas Terstruktur 8 - Komgraf

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Nama : Aziz Dima Putra

NIM : 191011401321

Kelas : 06TPLM008

TUGAS TERSTRUKTUR PERTEMUAN 8

1. Translasi

Tampilan :

Source Code :

package Translasi;

/**
*
* @author AZIZ-PC
*/
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;

public class contohTranslasi extends JPanel {


public static void main(String[] args){
JFrame f = new JFrame("Translasi - Aziz Dima Putra");
contohTranslasi bs = new contohTranslasi();
f.getContentPane().add(bs);
f.setSize(300,300);
f.setBackground(Color.yellow);
f.setVisible(true);
}

public void paintComponent(Graphics g) {


Graphics2D g2d = (Graphics2D) g;

g2d.setColor(Color.magenta);
g2d.fillRect(20, 20, 80, 50);
g2d.translate(100, 100);
g2d.setColor(Color.blue);
g2d.fillRect(20, 20, 80, 50);
g2d.translate(120, 100);
g2d.setColor(Color.gray);
g2d.fillRect(20, 20, 80, 50);
g2d.translate(140, 100);
g2d.setColor(Color.cyan);
g2d.fillRect(20, 20, 80, 50);
g2d.translate(160, 100);
g2d.setColor(Color.green);
g2d.fillRect(20, 20, 80, 50);

}
}
2. Rotasi

Tampilan :

Source Code :

package Translasi;

/**
*
* @author AZIZ-PC
*/
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;

public class rotasi extends JPanel {


public static void main(String[] args){
JFrame f = new JFrame("Rotasi - Aziz Dima Putra");
rotasi bs = new rotasi();
f.getContentPane().add(bs);
f.setSize(300,300);
f.setBackground(Color.yellow);
f.setVisible(true);
}

public void paintComponent(Graphics g) {


Graphics2D g2d = (Graphics2D) g;

g2d.setColor(Color.magenta);
g2d.translate(120, 120);
g2d.fillRect(20, 20, 80 , 50);
g2d.setColor(Color.cyan);
g2d.translate(200, 0);
g2d.rotate(Math.PI/3);
g2d.fillRect(20, 20, 80 , 50);
g2d.setColor(Color.gray);
g2d.translate(180,0);
g2d.rotate(Math.PI/6);
g2d.fillRect(20, 20, 80 , 50);
g2d.setColor(Color.blue);
g2d.translate(200,0);
g2d.rotate(Math.PI/8);
g2d.rotate(Math.toRadians(30));
g2d.fillRect(20, 20, 80 , 50);
g2d.setColor(Color.green);
g2d.translate(200,0);
g2d.rotate(Math.PI/10);
g2d.rotate(Math.toRadians(20));
g2d.fillRect(20, 20, 80 , 50);
}
}
3. Scale/skala

Tampilan :

Source Code :

package Translasi;

/**
*
* @author AZIZ-PC
*/
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;

public class Scale extends JPanel {


public static void main(String[] args){
JFrame f = new JFrame("Scale - Aziz Dima Putra");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Scale sc = new Scale();
f.getContentPane().add(sc);
f.setSize(300,300);
f.setBackground(Color.yellow);
f.setVisible(true);
}

public void paintComponent(Graphics g) {


Graphics2D g2d = (Graphics2D) g;

g2d.setColor(Color.magenta);
g2d.drawOval(20, 20, 30, 30);
g2d.scale(2, 2);
g2d.translate(20, 20);

g2d.setColor(Color.green);
g2d.drawOval(20, 20, 30, 30);
g2d.scale(2, 2);
g2d.translate(20, 20);

g2d.setColor(Color.blue);
g2d.drawOval(20, 20, 30, 30);
g2d.scale(2, 2);
g2d.translate(20, 20);

g2d.setColor(Color.red);
g2d.drawOval(20, 20, 30, 30);
g2d.scale(2, 2);
g2d.translate(20, 20);

}
}

You might also like