java实现输入心型

package com.mr.rocket;

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
public class Test_2 extends Applet{
          int width , height ;
          Image image ;                                                                     //缓冲区对象
          Graphics g1 ;

        public void init(){                                                   //Applet 初始化时调用
                 setBackground(Color. black );                                 //设置背景
                 this .setSize(350, 310);
                     
                 width = getSize(). width ;                                    //获得窗口宽度
                 height = getSize(). height ;
                 image = createImage( width , height );                  //创建图像对象
                 g1 = image .getGraphics();
          }
        public void paint(Graphics g){                                 //绘图方法
                 g1 .clearRect(0, 0, width , height );
                 g1 .setColor(Color. red );
                 for ( int i = 0; i <= 90; i++)                                      
                             for ( int j = 0; j  <= 90; j++){                                
                             int r = ( int ) (Math. PI / 45 * i * (1 - Math.sin(Math. PI / 45 * j)) * 18);
                             int x = ( int ) (r * Math.cos(Math. PI / 45 * j) * Math.sin(Math. PI / 45 * i) + width / 2);                                                               //为了在中间显示,加了偏移量
                             int y = ( int ) (-r * Math.sin(Math. PI / 45 * j) + height / 4);
                              g1 .fillOval(( int ) x, ( int )y, 2,2);           
                 g.drawImage( image , 0, 0, this );
          }

          }

        /**
        * @param args
        */
        public static void main(String[] args) {
               // TODO Auto-generated method stub
       }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值