Blogger Tricks

PROJECT UAS GRAFIKA KOMPUTER (BERNARD R.F. NAY 13110269)


 tugas project uas grafika komputer dimana membuat animasi gerak menggunakan object atau charakter pada netbeans.

codingnya :
 // bernardpunk coding
//animasi kincir angin

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.GeneralPath;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JPanel;


 public class KipasAngin extends JPanel implements Runnable  {
private int x = 0;
    int x2 = 255;
    int x3 = 255;
    Thread th = new Thread(this);
  
     public KipasAngin() {
        setPreferredSize(new Dimension(350, 300));
        th.start();
    }
   
   
@Override
     public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;
        GradientPaint wp = new GradientPaint(150, 0, Color.yellow, 200, 0, Color.blue);
        if (x < 256) {
            x2 = x;
        }
        GradientPaint wl = new GradientPaint(0, 0, new Color(0 + x2, 255 - x2, 255 - x2), 0, 100, new Color(255, 255, 255 - x2));
        GradientPaint wt = new GradientPaint(0, 200, Color.black, 0, 250, new Color(18, 102, 2));

        g2.setPaint(wl);
        g2.fillRect(0, 0, 350, 300);

        g2.setPaint(wt);
        g2.fillRect(0, 200, 350, 100);

        g2.setPaint(wp);
        GeneralPath gp = new GeneralPath();
        gp.moveTo(150, 150);
        gp.lineTo(200, 150);
        gp.lineTo(210, 270);
        gp.lineTo(140, 270);
        gp.closePath();
        g2.fill(gp);
        g2.setColor(Color.black);
        g2.draw(gp);

        gamTri(g, x);
        gamTri(g, x + 90);
        gamTri(g, x + 180);
        gamTri(g, x + 270);
        g2.setColor(Color.GREEN);
        g2.fillOval(171, 171, 10, 10);

    }

    private void gamTri(Graphics g, int angle) {
        g.setColor(Color.red);
        g.fillArc(100, 100, 150, 150, angle, 30);
    }
@Override
   public void run() {
        while (true) {
            this.x = x + 1;
            try {
                repaint();
                Thread.sleep(10);
            } catch (InterruptedException ex) {
                Logger.getLogger(KipasAngin.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public static void main(String[] args) {
        JFrame fra = new JFrame();
        JPanel pa = new KipasAngin();
        fra.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        fra.getContentPane().add(pa);
        fra.pack();
        fra.setVisible(true);
    }
}





0 komentar :

Posting Komentar