How to make love to tell the truth in Java

Java can be plotted, do not think small Java function

The power of Java that it is difficult to learn

But we can learn a specialized


The following is a confession of love plot


Give you the girls like it


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();


}


}

Published 19 original articles · won praise 58 · views 50000 +

Guess you like

Origin blog.csdn.net/cyg_l02/article/details/80296211