99偷拍视频精品区一区二,口述久久久久久久久久久久,国产精品夫妇激情啪发布,成人永久免费网站在线观看,国产精品高清免费在线,青青草在线观看视频观看,久久久久久国产一区,天天婷婷久久18禁,日韩动漫av在线播放直播

【圣誕快樂】如何用代碼畫一顆圣誕樹?-創新互聯

文章目錄
    • 一、前言
    • 二、創意角度
    • 三、java swing版 效果展示
    • 四、java swing版 實現步驟&代碼
    • 五、springboot項目banner版 效果展示
    • 六、springboot項目banner版 實現步驟
    • 七、 linux shell界面打印版 效果展示
    • 八、 linux shell界面打印版 實現步驟

貴港ssl適用于網站、小程序/APP、API接口等需要進行數據傳輸應用場景,ssl證書未來市場廣闊!成為創新互聯的ssl證書銷售渠道,可以享受市場價格4-6折優惠!如果有意向歡迎電話聯系或者加微信:18980820575(備注:SSL證書合作)期待與您的合作!一、前言

一年一度的圣誕節來了 讓我們一起動動小手 給平凡而普通的生活 添加一筆色彩吧
看看誰敢說程序員不懂浪漫? 程序員一天能new 1024個對象(GC 此時有話要說)

二、創意角度

從代碼,項目標簽,linux等多方面 畫一顆圣誕樹,讓圣誕變得花里胡哨!

三、java swing版 效果展示

(播放有音樂)
在這里插入圖片描述

四、java swing版 實現步驟&代碼

(基于jdk11)

  1. main方法
package view;

public class Main {// 程序入口,運行此處
   public static void main(String[] args) {   try {   new MyFrame();
       } catch (Exception e) {   e.printStackTrace();
       }
   }
}
  1. JFrame方法
package view;

import javax.swing.*;

public class MyFrame extends JFrame {MyPanel p;

    MyFrame() throws Exception {p = new MyPanel();
        add(p);
        setBounds(400, 200, 800, 800);
        setVisible(true);
        validate();
        setDefaultCloseOperation(MyFrame.EXIT_ON_CLOSE);
    }
}
  1. Jpanel方法(核心實現)
package view;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;

public class MyPanel extends JPanel implements ActionListener {// 圖片、音樂路徑 音樂推薦wav格式 
    static final String MUSIC = "src/resouce/music.wav";
    static final String STAR_SHINE = "src/resouce/STAR_SHINE.png";
    static final String STAR_NOT_SHINE = "src/resouce/STAR_NOT_SHINE.png";
    static final String ON = "src/resouce/ON.png";
    static final String OFF = "src/resouce/OFF.png";

    int x, y;
    JButton onOff;
    Timer time;
    boolean flag;
    boolean color;
    File file = new File(MUSIC);
    URL url = null;
    URI uri = null;
    //   since jdk9 : Clip (jdk9 before : AudioClip)
    Clip clip = null;
    AudioInputStream ais = null;

    MyPanel() throws Exception {setLayout(null);
        ImageIcon icon = new ImageIcon(OFF);
        icon.setImage(icon.getImage().getScaledInstance(50, 50, 0));
        onOff = new JButton();
        onOff.addActionListener(this);
        onOff.setIcon(icon);
        onOff.setBorder(null);
        onOff.setContentAreaFilled(false);
        onOff.setBounds(0, 0, 50, 50);
        add(onOff);
        flag = true;
        color = true;
        time = new Timer(300, this);
        time.stop();
        try {uri = file.toURI();
            url = uri.toURL();
        } catch (MalformedURLException e1) {System.out.println(e1);
        }
        clip = AudioSystem.getClip();
        ais = AudioSystem.getAudioInputStream(file);
        clip.open(ais);

    }

    public void paintComponent(Graphics g) {x = 380;
        y = 100;
        if (color) {ImageIcon image1 = new ImageIcon(STAR_NOT_SHINE);
            g.drawImage(image1.getImage(), x - 3, y - 25, 28, 26, null);
        } else {ImageIcon image1 = new ImageIcon(STAR_SHINE);
            g.drawImage(image1.getImage(), x - 3, y - 25, 25, 25, null);
        }
        Color red = new Color(255, 0, 0);
        Color yellow = new Color(255, 241, 0);
        drawTree(1, 4, g);
        if (color) {drawDecoration(x + 22, y - 44, 6, yellow, g);
            drawDecoration(x, y - 22, 8, red, g);
        } else {drawDecoration(x + 22, y - 44, 6, red, g);
            drawDecoration(x, y - 22, 8, yellow, g);
        }
        x = 380 - 2 * 22;
        drawTree(3, 6, g);
        if (color) {drawDecoration(x + 22, y - 44, 10, yellow, g);
            drawDecoration(x, y - 22, 12, red, g);
        } else {drawDecoration(x + 22, y - 44, 10, red, g);
            drawDecoration(x, y - 22, 12, yellow, g);
        }
        x = 380 - 4 * 22;
        drawTree(5, 8, g);
        if (color) {drawDecoration(x + 22, y - 44, 14, yellow, g);
            drawDecoration(x, y - 22, 16, red, g);
        } else {drawDecoration(x + 22, y - 44, 14, red, g);
            drawDecoration(x, y - 22, 16, yellow, g);
        }
        x = 380 - 1 * 22;
        drwaRoot(g);
    }

