Translate

Minggu, 23 November 2014

Tugas Akhir Komputer Graphic

logo unindra_logo.JPG


BERMACAM ALGORITMA PEMBENTUKAN GARIS LURUS, KURVA DAN
PEMBENTUKAN KARAKTER & ALGORITMA GARIS DAN LINGKARAN
PENGISIAN POLLYGON, POLA GARIS KLIPING

Dosen :
Nahot Frastian, M.Kom

MAKALAH
DIAJUKAN UNTUK MEMENUHI
SALAH SATU TUGAS MATA KULIAH
KOMPUTER GRAFIK

Disusun oleh :
Edi Susanto    201143500321
Kelas : 7 X K




PROGRAM STUDI TEKNIK INFORMATIKA
FAKULTAS TEKNIK MATEMATIKA DAN ILMU PENGETAHUAN ALAM
UNIVERSITAS INDRAPRASTA PGRI
2014










Lembar Pengesahan
BERMACAM ALGORITMA PEMBENTUKAN GARIS LURUS, KURVA DAN
PEMBENTUKAN KARAKTER & ALGORITMA GARIS DAN LINGKARAN
PENGISIAN POLLYGON, POLA GARIS KLIPING



Telah Disetujui Oleh:


   Dosen Komputer Grafik





NAHOT FRASTIAN, M.Kom
























LINE2

import java.awt.Graphics;

public class LINE2 extends java.applet.Applet {
    public void paint(Graphics g) {
        g.drawLine(100,100,200,200);
        g.drawString ("KOMPUTER Graphics, DOSEN : NAHOT FRASTIAN, M.KOM",50,90);
    }
}

Output :



MyLine1

import java.awt.Graphics;

public class MyLine1 extends java.applet.Applet {
    public void paint(Graphics g) {
        g.drawRect(50,100,150,250);
    }
}

Output :





MyLine

import java.awt.Graphics;

public class MyLine extends java.applet.Applet {
    public void paint(Graphics g) {
        g.drawString ("KOMPUTER GRAPHICS, DOSEN : NAHOT FRASTIAN, M.KOM", 50,90);
        g.drawRect(50,100,150,250);
    }
}

Output :





drawOval

import java.awt.Graphics;

public class drawOval extends java.applet.Applet {
    public void paint(Graphics g) {
        g.drawOval(250,200,350,100);
        g.drawLine(100,100,200,200);
        g.drawString("KOMPUTER Graphics Basics, DOSEN : NAHOT FRASTIAN, M.KOM", 50,90);
    }
}

Output :





graphics

//BasicGraphics.java
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
public class graphics extends java.applet.Applet {
public void paint (Graphics g) {
int xPts[] = {5,25,50,30,15,5};
int yPts[] = {10,35,20,65,40,10};
g.drawString ("KOMPUTER Graphics, DOSEN : NAHOT FRASTIAN, M.KOM", 50,90);
g.setColor(Color.red);
g.drawRect(50,100,150,250);
g.drawRoundRect(50,150,150,250,6,120);
g.drawPolygon(xPts, yPts, xPts.length);
// cara lain membuat polygon
// polygon poly = new Polygon(xPts+100,xPts.length);
// g.fillPolygon(poly);
g.drawArc(50,100,150,275,95,115);
}
}

Output :
BasicGraphics

//BasicGraphics.java

import java.awt.Graphics;
import java.awt.Color;     
    public class BasicGraphics extends java.applet.Applet {  
    public void paint (Graphics g) {
        int xPts[] = {5, 25, 50, 30, 15, 5};
        int yPts[] = {10, 35, 20, 65, 40, 10};
        g.drawString ("KOMPUTER Graphics Basics, DOSEN : NAHOT FRASTIAN, M.KOM", 50,90);
        g.setColor(Color.red);         
        g.drawRect(50,100,150,250);
        g.drawRoundRect(50,150,150,250,6,12);
        g.drawPolygon(xPts, yPts, xPts.length);
//cara lain membuat polygon
        //polygon poly = new Polygon(xPts+100, yPts+100, xPts.length);
        //g.fillPolygon(poly);
        g.drawOval(150,100,250,55);
        g.drawArc(50, 100, 150, 275, 95, 115);
    }
}
Output :
BasicGraphics1

