Sabtu, 31 Agustus 2013

Ploting Fungsi Sin dan Cosinus Java

import.javax.swing.*;
import.java.*;

class Kanvas1 extends Canvas
{
public void paint(Graphics g)
{
g.setColor(Color.black);
g.drawLine(10,10,10,210);
g.drawLine(5,110,380,110);
g.drawString("1",2,14);
g.drawString("-1",14,210);
g.drawString("0",13,123);
g.drawString("90",100,123);
g.drawString("180",190,123);
g.drawString("270",280,123);
g.drawString("360",379,123);

g.setColor(Color.red);
for(int i=0; i<360; i+=1)
{
int y=(int)
(Math.sin(i*Math.PI/180)*100)*-1;
g.drawOval(i+10,y+110,1,1);
}
g.setColor(Color.blue);
for (int i=0; i<360; i+=1)
{
int y=(int)
(Math.cos(i.Math.PI/180)*100)*-1;
g.drawOval(i+10,y+110,1,1);
}
}
}

class Animasi extends JFrame
{
KanvasAnimasi gambar=new KanvasAnimasi();

Animasi()
{

setTitle("Ploting Fungsi Sinus dan Cosinus");
setLocation(200, 100);
setSize(400, 260);

setDefaultCloserOperation(JFrame.EXIT_ON_CLOSE);
}

void KomponenVisual()
{
getContentPane().setLayout(new
BorderLayout());
getContentPane().add(gambar,BorderLayout.CENTER);

setVisible(true);
}
public static void main(String[] args)
}
Animasi anime=new Animasi();
anime.KomponenVisual();
}
}

0 komentar: