Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

Sphere by Lines

Sat Apr 07, 2007 8:15 pm

This a trivial graphics program i made. I draw a sphere using loop to change the degree of the rotation theta.

java code
// LineCircle.java
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;

/**
*

*/
public class LineCircle extends JFrame{

/** Creates a new instance of LineCircle */

private int r=200;
private float theta;
private int width=500;
private int height=500;
private int x=0;
private int y=0;
public LineCircle() {
setTitle("Codemiles");
setSize(width,height);

}
public void paint(Graphics g) {
g.fillRect(0,0,500,500);
g.setColor(Color.RED);
int drawX=0;
int drawY=0;
int color=0;
while(theta<360)
{
g.setColor(new Color(255-color,10+color,color));
drawX=(x+(int)(r*Math.cos(theta)));
drawY=(y+(int)(r*Math.sin(theta)));
g.drawLine(0+250,250-0,drawX+250,250-drawY);
theta+=0.5;
if(theta%2==0)
color++;
}
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
LineCircle LC=new LineCircle();
LC.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
LC.setVisible(true);
}



}



Last edited by msi_fci on Thu May 03, 2007 11:17 pm, edited 1 time in total.

Post a reply
  Related Posts  to : Sphere by Lines
 drawing a rotating sphere     -  
 Draw a solid sphere using openGL     -  
 Adding lighting to a solid sphere     -  
 rotate sphere in a circle with light     -  
 Drawing Lines in php     -  
 Lines on the plane     -  
 Script ingoring lines     -  
 Draw Triangle using Lines     -  
 increase the number of bank lines by <br/>     -  
 draw any number of lines on mouse clicks     -  

Topic Tags

Java Graphics