Java可以作图,不要以为Java功能少
Java的强大功能以致于难以学会
但是可以专门学一处
下面这个是爱心表白作图
送给你喜欢的女孩子吧
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JFrame;
public class Cardioid extends JFrame{
private static final int WIDTH=500;
private static final int HEIGHT=500;
private static int WINDOW_WIDTH=Toolkit.getDefaultToolkit().getScreenSize().width;
private static int WINDOW_HEIGHT=Toolkit.getDefaultToolkit().getScreenSize().height;
public Cardioid(){
super("I love you");
this.setBackground(Color.BLACK);
this.setLocation((WINDOW_WIDTH-WIDTH)/2,(WINDOW_HEIGHT-HEIGHT)/2);
this.setSize(WIDTH, HEIGHT);
this.setLayout(getLayout());
this.setVisible(true);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
public void paint(Graphics g){
double x,y,r;
Image image=this.createImage(WIDTH,HEIGHT);
Graphics pic=image.getGraphics();
for(int i=-2;i<90;i++){
for(int j=-2;j<90;j++){
r=Math.PI/45+Math.PI/45*i*(1-Math.sin(Math.PI/45*j))*18;
x=r*Math.cos(Math.PI/45*j)*Math.sin(Math.PI/45*i)+WIDTH/2;
y=-r*Math.sin(Math.PI/45*j)+HEIGHT/3;
pic.setColor(Color.MAGENTA);
pic.fillOval((int)x, (int)y, 2, 2);
}
g.drawImage(image, 0, 0, this);
}
}
public static void main(String[] args) {
new Cardioid();
}
}