JAVA随机大楼

import java.awt.Graphics;
import java.applet.Applet;
import java.awt.*;
import javax.swing.JApplet;
import javax.swing.*;
import java.util.Random;
public class Building1 extends JApplet
{
   
  public void paint(Graphics page)
  {
     int r1=20; //外接大圆半径
     int r0=(int)(r1*Math.cos(72*Math.PI/180));
     int[] xrr={
       (int)0, (int)(r0*Math.cos(54*Math.PI/180)),
       (int)(r1*Math.sin(72*Math.PI/180)), (int)(r0*Math.cos(18*Math.PI/180)),
       (int)(r1*Math.cos(54*Math.PI/180)), (int)0,
       (int)((-r1)*Math.cos(54*Math.PI/180)),(int)((-r0)*Math.cos(18*Math.PI/180)),
       (int)((-r1)*Math.sin(72*Math.PI/180)),(int)((-r0)*Math.cos(54*Math.PI/180)),
     };
     int[] yrr={
       (int)-r1, (int)(-r0*Math.sin(54*Math.PI/180)),
       (int)(-r1*Math.cos(72*Math.PI/180)), (int)((r0)*Math.sin(18*Math.PI/180)),
       (int)((r1)*(Math.sin(54*Math.PI/180))), (int)(r0),
       (int)((r1)*(Math.sin(54*Math.PI/180))), (int)((r0)*Math.sin(18*Math.PI/180)),
       (int)(-r1*Math.cos(72*Math.PI/180)), (int)(-r0*Math.sin(54*Math.PI/180)),
     };
     Random ran1 = new Random();
     page.setColor(Color.yellow);
     setBackground(Color.cyan);
     int num0=ran1.nextInt(6)+1;
     for(int j=0;j<num0;j++)
    {
       int width= ran1.nextInt(60)+40;
       int height=ran1.nextInt(250)+200;
       page.setColor(Color.black);
       int num1=ran1.nextInt(6)+1;
       page.fillRect(j*100,450-height,width,height);
       page.setColor(Color.yellow);
       for(int i=0;i<num1;i++)
       {
        int x=ran1.nextInt(width-10)+100*j;
        int y=ran1.nextInt(height-200)+250;
        page.fillRect(x,y,10,10);
       }
     }
      int n1=ran1.nextInt(4)+2;
      for(int i=0;i<n1;i++)
      {
        int xs=ran1.nextInt(600)+100;
        int xy=ran1.nextInt(100)+30;
        for(int j=0;j<10;j++)
        {
          xrr[j]=xrr[j]+xs;
          yrr[j]=yrr[j]+xy;
        }
        page.fillPolygon(xrr,yrr,10);
    }
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值