Spriopanel with java swing

artikel kali membahas mengenai spriopanel(spiral/oval) dengan bahasa pemrograman. ya karena susah ngomongnya ya langsung ja ke codenya. kurang lebih seperti ini :

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
*
* @author cyber-blackhat
*/
public class SprioPanel {

public static void main(String[] args){
BufferedReader mlx = new BufferedReader(new InputStreamReader(System.in));
try {
}catch(Exception e){
System.out.println(e);
}
JFrame ml = new JFrame(“Still Trying”);
JPanel mo = new Spionase();
ml.add(mo);
ml.setVisible(true);
ml.setSize(400,400);
}

//created panel
final static class Spionase extends JPanel{
int nPoints = 1000;
double r1 = 100;
double r2 = 50;
double p = 19;

public Spionase(){
setPreferredSize(new Dimension(200,200));
setBackground(getBackground());
}
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.translate(200, 200);
g2.setColor(Color.red);
int x1 = (int)(r1+r2-p);
int y1 = 0;
int x2;
int y2;
for(int i = 0;i<nPoints;i++){
//double t = i * Math.PI/90; // spionase
double t = i *Math.PI/90;
//double x = i *Math.sin(t)*2;
x2 = (int) ((r1-r2)*Math.cos(t)-p*Math.cos((r1/r2)*t/r2));

y2 = (int) ((r1+r2)*Math.sin(t)-p*Math.sin((r1/r2*r2)*t/r2));
for(int w=0;w<=10;w++){
g2.drawLine(x1, y1, x2, y2);
}
x1 = x2;
y1 = y2;

}
}
}
}

hasil setelah dicompile akan muncul gambar garis spiral.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s