win7 dos窗口模拟帧刷新
前几天是白色情人节,临时脑抽写了个表白神器 高端大气上档次,就是不知道该送给谁,经过两天的反射弧思考决定还是写给博客娘吧。- -~
这个程序就是打开后,在Dos窗口内模拟写出几行字母。其实主要就是模拟一下帧刷新。像游戏引擎那样每一帧都打印一个满屏,那么所有的动画也就出来了。想在里边写个小游戏也未尝不可。
但是理想丰满现实骨感,Dos窗口不断帧刷新效果很一般,是不是会出现跳动的情况,很蛋疼。
win7 dos窗口的默认宽度是80个字符,高度是25个字符。经过简单的处理,通过调用Sleep函数来控制间隔时间来无限打印80x25的字符串集合,就能模拟帧刷新了,非常的简单。
c/c++版本代码
#include <stdio.h> #include <iostream> #include <string.h> #include <stdlib.h> #include <windows.h> #include <vector> using namespace std; //全局变量 标记是否处于update状态 bool update_flag = false; //全局数组,每一帧打印的所有字符 ]; //全局变量,打印刷新计数器 ; //结构体 代表80x25中的一个点 struct _pos { int _x; int _y; _pos(int x, int y) : _x(x), _y(y){} }; //刷新函数的函数指针 typedef void(*_update)(vector<_pos>&); _pos makepos(int x, int y) { _pos ret(x, y); return ret; } //初始化要打印的点阵 虽然屏幕是80个字符的宽度,但是字符要多一个,原因是\0的字符串结尾标识符占一个//最后一行做特殊处理 没有\n换行符,以免每一帧的时候窗口被向下延伸一行 void init_screen() { ; i < ; i++) { screen[i] = (); memset(screen[i], ); //if (i == 0) screen[i][0] = 'x'; screen[i][] = '\n'; screen[i][] = '\0'; ) { screen[i][] = '\0'; screen[i][] = '\0'; } } } //打印一帧的屏幕 上边缺失的换行符在这里补充 void display_screen() { printf("\n"); ; i < ; i++) { printf(screen[i]); } } //更改某一点的显示字符 void set_char(int x, int y, char target) { && x < && y >= && y < ) { char* index = (screen[x] + y); *index = target; } } //开始update函数 void start_update(_update update_function, int daley, vector<_pos>& _vec) { update_flag = true; while (update_flag) { Sleep(daley); update_function(_vec); } } //停止update void stop_update() { update_flag = false; } //每一帧执行的函数 void processing(vector<_pos>& _vec) { if (pro_count < _vec.size()) set_char(_vec[pro_count]._x, _vec[pro_count]._y, 'o'); display_screen(); pro_count++; } //制作一个序列,这个序列用来保存需要 更改的点 void init_vec(vector<_pos>& vec) { vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); vec.push_back(makepos(, )); } int main(int argc, char* argv[]) { vector<_pos> poses; init_vec(poses); init_screen(); _update _s_fun = processing; start_update(_s_fun, , poses); system("pause"); }
下面是C#版本 C#版本追加了颜色变化效果,更浪♂van
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; namespace confession { class Program { static void Main(string[] args) { InitScreen(); DisplayScreen(); List<Pos> poses = new List<Pos>(); InitPoses(poses); Update(, poses); Console.ReadKey(); } static void InitPoses(List<Pos> poses) { poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); poses.Add(Pos.MakePos(, )); } static private string[] screen; static private bool update_flag; static private int pro_count; static void InitScreen() { screen = ]; update_flag = true; pro_count = ; ; i < ; i++) { screen[i] = ); ) screen[i] += "\n"; else screen[i] += ""; } } static void SetChar(int x, int y, char target) { && x < && y >= && y < ) { char[] line = screen[x].ToCharArray(); line[y] = target; string newLine = new string(line); screen[x] = newLine; } } static void Update(int delay, List<Pos> poses) { while (update_flag) { Thread.Sleep(delay); Processing(poses); } } static void Processing(List<Pos> poses) { if (pro_count < poses.Count) { SetChar(poses[pro_count].X, poses[pro_count].Y, 'o'); } else { DisplayColor(); } DisplayScreen(); ; pro_count++; } static void StartUpdate() { update_flag = true; } static void StopUpdate() { update_flag = false; } static void DisplayScreen() { Console.WriteLine(); ; i < ; i++) { Console.Write(screen[i]); } } static void DisplayColor() { ; ; switch (_type) { : Console.ForegroundColor = ConsoleColor.Cyan; break; : Console.ForegroundColor = ConsoleColor.DarkGray; break; : Console.ForegroundColor = ConsoleColor.Red; break; : Console.ForegroundColor = ConsoleColor.White; break; : Console.ForegroundColor = ConsoleColor.Yellow; break; : Console.ForegroundColor = ConsoleColor.Green; break; : Console.ForegroundColor = ConsoleColor.Magenta; break; : Console.ForegroundColor = ConsoleColor.Blue; break; } } } class Pos { private int x; private int y; public int X { get { return x; } set { x = value; } } public int Y { get { return y; } set { y = value; } } Pos(int _x, int _y) { x = _x; y = _y; } public static Pos MakePos(int _x, int _y) { Pos ret = new Pos(_x, _y); return ret; } } }
编译后有惊喜 噗噗噗
win7 dos窗口模拟帧刷新的更多相关文章
- 学习java之电脑的常用快捷键和DOS窗口下的常用命令
学习java之电脑的常用快捷键和DOS窗口下的常用命令 电脑一些常用的快捷键 win快捷键: 单独按Windows:显示或隐藏 "开始"功能表 Windows+BREAK:显示&q ...
- Windows环境变量设置无效解决办法——DOS窗口设置环境变量
公司配置的电脑是Win7,使用的账户并不是管理员账户,我在计算机->属性中设置环境变量无效. 后来在DOS窗口中设置环境变量成功. 1. set [环境变量名称]=[所有环境变量值]:set P ...
- 系统右键菜单添加剪贴板清空项(隐藏DOS窗口)
@color 0A @title 系统右键菜单添加剪贴板清空项(隐藏DOS窗口) by wjshan0808 @echo off echo 请输入右键菜单名称 set /p name= ::创建本机A ...
- 打包bat等文件成exe,双击运行不显示dos窗口,exe不报毒
准备材料如下bat和vbs直接新建文本,然后改后缀就可以建出来了(后面发现exe运行vbs来启动bat不报毒)下面内容就是要把这些文件打包成exe,双击exe后打开图片test.jpg,不显示dos窗 ...
- visual studio 2005 编fortran程序,运行后dos窗口显示问题
比如程序: program main implicit none write(*,*) "AAAAAAAAAAAAAAAAAAAAAAAA" stop end 虽然可以看见DOS窗 ...
- HTML的窗口分帧
下面通过一个后台管理的部分设计来说明窗口分帧 frameset.html代码 <!-- <frameset>标签(常用来做后台管理界面) 属性:rows(行).cols(列).可以使 ...
- window.open窗口关闭后刷新父窗口代码
window.open窗口关闭后刷新父窗口代码 window.opener.location.href=window.opener.location.href;window.close();
- VS2012 编写C++程序的时候DOS窗口一闪而过解决办法。
在我每次通过VS2012 运行C++程序的时候,DOS窗口在显示结果的时候都是一闪而过.这样让人没法观察输出的结果.经试验找到了一较好的解决办法: 首先包含头文件"stdlib.h" ...
- 让windows系统的DOS窗口也可以显示utf8字符集
C:\Users\Administrator>chcp活动代码页: 936 windows cmd命令显示UTF8设置 在中文Windows系统中,如果一个文本文件是UTF-8编码的,那么在CM ...
随机推荐
- UDK游戏打包详解
转自:http://blog.sina.com.cn/s/blog_944177030100ycki.html 安装完的udk目录下有4个主要的文件夹 Binaries -这个文件夹包含游戏的exe程 ...
- Elasticsearch集成ik分词器
1.插件地址https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.0.0/elasticsearch-anal ...
- 用python监控您的window服务
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://world77.blog.51cto.com/414605/782935 最近比较 ...
- chromium浏览器开发系列第五篇:Debugging with WinDBG
Windbg 相信windows开发的人都知道,有些人用的溜儿溜儿的,有个crash,直接拿这个工具一分析,就定位出来了.非常好用.以前有个同事,做sdk开发 的,会各种命令.来北京后,还去过微软面试 ...
- ACM-ICPC2018徐州网络赛 Features Track(二维map+01滚动)
Features Track 31.32% 1000ms 262144K Morgana is learning computer vision, and he likes cats, too. ...
- WordPress博客搭建指南
WordPress是一个以PHP和MySQL为平台的自由开源的博客软件和内容管理系统.WordPress具有插件架构和模板系统.Alexa排行前100万的网站中有超过16.7%的网站使用WordPre ...
- Linux 错误集锦
1. CentOS 7 运行yum时出现/var/run/yum.pid已被锁定,PID为xxxx的另一个程序正在运行的问题解决 解决办法: rm -f /var/run/yum.pid,删除文件后再 ...
- Python:关于subprocess.stdout.read()导致程序死锁的问题
subprocess.stdout.read()导致程序死锁的问题解决 今天有位老哥联系我说,在我的python之路系列中,解决粘包问题那一章的代码有BUG 这里当运行命令过于庞大的时候,会导致程序直 ...
- linux命令之grep,find
grep命令 grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索 ...
- 静态文件与APP
目录 静态文件的配置和使用 什么是静态文件? 为什么使用静态文件 如何配置,使用静态文件 静态文件相关(动态配置) app创建预注册 app指什么? 创建一个APP 注册app app文件作用 app ...