//BasicGraphics.java
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
public class BasicGraphics1 extends java.applet.Applet {
public void paint (Graphics g) {
int xPts[] = {5, 25, 50, 30, 15, 5};
int yPts[] = {10, 35, 20, 65, 40, 10};
g.drawString ("KOMPUTER Graphics Basics, DOSEN: NAHOT FRASTIAN, M.KOM",0,50);
g.drawLine (5, 100, 150, 250);
g.setColor (Color.blue);
g.drawRoundRect (50, 150, 150, 250, 6, 12);
g.drawPolygon (xPts, yPts, xPts.length);
//cara lain membuat polygon
//Polygon poly = new Polygon (xPts+100, yPts.lenght);
// g.fillPolygon(poly);
g.drawOval (150, 100, 250, 55);
g.drawArc(50, 100, 150, 275, 95, 115);
}
}     

Output :
graphics1

//BasicGraphics.java
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
public class graphics1 extends java.applet.Applet {
public void paint (Graphics g) {
$int xPts[] = {5, 25, 50, 30, 15, 5};
int yPts[] = {10, 35, 20, 65, 40, 10};
g.drawString ("KOMPUTER Graphics, DOSEN: NAHOT FRASTIAN, M.KOM",50,90);
g.setColor (Color.green);
g.drawRect (50, 100, 150, 250);
g.drawRoundRect (50, 150, 150, 250, 6, 12);
}
}     

Output :
graphic2

//BasicGraphics.java  
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
public class graphic2 extends java.applet.Applet {
public void paint (Graphics g) {
int xPts[] = {5, 25, 50, 30, 15, 5};
int yPts[] = {10, 35, 20, 65, 40, 10};
g.drawString ("KOMPUTER Graphics, DOSEN: NAHOT FRASTIAN, M.KOM",50,90);
g.setColor (Color.green);

g.drawPolygon (xPts, yPts, xPts.length);
//cara lain membuat polygon
//Polygon poly = new Polygon (xPts+100, yPts+100, yPts.lenght);
// g.fillPolygon(poly);
g.drawArc(50, 100, 150, 275, 95, 115);
}
}     

Output :
SegiEmpat1

import java.awt.Graphics;
 public class SegiEmpat1 extends java.applet.Applet {
     public void paint (Graphics g) {
         g.drawRect (20, 20, 60, 60);
         g.fillRect (120, 20, 60, 60);
     }
}     

Output :






SEGI

import java.awt.Graphics;
 public class SEGI extends java.applet.Applet {
 public void paint (Graphics g) {
     g.drawRect (20, 20, 60, 60);
    }
}

Output :
     








SEGI4

import java.awt.Graphics;
  public class SEGI4 extends java.applet.Applet {
     public void paint (Graphics g) {
         g.drawRoundRect (20, 20, 60, 60, 10, 10);

     }
}     

Output :







SegiEmpat

import java.awt.Graphics;

 public class SegiEmpat extends java.applet.Applet {
     public void paint (Graphics g) {
         g.drawRoundRect (20, 20, 60, 60, 10, 10);
         g.fillRoundRect (120, 20, 60, 60, 20, 20);
     }
}     

Output :






Kotak3D

import java.awt.Graphics;

 public class Kotak3D extends java.applet.Applet {
     public void paint (Graphics g) {
         g.draw3DRect (20, 20, 60, 60, true);
         g.draw3DRect (120, 20, 60, 60, false);
         g.fill3DRect (122, 22, 58, 57, true);
     }
}     

Output :




MyPoly

import java.awt.Graphics;

