Code sharing for Ava swing heart-shaped dynamic patterns

Source: Internet
Author: User

Today the Java Mall Product development staff shares the code of a Java swing heart-shaped dynamic pattern

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 package com.zuidaima.swing;    import java.awt.Color;  import java.awt.Graphics;  import java.awt.Image;  import java.awt.Toolkit;    import javax.swing.JFrame;    @SuppressWarnings("serial" class Cardioid extends JFrame {      // 定义窗口大小      private static final int WIDTH = 480     private static final int HEIGHT = 600        // 获取屏幕大小      private static int WINDOW_WIDTH = Toolkit.getDefaultToolkit()              .getScreenSize().width;      private static int WINDOW_HEIGHT = Toolkit.getDefaultToolkit()              .getScreenSize().height;        // 构造函数      public Cardioid() {          // 设置窗口标题          super("?形线");          // 设置背景色          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 = 0; i < 100; i++) {              for (int j = 0; j < 100; 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 / 2                   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();    

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.