zoukankan      html  css  js  c++  java
  • 心形曲线

     1 package Test;
     2 
     3 import java.awt.Color;
     4 import java.awt.Graphics;
     5 import java.awt.Image;
     6 import java.awt.Toolkit;
     7 
     8 import javax.swing.JFrame;
     9 
    10 public class Love extends JFrame {
    11     
    12     private static final int width = 480;
    13     private static final int height = 600;
    14     
    15     private static int window_width = Toolkit.getDefaultToolkit().getScreenSize().width;
    16     private static int window_height = Toolkit.getDefaultToolkit().getScreenSize().height;
    17 
    18     public Love()
    19     {
    20         super("心形线");
    21         this.setBackground(Color.BLACK);
    22         this.setLocation((window_width - width) / 2, (window_height - height) / 2);
    23         this.setSize(width, height);
    24         this.setLayout(getLayout());
    25         this.setVisible(true);
    26         this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    27     }
    28     
    29     public void paint(Graphics g)
    30     {
    31         double x, y, r;
    32         Image image = this.createImage(width, height);
    33         Graphics pic = image.getGraphics();
    34         
    35         for(int i = 0; i < 100; i++)
    36         {
    37             for(int j = 0; j < 100; j++)
    38             {
    39                 r = Math.PI / 45 + Math.PI / 45 * i * (1 - Math.sin(Math.PI / 45 * j)) * 18;
    40                 x = r * Math.cos(Math.PI / 45 * j) * Math.sin(Math.PI / 45 * i) + width / 2;
    41                 y = -r * Math.sin(Math.PI / 45 * j) + height / 2;
    42                 pic.setColor(Color.MAGENTA);
    43                 pic.fillOval((int)x, (int)y, 2, 2);
    44             }
    45             g.drawImage(image, 0, 0, this);
    46         }
    47     }
    48     
    49     public static void main(String[] args) {
    50         new Love();
    51     }
    52 }

  • 相关阅读:
    为cocos2d-x实现安卓输入框。非全屏,无dialog,绑定到lua
    自己动手,丰衣足食。普通键盘实现键盘宏(Windows和Mac版)
    go语言使用protobuf
    go语言使用redis —— redigo
    go语言实现线程池
    go语言实现的目录共享程序
    ss
    BST
    堆排序—最大优先级队列
    STL_Vector
  • 原文地址:https://www.cnblogs.com/fylove/p/6213912.html
Copyright © 2011-2022 走看看