public class MyPoly extends java.applet.Applet {
    public void paint(Graphics g) {
        int exes[] = {39,94,97,142,53,58,26};
        int whys[] = {33,74,36,70,108,80,106};
        int pts = exes.length;
        g.drawPolygon(exes,whys,pts);
    }
}

Output :



MyPoly1

import java.awt.Graphics;

public class MyPoly1 extends java.applet.Applet {
    public void paint(Graphics g) {
        int exes[] = {39,94,97,142,53,58,26};
        int whys[] = {33,74,36,70,108,80,106};
        int pts = exes.length;
        g.fillPolygon(exes,whys,pts);
    }
}

Output :




setengahOval

import java.awt.Graphics;

public class setengahOval extends java.applet.Applet {
    public void paint(Graphics g) {
        g.drawArc(20,20,60,60,90,180);
        g.fillArc(120,20,60,60,90,180);
    }
}

Output :




MyOval

import java.awt.Graphics;

public class MyOval extends java.applet.Applet {
    public void paint(Graphics g) {
        g.drawOval(20,20,60,60);
        g.fillOval(120,20,100,60);
    }
}

Output :





ManyFonts

import java.awt.Font;
import java.awt.Graphics;

    public class ManyFonts extends java.applet.Applet {
    public void paint(Graphics g) {
Font f = new Font("TimesRoman", Font.PLAIN, 18);
    Font fb = new Font("TimesRoman", Font.BOLD, 18);
    Font fi = new Font("TimesRoman", Font.ITALIC, 18);
    Font fbi = new Font("TimesRoman", Font.BOLD+Font.ITALIC, 18);
   
                g.setFont(f);
                g.drawString("This is a plain font", 10,25);
                g.setFont(fb);
                g.drawString("This is a bold font", 10,50);
                g.setFont(fi);
                g.drawString("This is a italic font", 10,75);
                g.setFont(fbi);
                g.drawString("This is a bold italic font", 10,100);
    }
}

Output :
ManyFonts1

import java.awt.Font;
import java.awt.Graphics;

    public class ManyFonts1 extends java.applet.Applet {
    public void paint(Graphics g) {
Font f = new Font("COMPUTER GRAPHICS", Font.PLAIN, 18);
    Font fb = new Font("DOSEN : NAHOT FRASTIAN, M.KOM", Font.BOLD, 18);
    Font fi = new Font("COMPUTER GRAPHICS", Font.ITALIC, 18);
    Font fbi = new Font("DOSEN : NAHOT FRASTIAN, M.KOM", Font.BOLD+Font.ITALIC, 18);
   
                g.setFont(f);
                g.drawString("COMPUTER GRAPHICS", 10,25);
                g.setFont(fb);
                g.drawString("DOSEN : NAHOT FRASTIAN, M.KOM", 10,50);
                g.setFont(fi);
                g.drawString("COMPUTER GRAPHICS", 10,75);
                g.setFont(fbi);
                g.drawString("DOSEN : NAHOT FRASTIAN, M.KOM", 10,100);
    }
}

Output :
myline2D

import java.awt.*;
import java.applet.*;
import java.awt.geom.*;

public class myline2D extends Applet{
    public void paint(Graphics g){
       
    //menetapkan pola garis(stroke)
    float dashes[]={10.0f};
    BasicStroke stroke1=new BasicStroke(5.0f,1,2,1.0f,dashes,0.0f);
   
    //memilih object grafic 2D
    Graphics2D g2d=(Graphics2D)g;
   
    //memebri warna hitam sebagai latar belakang
    setBackground(Color.black);
   
    //mengubah warna pena menjadi warna hijau
    g2d.setPaint(Color.blue);
   
    //membuat garis yang dikombinasikan dengan pola garis
    g2d.setStroke(stroke1);
    for(int i=0;i<=50;i++)
        g2d.draw(new Line2D.Double(150,150,150+((int)150*Math.cos(i)),150+((int)150*Math.sin(i))));
    }
}





Output :













TugasBintang_Edi Susanto

import java.awt.Graphics;
import java.awt.Color;
import java.applet.Applet;
public class TugasBintang_Edi Susanto extends java.applet.Applet {
    public void paint(Graphics g) {
        g.setColor(Color.blue);
        int xPts[] = {200,100,325,75,300,200};
        int yPts[] = {60,250,125,125,250,60};
        int aPts[] = {400,300,525,275,500,400};
        int bPts[] = {270,460,335,335,460,270};
        g.drawString("Dosen                      : NAHOT FRASTIAN, M.KOM",400,100);
        g.drawString("Mata Kuliah             : KOMPUTER GRAFIK",400,120);
        g.setColor(Color.red);
        g.drawString("Nama Mahasiswa : EDI SUSANTO",400,140);
        g.drawString("NPM                         : 201143500321",400,160);
        g.drawString("Kelas                       : 7 X K", 400,180);
        g.setColor(Color.blue);
        g.drawString("TEKNIK INFORMATIKA, UNIVERSITAS INDRAPRASTA PGRI",400,220);
        g.setColor(Color.blue);
        g.fillPolygon(xPts,yPts,xPts.length);
        g.setColor(Color.red);
        g.drawPolygon(xPts,yPts,xPts.length);
        g.setColor(Color.red);
        g.fillPolygon(aPts,bPts,bPts.length);
        g.setColor(Color.blue);
        g.drawPolygon(aPts,bPts,aPts.length);
    }
}

Output :






Bintang_Nahot_Frastian_M_Kom

import javax.swing.*;
import java.applet.Applet.*;
import java.awt.Graphics;
import java.awt.Color;
    public class Bintang_Nahot_Frastian_M_Kom extends java.applet.Applet {
        public void paint (Graphics g) {
        g.setColor(Color.blue);
        g.drawString("DOSEN : NAHOT FRASTIAN, M.KOM",60,40);
        g.drawString("Mata Kuliah : Komputer Grafik",60,60);
        g.drawString("TEKNIK INFORMATIKA, UNIVERSITAS INDRAPRASTA PGRI",60,80);
        int xvalues[]={180,40,270,40,180};
        int yvalues[]={100,310,225,150,350};
        g.setColor(Color.red);
        g.drawPolygon(xvalues,yvalues,xvalues.length);
        int xvalues2[]={380,240,470,240,380};
        int yvalues2[]={250,460,375,300,500};
        g.setColor(Color.green);
        g.fillPolygon(xvalues2,yvalues2,xvalues2.length);
    }
}

Output :








Bintang1

import javax.swing.*;
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
    public class Bintang1 extends java.applet.Applet {
        public void paint (Graphics g) {
        g.setColor(Color.green);
        g.drawString("Dosen : NAHOT FRASTIAN, M.Kom",40,50);
        g.drawString("Mata Kuliah : Komputer Grapik",40,70);
        int xvalues[]={180,40,270,40,180};
        int yvalues[]={100,310,225,150,350};
        g.setColor(Color.red);
        g.drawPolygon(xvalues,yvalues,xvalues.length);
        int xvalues2[]={380,240,470,240,380};
        int yvalues2[]={250,460,375,300,500};
        g.setColor(Color.blue);
        g.fillPolygon(xvalues2,yvalues2,xvalues2.length);
    }
}

Output :










BasicShapes2D

import java.awt.*;
import java.applet.*;
import java.awt.geom.*;
public class BasicShapes2D extends Applet{
//definisi variabel
final static int maxCharHeight=15;
    final static int minFontSize=6;
    final static Color background=Color.white;
    final static Color foreground=Color.black;
    final static BasicStroke stroke=new BasicStroke(2.0f);
    final static BasicStroke wideStroke=new BasicStroke(5.0f);
    final static float dash[]={10.0f};
    final static BasicStroke stroke02=new
    BasicStroke(1.0f,0,1,10.f,dash,0.0f);
    Dimension dim;
    FontMetrics fontMetrics;
    //fungsi inisialisasi
    public void init(){
        setBackground(background);
        setForeground(foreground);
    }
    //fungsi untuk menggambar
    public void paint(Graphics g){
        Graphics2D g2d=(Graphics2D) g;
        dim = getSize();
        int width []=new int[6];
        int height []=new int[3];
        int i;
        width[0]=0;
        height[0]=0;
        for(i=1;i<=5;i++)
            width[i]=width[i-1]+dim.width/5;
        for(i=1;i<=2;i++)
            height[i]=height[i]+dim.height/2;
        g2d.setPaint(Color.black);
        g2d.fill(new Rectangle2D.Double(0, 0, size().width,size().height));
       
        //menggambar bentuk pertama berupa garis
        g2d.setPaint(Color.yellow);
        g2d.draw(new Line2D.Double(width[0],height[1]-20,width[1]-10,0));
        g2d.drawString("Line2D",width[0]+20,height[1]-5);
       
        //menggambar bentuk persegi dengan stroke berapa garis putus-putus
        //menggambar bentuk persegi dengan sudut tumpul
        g2d.setStroke(stroke);
        g2d.setPaint(Color.green);
        g2d.fill(new RoundRectangle2D.Double(width[2],height[0],width[1]-
            10,height[1]-20,10,10));
        g2d.drawString("RoundRectingle2D",width[2]+3,height[1]-5);
        g2d.setPaint(Color.black);
      

        g2d.fill(new
        RoundRectangle2D.Double(width[2]+5,height[0]+5,width[1]-20,height[1]-30,10,10));
       
        //menggambar bentuk busur dengan isinya
        g2d.setStroke(stroke);
        g2d.setPaint(Color.lightGray);
        g2d.fill(new Arc2D.Double(width[2],height[1],width[1]-10,height[2]-20,150,270,2));
        g2d.drawString("filledArc2D",width[2]+10,(2*height[1])-5);
        
        //menggambar bentuk busur
        g2d.setStroke(wideStroke);
        g2d.setPaint(Color.yellow);
        g2d.draw(new Arc2D.Double(width[3],height[0]+5,width[1]-10,height[1]-20,60,180,0));
        g2d.drawString("Arc2D",width[3]+20,height[1]-5);
       
        //menggambar bentuk busur dengan isinya
        g2d.setStroke(stroke);
        g2d.setPaint(Color.pink);
        g2d.draw(new Arc2D.Double(width[3],height[1],width[1]-10,height[2]-20,0,225,1));
        g2d.drawString("Arc2D",width[3]+20,(2*height[1])-5);
       
        //menggambar bentuk elips dengan isinya diberikan warna gradien
        g2d.setStroke(stroke);
        g2d.setPaint(new GradientPaint(width[4],height[0],Color.white,size().width,size().height-50,Color.gray,true));
        g2d.fill(new Ellipse2D.Double(width[4],height[0],width[1]-10,height[1]-20));
        g2d.drawString("filledEllipse2D",width[4]+10,height[1]-5);
       
        //menggambar bentuk elips dengan isinya ditimpa
        //dengan bentuk ellipse yang berupa bingkainya saja
        g2d.setStroke(stroke);
        g2d.setPaint(Color.magenta);
        g2d.fill(new Ellipse2D.Double(width[4],height[1],width[1]-10,height[2]-20));
        g2d.drawString("filledEllipse2D",width[4]+10,(2*height[1])-5);
        g2d.setPaint(Color.cyan);
        g2d.draw(new Ellipse2D.Double(width[4],height[1],width[1]-10,height[2]-20));
    }
}

Output :


circle

import java.awt.*;
public class circle extends java.applet.Applet{
    private int mouseX, mouseY;
    private boolean mouseclicked = false;
   