    void drawTree(int from, int to, Graphics g) {Color c = new Color(9, 124, 37);
        g.setColor(c);
        for (int i = from; i<= to; i++) {for (int j = 0; j< (i * 2 - 1); j++) {g.fillRect(x, y, 20, 20);
                x += 22;
            }
            x = 380 - i * 22;
            y += 22;
        }
    }

    void drawDecoration(int tx, int ty, int num, Color c, Graphics g) {g.setColor(c);
        g.fillRoundRect(tx, ty, 18, 18, 18, 18);
        g.fillRoundRect(tx + num * 22, ty, 18, 18, 18, 18);
    }

    void drwaRoot(Graphics g) {Color c = new Color(131, 78, 0);
        g.setColor(c);
        for (int i = 0; i< 4; i++) {for (int j = 0; j< 3; j++) {g.fillRect(x, y, 20, 20);
                x += 22;
            }
            x = 380 - 1 * 22;
            y += 22;
        }
    }

    public void actionPerformed(ActionEvent e) {if (e.getSource() == onOff) {if (flag) {ImageIcon icon = new ImageIcon(ON);
                icon.setImage(icon.getImage().getScaledInstance(50, 50, 0));
                onOff.setIcon(icon);
                try {clip.start();
                } catch (Exception exc) {exc.printStackTrace();
                }
                flag = false;
                clip.setLoopPoints(0, -1);
                time.restart();
            } else {ImageIcon icon = new ImageIcon(OFF);
                icon.setImage(icon.getImage().getScaledInstance(50, 50, 0));
                onOff.setIcon(icon);
                flag = true;
                time.stop();
                clip.stop();
            }
        } else if (e.getSource() == time) {repaint();
            color = !color;
        }
    }
}
  1. 目錄結構、資源路徑:
    在這里插入圖片描述
    音樂推薦wav格式,且開關圖片、星星圖片、音樂可以自由替換 ,替換后注意文件名保持一致 或在代碼里面將相應文件名更改。

  2. 靜態資源、代碼地址:
    https://github.com/qiuhuanhen/christmasTree

五、springboot項目banner版 效果展示

想想你把這個效果提交到git dev分支之后,同事啟動項目時會不會覺得小驚喜呢
在這里插入圖片描述

六、springboot項目banner版 實現步驟
  1. 在resources目錄下新建banner.txt文件 文件名必須是這個,這是springboot的機制,根據名字讀取。(和我們的application.yml處于同級目錄)

  2. 將符號文字復制進去,啟動項目即可。同樣的 符號文字也是可以隨意替換的 我們可以在網上找更好看的符號 或者動手能力強的同學可以自己設計

∵∴∵︿︿︿︿︿︿..∴∵∴∵∴∵∴☆∵∴∵
∴∵/    ?。埽堋摺嗦}∵∴∵/\∴∵∴
∵/      ?。埽堋摺唷摺啵。堋摺?╭~~~~~~~~~╮○誕∴-/?。 。堋?╰~~~~~~~~~╯∵∴/?。  铩。?/        ?。堋嗫臁?- ̄/.?。埽?|  ∩   ∩  ---|∵∴∵/★?。。堋?| ?     ? ---|∴樂-/    .?。?\    ﹏    -/∴∵--○ ̄/ ̄ ̄\ ̄○
∵\       --/∴∵!∴∵| ?。摺?∴∵ ̄ ̄ ̄ ̄ ̄ ̄ ̄∵∴∵--∴∵∴╰--╯∵∴
〓〓〓◇◇◇〓〓〓○○○〓〓〓☆☆☆〓〓〓〓
七、 linux shell界面打印版 效果展示

在這里插入圖片描述

八、 linux shell界面打印版 實現步驟
  1. 我們首先找到張圣誕樹圖片
    在這里插入圖片描述

  2. 圖片需要轉換成pnm格式 可以利用在線轉換網站或者工具進行轉換 , 轉換后的文件名字 重命名 例如叫 merry.pnm

  3. 將圖片上傳至linux,

  4. centos使用ascillview merry.pnm命令
    Ubuntu使用aview merry.pnm命令

注: 使用命令前需要先安裝aa-lib,aview,ImageMagick等環境 ,
具體教程可以在我博客主頁搜索 : 如何實現將圖片用代碼打印出來

你是否還在尋找穩定的海外服務器提供商?創新互聯www.cdcxhl.cn海外機房具備T級流量清洗系統配攻擊溯源,準確流量調度確保服務器高可用性,企業級服務器適合批量采購,新人活動首月15元起,快前往官網查看詳情吧

名稱欄目:【圣誕快樂】如何用代碼畫一顆圣誕樹?-創新互聯
新聞來源:http://www.yijiale78.com/article42/csodhc.html

成都網站建設公司_創新互聯,為您提供定制開發、App設計、App開發移動網站建設、服務器托管ChatGPT

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

手機網站建設