『C # 開發』技能 Get√ ——制作CMD界面的簡單GIF圖片


    今天看到C#課本上個列子把星號(*)有規則打印在控制台中間位置

    程序不難,利用的是光標定位函數Console.SetCursorPosition(x, y)做到的

    心想是不是弄出一個動態的圖案比較好玩啊,說Gan就Gan~

    可是問題來了:

    以我毫無藝術細胞且又愚笨無比的大腦,實在想不出什么優美的圖案

    即使想出來我也未必做的出啊 0.0 

    最終,還是覺得做出來一個弓箭射出的動態圖比較Easy

    看到的小伙伴們且噴且珍惜 ...

 

0x 01 作品展示

    視頻我引不過來 = =

    先把鏈接貼上吧

    http://v.youku.com/v_show/id_XNzk1NTI4MDQw_type_99.html

0x 02 設計圖案素材

    我大火影各種炫酷,基情的動畫不也是從動漫圖一張張拼起來的么

    現在先在TXT上把圖案先點出來(好費勁我會亂說.......)

    Pic 1,2,3,4

    

    

    素材就用上面四張就 OK了,在C#中讓他們延時(sleep)打印出來

    最后利用循環定位函數把箭(➹)射出來 

0x 03 代碼展示

 1 using System;  2 using System.Collections.Generic;  3 using System.Linq;  4 using System.Text;  5 using System.Threading;  6 /*=============================================================================  7 1 * 功能描述:射箭GIF  8 2 * 創 建 者:Anka9080  9 3 * 創建日期:2014/10/2 19:35:05 10 ==============================================================================*/
11 namespace SheJian 12 { 13     class Program 14  { 15         static void Main(string[] args) 16  { 17             Console.Title = "猜猜我射的中不~~~"; 18             while (true) { 19                 //清屏並設置前景色
20  Console.Clear(); 21                 Console.ForegroundColor = ConsoleColor.Red; 22                // Console.Beep(); 23                 // 初始狀態
24                Console.Write(" *\n * *\n"+
25 " * *\n * **\n * **\n"+
26 " * *\n *** * * *\n **********************************\n"+
27 " *** * * *\n * *\n * **\n"+
28 " * **\n * *\n * *\n"+
29 " *\n"); 30                 Thread.Sleep(500); 31  Console.Clear(); 32                 Console.Write(" *\n * *\n" +
33 " * *\n * **\n * **\n" +
34 " * *\n *** * * *\n " +
35 " *******************************\n *** * * *\n" +
36 " * *\n * **\n * **\n" +
37 " * *\n * *\n *\n"); 38                 Thread.Sleep(200); 39  Console.Clear(); 40                 Console.Write(" *\n * *\n" +
41 " * *\n * **\n * **\n"+
42 " * *\n *** * * *\n"+
43 " ***************************\n *** * * *\n"+
44 " * *\n * **\n * **\n"+
45 " * *\n * *\n *\n"); 46                 Thread.Sleep(200); 47  Console.Clear(); 48                 Console.Write(" *\n * *\n"+
49 " * *\n * **\n * **\n"+
50 " * *\n * * *** *\n"+
51 " * * ***************************\n * * *"+
52 "** *\n * *\n * **\n"+
53 " * **\n * *\n"+
54 " * *\n *\n"); 55                 Thread.Sleep(200); 56  Console.Clear(); 57            
58                 for (int i = 1; i < 20; i++) 59  { 60      
61                 // 定位輸出箭頭部分代碼
62                 
63                     string pre = string.Format("{0,32}",' '); 64                     Console.SetCursorPosition(0+i, 6); 65                     Console.Write(pre+"*** *\n"); 66                     Console.SetCursorPosition(0+i, 7); 67                     Console.Write(pre+" ***************************\n"); 68                     Console.SetCursorPosition(0+i, 8); 69                     Console.Write(pre+"*** *\n"); 70                     Console.SetCursorPosition(0, 0); 71                     Console.Write(" *\n * *\n" +
72 " * *\n * **\n * **\n" +
73 " * *\n * *\n" +
74 " * *\n * *\n * *\n" +
75 " * **\n * **\n * *\n" +
76 " * *\n *\n"); 77                     Thread.Sleep(100); 78  Console.Clear(); 79  } 80 
81 
82 
83                     Thread.Sleep(500); 84                
85  } 86  } 87  } 88 }

    基本實現思路在0x 02已經說了,這里就不敘述了~


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM