GRAFIKA KOMPUTER ALGORITMA GARIS DDA



1. Buatlah bangunan seperti di gambar diatas ini  menggunakan coding dibawah :



   2.  Penerapan coding pada netbeans
package Rumah;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Rumah extends JPanel{
@Override
public void paint(Graphics g) {
g.setColor(Color.blue);
{
}
g.setColor(Color.green);
int window = 0;
while (window <=50){
g.fillRect(410, 220+window, 5, 5);
g.fillRect(490, 220+window, 5, 5);
window++;
}
g.setColor(Color.black);
int nok = 0;
while (nok <=50){
g.fillRect(500, 50, 5, 5);
g.fillRect(500, 60, 5, 5);
g.fillRect(500, 70, 5, 5);
g.fillRect(500, 80, 5, 5);
g.fillRect(500, 90, 5, 5);
g.fillRect(500, 100, 5, 5);
g.fillRect(500, 110, 5, 5);
g.fillRect(500, 120, 5, 5);
g.fillRect(500, 130, 5, 5);
g.fillRect(500, 140, 5, 5);
g.fillRect(500, 140, 5, 5);
g.fillRect(500, 150, 5, 5);
nok++;
}

g.setColor(Color.green);
int windowatas = 0;
while (windowatas <=75){
g.fillRect(414+windowatas, 220, 5, 5);
g.fillRect(414+windowatas, 270, 5, 5);
windowatas++;
}
g.setColor(Color.magenta);
int daon = 0;
while (daon <=100){
g.fillRect(500-daon, 50+daon, 5, 5);
g.fillRect(500+daon, 50+daon, 5, 5);
daon++;
}
g.setColor(Color.red);
int Garis1 = 0;
while (Garis1 <=150){
g.fillRect(400, 150+Garis1, 5, 5);
g.fillRect(600, 150+Garis1, 5, 5);
Garis1++;
}
g.setColor(Color.yellow);
int Garis2 = 0;
while (Garis2 <=75){
g.fillRect(549, 219+Garis2, 5, 5);
g.fillRect(500, 219+Garis2, 5, 5);
Garis2++;
}
g.setColor(Color.yellow);
int Garis3 = 0;
while (Garis3 <=50){
g.fillRect(500+Garis3, 216, 5, 5);
Garis3++;
}
g.setColor(Color.blue);
int jumlahtitik2 = 0;
while (jumlahtitik2 <=200){
g.fillRect(400 +jumlahtitik2 , 300, 5, 5);
g.fillRect(400 +jumlahtitik2 , 150, 5, 5);
jumlahtitik2++; }
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().add(new Rumah());

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1000,1000);
frame.setVisible(true);
}
}
 3 Hasil run



Komentar

Postingan Populer