        public void init(){
            setBackground (Color.magenta);
        }
   public boolean mouseDown(Event e, int x, int y){
            mouseX = x; mouseY = y;
            mouseclicked = true;
            repaint();
            return true;
        }
   public void paint(Graphics g){
       g.setColor(Color.red);
       if(mouseclicked){
           g.fillOval((mouseX-5), (mouseY-5),10,10);
           mouseclicked = false;
        }
    }
}
           
Output :

            















circle_Right

import java.awt.*;
public class circle_Right extends java.applet.Applet{
   private int mouseX, mouseY;
   private boolean mouseclicked = false;
   
        public void init(){
            setBackground (Color.magenta);
        }
   public boolean mouseDown(Event e, int x, int y){
            mouseX = x; mouseY = y;
            mouseclicked = true;
            repaint();
            return true;
        }
   public void paint(Graphics g){
       g.setColor(Color.green);
       if(mouseclicked){
           g.fillOval((mouseX-5), (mouseY-5),20,20);
           mouseclicked = false;
        }
    }
    public void update(Graphics g){
        paint(g);
        g.drawString("KOMPUTER Graphics, Dosen : NAHOT FRASTIAN,M.KOM",50,90);
    }
}
           

Output :

      








clock1

import java.applet.*;
import java.awt.*;
import java.util.*;
import java.text.*;

public class clock1 extends Applet implements Runnable {

    int width, height;
    Thread t = null;
    boolean threadSuspended;
    int hours=0, minutes=0, seconds=0;
    String timeString = "";
   
    public void init () {
        width = getSize().width;
        height = getSize().height;
        setBackground(Color.red);
    }
    public void start() {
        if(t == null) {
            t = new Thread (this);
            t.setPriority (Thread.MIN_PRIORITY);
            threadSuspended = false;
            t.start();
        }
        else {
            if (threadSuspended) {
                threadSuspended = false;
                synchronized (this) {
                    notify();
                }
            }
        }
    }
    public void stop() {
        threadSuspended = true;
    }
    public void run() {
        try {
            while(true) {
                //Here's where the thread does some work
                Calendar cal = Calendar.getInstance();
                hours = cal.get (Calendar.HOUR_OF_DAY);
                if (hours > 12) hours -=12;
                minutes = cal.get (Calendar.MINUTE);
                seconds = cal.get (Calendar.SECOND);
               
                SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ss", Locale.getDefault());
                Date date = cal.getTime();
                timeString = formatter.format(date);
               
                //Now the thread checks to see if it should suspended itself
                if (threadSuspended) {
                    synchronized (this) {
                        while (threadSuspended) {
                            wait();
                        }
                    }
                }
                repaint();
                Color[] c = {Color.green, Color.red};
                setBackground (c[seconds%2]);
                t.sleep (1000); //interval given in millisecounds
            }
        }
        catch (InterruptedException e) {}
    }
    void drawHand (double angle, int radius, Graphics g) {
        angle -= 0.5* Math.PI;
        int x = (int) (radius*Math.cos(angle));
        int y = (int) (radius*Math.sin(angle));
        g.drawLine (width/2, height/2, width/2 + x, height/2 + y);
    }
    void drawWedge(double angle, int radius, Graphics g) {
        angle -= 0.5*Math.PI;
        int x = (int) (radius*Math.cos(angle));
        int y = (int) (radius*Math.sin(angle));
        angle += 2*Math.PI/3;
        int x2 = (int) (5*Math.cos(angle));
        int y2 = (int) (5*Math.sin(angle));
        angle += 2*Math.PI/3;
        int x3 = (int) (5*Math.cos(angle));
        int y3 = (int) (5*Math.sin(angle));
        g.drawLine (width/2+x2, height/2+y2, width/2+ x, height/2 + y);
        g.drawLine (width/2+x3, height/2+y3, width/2+ x, height/2 + y);
        g.drawLine (width/2+x2, height/2+y2, width/2+ x3, height/2 + y3);
    }
    public void paint (Graphics g) {
        g.setColor (Color.black);
        drawWedge (2*Math.PI * hours / 12, width/5, g);
        drawWedge (2*Math.PI * minutes / 60, width/3, g);
        drawHand (2*Math.PI * seconds / 60, width/2, g);
        g.setColor (Color.black);
        g.drawString (timeString,10, height-10);
        g.drawString ("KOMPUTER Graphics, DOSEN : NAHOT FRASSTIAN, M.KOM", 50,90);
      
    }
}






