laporan tugas program clipping

17
0 TUGAS LAPORAN PROGRAM CLIPPING Disusun oleh : M.NEJATULLAH.K (201210370311268) LABORATORIUM REKAYASA PERANGKAT LUNAK TEKNIK INFORMATIKA FAKULTAS TEKNIK UNIVERSITAS MUHAMMADIYAH MALANG

Upload: mn-kautsar

Post on 23-Nov-2015

16 views

Category:

Documents


3 download

DESCRIPTION

grafkom

TRANSCRIPT

  • 0

    TUGAS LAPORAN

    PROGRAM CLIPPING

    Disusun oleh :

    M.NEJATULLAH.K (201210370311268)

    LABORATORIUM REKAYASA PERANGKAT LUNAK

    TEKNIK INFORMATIKA FAKULTAS TEKNIK

    UNIVERSITAS MUHAMMADIYAH MALANG

  • 1

    DAFTAR ISI

    Daftar Isi 1

    A. Source code 2 B. Printscreen Source Code 10 C. Hasil Running (Inputan User) 14

    - Hasil Input 1 14 - Hasil Input 2 14 - Hasil Input 3 14 - Hasil Input 4 14 - Hasil Input 5 15 - Hasil Input 6 15 - Hasil Input 7 15 - Hasil Input 8 15 - Hasil Input 9 16

    D. Printscreen Hasil Akhir

  • 2

    A. SOURCE CODE

    /*

    * To change this template, choose Tools | Templates

    * and open the template in the editor.

    */

    package belajar;

    import java.awt.Color;

    import java.awt.Graphics;

    import java.awt.Graphics2D;

    import java.awt.Rectangle;

    import java.awt.RenderingHints;

    import java.awt.event.ActionEvent;

    import java.awt.event.ActionListener;

    import java.awt.geom.AffineTransform;

    import java.awt.geom.Ellipse2D;

    import java.awt.geom.GeneralPath;

    import javax.swing.JFrame;

    import javax.swing.JOptionPane;

    import javax.swing.JPanel;

    import javax.swing.SwingUtilities;

    import javax.swing.Timer;

  • 3

    /**

    *

    * @author M.n. Kautsar

    */

    public class clipping2 extends JPanel

    implements ActionListener {

    private Timer timer;

    //private double rotate = 1;

    public double delta[] = {1, 1};

    public int radius;

    public int pos_x;

    public int pos_y;

    int rx = 10, ry = 10, rwidth = 20, rheight = 10;

    public clipping2(int pos_x, int pos_y, int radius) {

    this.pos_x = pos_x;

    this.pos_y = pos_y;

    this.radius = radius;

    initTimer();

    }

  • 4

    public void setRect(int rx, int ry, int rwidth, int rheight) {

    this.rx = rx;

    this.ry = ry;

    this.rwidth = rwidth;

    this.rheight = rheight;

    }

    private void initTimer() {

    timer = new Timer(10, this);

    timer.start();

    }

    private void doDrawing(Graphics g) {

    clipping2 clip = new clipping2(this.pos_x, this.pos_y, this.radius);

    Graphics2D g2d = (Graphics2D) g;

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,

    RenderingHints.VALUE_ANTIALIAS_ON);

    g2d.setRenderingHint(RenderingHints.KEY_RENDERING,

    RenderingHints.VALUE_RENDER_QUALITY);

  • 5

    int w = getWidth();

    int h = getHeight();

    Rectangle rect1 = new Rectangle(this.rx, this.ry, this.rwidth, this.rheight);

    AffineTransform tx = new AffineTransform();

    //tx.rotate(Math.toRadians(rotate), w / 2, h / 2);

    tx.translate(w / 2 - 100, h / 2 - 40);

    Ellipse2D circle = new Ellipse2D.Double(pos_x, pos_y, radius, radius);

    step();

    GeneralPath path = new GeneralPath();

    path.append(tx.createTransformedShape(rect1), true);

    g2d.setColor(new Color(110, 110, 110));

    g2d.clip(circle);

    g2d.clip(path);

    g2d.fill(path);

    g2d.setClip(new Rectangle(0, 0, w, h));

    //g2d.draw(circle);

    g2d.draw(path);

    }

  • 6

    @Override

    public void paintComponent(Graphics g) {

    super.paintComponent(g);

    doDrawing(g);

    }

    public void step() {

    int w = getWidth();

    int h = getHeight();

    if (pos_x < 0) {

    delta[0] = 1;

    } else if (pos_x > w - radius) {

    delta[0] = -1;

    }

  • 7

    if (pos_y < 0) {

    delta[1] = 1;

    } else if (pos_y > h - radius) {

    delta[1] = -1;

    }

    pos_x += delta[0];

    pos_y += delta[1];

    }

    @Override

    public void actionPerformed(ActionEvent e) {

    //rotate += 1;

    repaint();

    }

    }

    class ClippingShapes extends JFrame {

  • 8

    public ClippingShapes() {

    initUI();

    }

    private void initUI() {

    setTitle("Clipping shapes");

    JOptionPane.showMessageDialog(null, "set lingkatan");

    int x = Integer.parseInt(JOptionPane.showInputDialog("x"));

    int y = Integer.parseInt(JOptionPane.showInputDialog("y"));

    int r = Integer.parseInt(JOptionPane.showInputDialog("r"));

    JOptionPane.showMessageDialog(null, "set persegi");

    int xp = Integer.parseInt(JOptionPane.showInputDialog("x"));

    int yp = Integer.parseInt(JOptionPane.showInputDialog("y"));

    int rw = Integer.parseInt(JOptionPane.showInputDialog("width"));

    int rh = Integer.parseInt(JOptionPane.showInputDialog("height"));

    clipping2 c = new clipping2(x, y, r);

    c.setRect(xp, yp, rw, rh);

    add(c);

  • 9

    setSize(500, 500);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    setLocationRelativeTo(null);

    }

    public static void main(String[] args) {

    SwingUtilities.invokeLater(new Runnable() {

    @Override

    public void run() {

    ClippingShapes cs = new ClippingShapes();

    cs.setVisible(true);

    }

    });

    }

    }

  • 10

    B. Printscreen Source Code

  • 11

  • 12

  • 13

  • 14

    C. Hasil Running (Inputan user)

    Hasil Input 1

    Hasil Input 2

    Hasil Input 3

    Hasil input 4

  • 15

    Hasil input 5

    Hasil Input 6

    Hasil Input 7

    Hasil Input 8

  • 16

    Hasil Input 9

    D. Hasil akhir