TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
使用java画出蒙娜丽莎的微笑!ml.rar文件:需要读取的颜色值文件,可用写字板程序打开。
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- import java.awt.Color;
- import java.awt.Frame;
- import java.awt.Graphics;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- import java.awt.event.WindowListener;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JFrame;
- /**
- *
- * @author Administrator
- */
- public class PaintMonaLisa extends JFrame {
- private int x, y, R, G, B, w, h;
- private Color color;
- private int count;
- private int i;
- private List< String> list = new ArrayList< String>();
- public PaintMonaLisa() {
- this.setSize(600, 550);
- this.setBackground(Color.BLACK);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.setTitle("Java画蒙娜丽莎的微笑 QQ:909854136 开源中国: @hoodoo");
- this.setResizable(false);
- this.setLocationRelativeTo(null);
- }
- @Override
- public void paint(Graphics g) {
- color = new Color(R, G, B);
- g.setColor(color);
- g.fillRect(x+50, y+50, w, h);
- if (i < count){
- changeNextPoint(list.get(i));
- }
- }
- public void readFileInfo(String path) {
- File file = new File(path);
- try {
- BufferedReader bw = new BufferedReader(new FileReader(file));
- String line = null;
- while ((line = bw.readLine()) != null) {
- list.add(line);
- }
- bw.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- count=list.size();
- System.out.println(count);
- }
- private void changeNextPoint(String temp) {
- String[] s = temp.split("x");
- x = Integer.parseInt(s[0]);
- y = Integer.parseInt(s[1]);
- w = Integer.parseInt(s[2]);
- h = Integer.parseInt(s[3]);
- R = Integer.parseInt(s[4].substring(0, 2), 16);
- G = Integer.parseInt(s[4].substring(2, 4), 16);
- B = Integer.parseInt(s[4].substring(4, 6), 16);
- try {
- Thread.sleep(1);
- } catch (InterruptedException ex) {
- }
- i++;
- repaint();
- }
- public static void main(String[] args) {
- final PaintMonaLisa s = new PaintMonaLisa();
- s.readFileInfo("ml");
- s.open();
- }
- private void open() {
- this.setVisible(true);
- }
- }
- 直接运行:如下图。
复制代码
源码下载:http://file.javaxxz.com/2014/11/13/235911843.zip |
|