import java.applet.*; import java.awt.*; public class Heart extends Applet { int AppletWidth,AppletHeight; Image OffScreen; Graphics drawOffScreen; public void init () { setBackground(Color.black); AppletWidth=700; AppletHeight=700; OffScreen =createImage(AppletWidth,AppletHeight); drawOffScreen =OffScreen.getGraphics(); } public void paint (Graphics g) { drawOffScreen.clearRect(0, 0, AppletWidth, AppletHeight); drawOffScreen.setColor(Color.green); int i,j; double x,y,r; for(i=0;i<180;i++) { for(j=0;j<180;j++) { r=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)+AppletWidth/2)*1; y=(-r*Math.sin(Math.PI/45*j)+AppletHeight/4)*1.01; drawOffScreen.fillOval((int)x,(int)y, 2, 2); try { //Thread.sleep(1); }catch(Exception e){} } } g.drawImage(OffScreen, 0, 0, this); } }

# Java画三维爱心

Posted on