Output :

















lukisan_kapal

import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;

public class lukisan_kapal extends JApplet {

public static void main(String s[]) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JApplet applet = new lukisan_kapal();
applet.init();
frame.getContentPane().add(applet);
frame.pack();
frame.setVisible(true);
}

public void init() {
JPanel panel = new Pan();
getContentPane().add(panel);
}

class Pan extends JPanel {

public Pan() {
setPreferredSize(new Dimension(1300, 600));
}

public void paintComponent(Graphics g) {
super.paintComponent(g);

Graphics2D g1 = (Graphics2D) g;
Graphics2D g2 = (Graphics2D) g;
// nama dan nim
kotak(g2);
GradientPaint paint1 = new GradientPaint(100, 100, new Color(130, 36, 2), 250, 100, new Color(253, 149, 51));
Font font = new Font("Comic Sans ms", Font.BOLD, 25);
g1.setPaint(paint1);
g1.setFont(font);
g1.drawString("Edi Susanto", 50, 500);
g1.drawString("( 201143500321 )", 65, 550);

garisdda(g2, 0, 350, 325, 350);
garisdda(g2, 625, 350, 1300, 350);

garisdda(g2, 350, 400, 600, 400);
garisdda(g2, 600, 400, 650, 300);
garisdda(g2, 300, 300, 350, 400);
garisdda(g2, 300, 300, 650, 300);

kotak_brass(g2, 350, 250, 600, 300);
bunder(g2, 1150, 100, 75);
body(g2);
garisdda(g2, 950, 100, 1050, 100);
garisdda(g2, 960, 25, 1060, 50);
garisdda(g2, 960, 175, 1060, 150);
garisdda(g2, 980, 250, 1080, 175);
budermidpoint(g2, 375, 275, 20);
budermidpoint(g2, 430, 275, 20);
budermidpoint(g2, 485, 275, 20);
budermidpoint(g2, 540, 275, 20);
awane(g2, -10, 50);
awane(g2, 90, 1);
awane(g2, 210, 50);
awane(g2, 310, 1);
awane(g2, 410, 50);
awane(g2, 510, 1);
awane(g2, 610, 50);
awane(g2, 710, 1);
}

public void body(Graphics2D g) {
GeneralPath gp = new GeneralPath();
GradientPaint p = new GradientPaint(0, 350, Color.gray, 50, 30, Color.black);
g.setPaint(p);

gp.moveTo(300, 300);
gp.lineTo(650, 300);
gp.lineTo(600, 400);
gp.lineTo(350, 400);
gp.closePath();
g.fill(gp);
}

public void kotak_brass(Graphics2D gr, int x_awal, int y_awal, int x_akhir, int y_akhir) {
GeneralPath gp = new GeneralPath();
Shape s = new Rectangle2D.Double(x_awal, y_awal, 250, 50);
GradientPaint p = new GradientPaint(0, 350, Color.green, 50, 30, Color.black);
gr.setPaint(p);
gr.fill(s);
int Dx = Math.abs(x_akhir - x_awal);
int Dy = Math.abs(y_akhir - y_awal);
int parameter = (2 * Dy) - Dx;
String status = "Kotak_BM";
this.repaint();
double g = x_awal, h = y_awal;
while (x_awal < x_akhir) {
if (parameter < 0) {
parameter += (2 * Dy);
} else {
y_awal++;
parameter = parameter + (2 * Dy) - (2 * Dx);
}
gp.moveTo(x_awal, y_awal);
x_awal++;
}
gp.lineTo(g, y_awal);
gp.lineTo(g, h);
gp.lineTo(x_awal, h);
gp.lineTo(x_awal, y_awal);
gp.closePath();
gr.draw(gp);}

public void garisdda(Graphics2D g, int x1, int y1, int x2, int y2) {

double m = (double) (y2 - y1) / (x2 - x1);
double y = (double) y1;
int iy;
for (int x = x1; x <= x2; x++) {
iy = (int) Math.round(y);
g.drawLine(x, iy, x, iy);
y += m;
}
}
}

public void kotak(Graphics2D g) {
Shape s = new Rectangle2D.Double(0, 0, 1300, 350);
GradientPaint p = new GradientPaint(0, 350, new Color(0, 255, 255), 50, 30, new Color(70, 51, 204));
g.setPaint(p);
g.fill(s);
Shape s1 = new Rectangle2D.Double(0, 350, 1300, 250);
GradientPaint r = new GradientPaint(0, 350, Color.white, 1300, 600, Color.blue);
g.setPaint(r);
g.fill(s1);
}

void budermidpoint(Graphics2D g, int x1, int y1, int r) {
Shape s = new Ellipse2D.Double(x1 - r, y1 - r, r * 2, r * 2);
g.setColor(Color.red);
g.fill(s);
int x = 0, y = r, p = 1 - r;
int xctr = x1, yctr = y1;
g.drawLine(xctr + x, yctr + y, xctr + x, yctr + y);
g.drawLine(xctr - x, yctr + y, xctr - x, yctr + y);
g.drawLine(xctr + x, yctr - y, xctr + x, yctr - y);
g.drawLine(xctr - x, yctr - y, xctr - x, yctr - y);
g.drawLine(xctr + y, yctr + x, xctr + y, yctr + x);
g.drawLine(xctr - y, yctr + x, xctr - y, yctr + x);
g.drawLine(xctr + y, yctr - x, xctr + y, yctr - x);
g.drawLine(xctr - y, yctr - x, xctr - y, yctr - x);
while (x < y) {
x++;
if (p < 0) {
p += 2 * x + 1;
} else {
y--;
p += 2 * (x - y) + 1;
}
}
}

public void bunder(Graphics2D g, int x1, int y1, int r) {
Shape s = new Ellipse2D.Double(x1 - r, y1 - r, r * 2, r * 2);
GradientPaint p = new GradientPaint(x1, y1, Color.orange, x1 + 200, y1 + 50, Color.red);
g.setPaint(p);
g.fill(s);
}

public void awane(Graphics2D g2, int x, int y) {
GeneralPath gp = new GeneralPath();
gp.moveTo(30 + x, 80 + y);
gp.curveTo(-5 + x, 60 + y, 22 + x, 15 + y, 40 + x, 42 + y);
gp.curveTo(37 + x, 31 + y, 53 + x, 31 + y, 58 + x, 43 + y);
gp.curveTo(60 + x, 7 + y, 116 + x, 4 + y, 100 + x, 34 + y);
gp.curveTo(150 + x, 29 + y, 150 + x, 89 + y, 120 + x, 90 + y);
gp.curveTo(100 + x, 120 + y, 95 + x, 97 + y, 87 + x, 100 + y);
gp.curveTo(71 + x, 120 + y, 35 + x, 100 + y, 35 + x, 70 + y);
gp.closePath();
gp.closePath();
g2.setPaint(new GradientPaint(0 + x, 20 + y, Color.lightGray, 0 + x, 150 + y, Color.white));
g2.fill(gp);
g2.setColor(Color.white);
g2.draw(gp);
}
}

Output :









LINE21

import java.awt.Graphics;

public class LINE21 extends java.applet.Applet {
    public void paint(Graphics g) {
        g.drawLine(100,50,200,300);
        g.drawString ("KOMPUTER Graphics, DOSEN : NAHOT FRASTIAN, M.KOM",50,90);
    }
}

Output :