双十一要到了,好激动啊!!!

    

  是时候准备出手了!

    

花了一天的时间写的表白代码。

    

  表示自己弱弱的.....

    

看了网上好多都是js写的,感觉碉堡了!js用的不熟,前端不好,java,Python写起来一定很顺手吧,但是还是决定用c写一下,简单的界面,大神路过不喜勿喷。下面和大家一起分享一下!

代码如下:

  顺便所以下:如果在windows上运行该代码,需要pthread库,我用的Dev c++写的,自己装上了这个库!

        运行程序下载:http://files.cnblogs.com/files/hujunzheng/love.zip

该程序主要包含windows编程,以及简单的线程,数学逻辑处理(弱弱的说一句,数学不好,动态心形图案借鉴的哦)。 简单介绍一下一些函数的功能。
1.GetStdHandle(STD_OUTPUT_HANDLE);//获取控制台输出句柄
2.SetConsoleScreenBufferSize(o, size); // 重新设置缓冲区大小
3.SMALL_RECT rc = {0, 0, 100-1, 40-1}; // 重置窗口位置和大小
SetConsoleWindowInfo(o, true, &rc);
4.SetConsoleTitle("LOVE");//设置控制台标题
5.system("color ec"); // 设置为红色,显得浪漫温馨点
6.SetConsoleTextAttribute(o, hjzgg_color[color_index]);//设置下个即将输出字体的前景色和背景色
7.SetConsoleCursorPosition(o, coord);//设置控制台光标的位置
8.WriteConsole(o, one_word, 2, NULL, 0);//在控制台光标的位置处连续输出一定长度的字符串
9.pthread_mutex_lock(&mutex);//给线程上锁,利用互斥变量
10.pthread_mutex_unlock(&mutex);给线程解锁
11.pthread_create(&tid[1], NULL, first_init_down, NULL); //创建线程
12.pthread_join(tid[0], NULL);//用来等待一个线程的结束
13.pthread_cond_timedwait(&cond, &mutex, &outtime);//线程进入等待,一定时间后自行苏醒
#include <stdio.h>
#include <math.h>
#include <windows.h>
#include <tchar.h>
#include <pthread.h>
#include <time.h>
#include <string.h>
#include <sys/time.h> pthread_mutex_t mutex;//互斥信号量
pthread_cond_t cond;//条件变量
HANDLE o = GetStdHandle(STD_OUTPUT_HANDLE);
_TCHAR buffer[][] = { _T(' ') };
_TCHAR ramp[] = _T(".:-=+*#%@"); WORD hjzgg_color[]={
BACKGROUND_INTENSITY|FOREGROUND_INTENSITY|FOREGROUND_RED | BACKGROUND_RED|BACKGROUND_GREEN, //red on yellow BACKGROUND_INTENSITY|FOREGROUND_INTENSITY|FOREGROUND_GREEN | BACKGROUND_RED|BACKGROUND_GREEN,
BACKGROUND_INTENSITY|FOREGROUND_INTENSITY|FOREGROUND_BLUE | BACKGROUND_RED|BACKGROUND_GREEN, BACKGROUND_INTENSITY|FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE | BACKGROUND_RED|BACKGROUND_GREEN, BACKGROUND_INTENSITY|FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN | BACKGROUND_RED|BACKGROUND_GREEN,
BACKGROUND_INTENSITY|FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE | BACKGROUND_RED|BACKGROUND_GREEN,
BACKGROUND_INTENSITY|FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE | BACKGROUND_RED|BACKGROUND_GREEN }; float f(float x, float y, float z) {
float a = x * x + 9.0f / 4.0f * y * y + z * z - ;
return a * a * a - x * x * z * z * z - 9.0f / 80.0f * y * y * z * z * z;
} float h(float x, float z) {
for (float y = 1.0f; y >= 0.0f; y -= 0.001f)
if (f(x, y, z) <= 0.0f)
return y;
return 0.0f;
} char flower1[][]={//一行20个字符
" {@} ",
" {@} * {@} ",
" {@} * {@} * {@} ",
"{@}* {@} * {@} * {@}",
" \\ {@} * {@} * {@} /",
" \\ \\ \\ L / / / ",
" \\\\ \\ O / // ",
" \\\\ V // ",
" \\\\E// ",
" >=< ",
" //*\\\\ "
}; char flower2[][]={//一行27个字符
".....@---------------@.....",
"-- @ @ @ --------- @ @ @ --",
".@ @\\@/@ @-------@ @\\@/@ @.",
".\\@|@|@|@/-....--\\@|@|@|@/.",
". \\\\\\|/// --..--- \\\\\\|/// -",
" - \\\\|// --..----- \\\\|//.--",
" -- \\|/--..---.---- \\|/---.",
" -- =&= ---..------ =&= ---",
" -- /|\\ --------.---/|\\ -.-"
} ; char piercing_arrow[][]={//一行33个字符
" ☆☆ ☆☆ ☆☆ ☆☆ ",
" ★★ ★ ★★ ",
" ☆☆ 快乐每一天 ☆☆ ",
" ★★ ★★ ",
">>>---------I LOVE YOU --------->",
" ★★ ★★ ",
" ☆☆ ☆☆ ",
" ★★ ★★ ",
" ☆☆ "
}; char love_word[][][]={//一共5个部分, 三行情书
{
"你 如 水 的 眸 光 笼 着 江 南 的 烟 雨",
"映 入 我 那 一 寸 一 寸 消 融 的 心",
"从 那 一 刻 我 不 在 属 于 自 己"
},
{
"我 默 默 收 集 你 的 所 有",
"不 知 还 要 多 久",
"却 不 曾 厌 倦"
}, {
"当 初 ,初 见 只 道 是 寻 常",
"寻 觅 ,何 枝 可 化 深 千 亿",
"犹 道 ,碧 桃 影 里 碧 三 声"
} ,
{
"在 这 个 年 纪 远 远 地 看 着 你",
"日 光 美 好 的 一 泻 千 里",
"温 暖 着 一 个 卑 微 而 简 单 的 心"
} ,
{
"你 的 一 纸 信 笺",
"压 在 书 底",
"压 过 了 青 春 的 夏 季",
"从 爱 你 的 花 季",
"一 直 等 到",
"爱 你 的 暮 年"
}
} ; void init_screen(){
COORD size = {, };
SetConsoleScreenBufferSize(o, size); // 重新设置缓冲区大小
SMALL_RECT rc = {, , -, -}; // 重置窗口位置和大小
SetConsoleWindowInfo(o, true, &rc);
SetConsoleTitle("LOVE");
system("color ec"); // 设置为红色,显得浪漫温馨点
} void* show_love_word(void* arg){
srand((unsigned)time(NULL));//随机每束花是否显示
while(true) {
int word_index = rand()%;
int col = ;
int row_index = ;
if(word_index == )
row_index = ;
//显示word
int color_index = rand()%;
for(int i=; i<row_index; ++i){
int row = ;
for(int j=; love_word[word_index][i][j]; j+=){
char one_word[];//得到一个汉字
sprintf(one_word, "%c%c", love_word[word_index][i][j], love_word[word_index][i][j+]);
COORD coord = {col, row};
pthread_mutex_lock(&mutex);
SetConsoleTextAttribute(o, hjzgg_color[color_index]);
SetConsoleCursorPosition(o, coord);
WriteConsole(o, one_word, , NULL, );
coord.Y += ;
if(love_word[word_index][i][j+]){
SetConsoleCursorPosition(o, coord);
WriteConsole(o, "__", , NULL, );
}
SetConsoleTextAttribute(o, hjzgg_color[]);
pthread_mutex_unlock(&mutex);
++row;
Sleep();
}
col+=;
} Sleep(); //擦除Word
col-=;
for(int i=row_index-; i>=; --i) {
char hjzgg_word[];
memcpy(hjzgg_word, love_word[word_index][i], sizeof(love_word[word_index][i]));
int len_hjzgg_word = strlen(hjzgg_word);
int len_word = len_hjzgg_word;
bool is_first = true;
while(len_word >= ) {
int row = ;
for(int j=; j<len_hjzgg_word; j+=){
char one_word[];//得到一个汉字
sprintf(one_word, "%c%c", hjzgg_word[j], hjzgg_word[j+]);
COORD coord = {col, row};
pthread_mutex_lock(&mutex);
SetConsoleTextAttribute(o, hjzgg_color[color_index]);
SetConsoleCursorPosition(o, coord);
WriteConsole(o, one_word, , NULL, );
coord.Y += ;
if(j+ == len_word){
SetConsoleCursorPosition(o, coord);
WriteConsole(o, "__", , NULL, );
++row;
}
SetConsoleTextAttribute(o, hjzgg_color[]);
pthread_mutex_unlock(&mutex);
++row;
}
if(is_first){
is_first = false;
hjzgg_word[len_hjzgg_word++] = ' ';
hjzgg_word[len_hjzgg_word++] = ' ';
} else {
len_hjzgg_word-=;
}
hjzgg_word[--len_word] = ' ';
hjzgg_word[--len_word] = ' ';
Sleep();
}
col-=;
}
Sleep();
}
} void* first_init_top(void* arg){
char tmp[];
for(int ld=; ld < ; ++ld){
COORD coord_top = { , ld};
memset(tmp, ' ', sizeof(tmp));
int cc = ;
while(cc < ){
while(buffer[ld][cc]==' ') ++cc;
tmp[cc] = buffer[ld][cc];
++cc;
pthread_mutex_lock(&mutex);
SetConsoleCursorPosition(o, coord_top);
WriteConsole(o, tmp, , NULL, );
pthread_mutex_unlock(&mutex);
Sleep();
}
}
} void* screen_down_flower(void* arg){//从第26行开始打印
srand((unsigned)time(NULL));//随机每束花是否显示
int flower_row[] = {, , };
int flower_col[] = {, , };
int flower_begin_col[] = {, , };
int flower_begin_row[] = {, , };
struct timeval now;
struct timespec outtime;
pthread_mutex_lock(&mutex);
while(true){
int k = ;
while(k < ){
char flower[][] = {' '};
int color_index = rand()%;
SetConsoleTextAttribute(o, hjzgg_color[color_index]);
if(k== || k==){
for(int i=; i<flower_row[k]; ++i)
for(int j=; j<flower_col[k]; ++j)
flower[i][j] = flower1[i][j];
} else {
for(int i=; i<flower_row[k]; ++i)
for(int j=; j<flower_col[k]; ++j)
flower[i][j] = flower2[i][j];
}
for(int i=flower_begin_row[k], j=; j<flower_row[k]; ++j, ++i){
COORD coord = {flower_begin_col[k], i};
SetConsoleCursorPosition(o, coord);
WriteConsole(o, flower[j], flower_col[k], NULL, );
}
++k;
SetConsoleTextAttribute(o, hjzgg_color[]);//重新设置为原来的原色
gettimeofday(&now, NULL);
outtime.tv_sec = now.tv_sec;
outtime.tv_nsec = now.tv_usec * ;
pthread_cond_timedwait(&cond, &mutex, &outtime);
}
}
pthread_mutex_unlock(&mutex);
} void* first_init_down(void* arg){
char tmp[];
for(int rd=; <= rd; --rd){
COORD coord_down = { , rd };
SetConsoleCursorPosition(o, coord_down);
memset(tmp, ' ', sizeof(tmp));
int cc = ;
while(cc >= ){
while(buffer[rd][cc]==' ') --cc;
tmp[cc] = buffer[rd][cc];
--cc;
pthread_mutex_lock(&mutex);
SetConsoleCursorPosition(o, coord_down);
WriteConsole(o, tmp, , NULL, );
pthread_mutex_unlock(&mutex);
Sleep();
}
}
}
//一箭穿心图案
void show_piercing_arrow(){
for(int i=; i<; ++i) {
pthread_mutex_lock(&mutex);
COORD coord_down = { , i+ };
SetConsoleCursorPosition(o, coord_down);
WriteConsole(o, piercing_arrow[i], , NULL, );
pthread_mutex_unlock(&mutex);
}
} void first_init(){
show_piercing_arrow();
pthread_t tid[];
// screen_down_flower
pthread_create(&tid[], NULL, screen_down_flower, NULL);
// show_love_word
pthread_create(&tid[], NULL, show_love_word, NULL);
// 心型 init_first
pthread_mutex_init(&mutex, NULL);
pthread_cond_init(&cond, NULL);
pthread_create(&tid[], NULL, first_init_top, NULL);
pthread_create(&tid[], NULL, first_init_down, NULL);
pthread_join(tid[], NULL);
pthread_join(tid[], NULL);
} int main() {
init_screen();
bool first = true;
for (float t = 0.0f;; t += 0.1f) {
int sy = ;
float s = sinf(t);
float a = s * s * s * s * 0.2f;
for (float z = 1.3f; z > -1.2f; z -= 0.1f) {
_TCHAR* p = &buffer[sy++][];
float tz = z * (1.2f - a);
for (float x = -1.5f; x < 1.5f; x += 0.05f) {
float tx = x * (1.2f + a);
float v = f(tx, 0.0f, tz);
if (v <= 0.0f) {
float y0 = h(tx, tz);
float ny = 0.01f;
float nx = h(tx + ny, tz) - y0;
float nz = h(tx, tz + ny) - y0;
float nd = 1.0f / sqrtf(nx * nx + ny * ny + nz * nz);
float d = (nx + ny - nz) * nd * 0.5f + 0.5f;
*p++ = ramp[(int)(d * 5.0f)];
}
else
*p++ = ' ';
}
}
if(first){
first = false;
first_init();
}
else {
pthread_mutex_lock(&mutex);
for (sy = ; sy < ; sy++) {
COORD coord = { , sy };
SetConsoleCursorPosition(o, coord);
WriteConsole(o, buffer[sy], , NULL, );
}
pthread_mutex_unlock(&mutex);
}
Sleep();
}
return ;
}

c语言表白程序代码的更多相关文章

  1. 反编译工具 使用.NET JustDecompile来反编译你的程序代码

    原文地址:http://www.it165.net/pro/html/201310/7383.html 前言 在项目的进行中有时会碰到需要去了解由第三方所开发的程序代码或者因为年久已经遗失原始码的程序 ...

  2. 使用.NET JustDecompile来反编译你的程序代码

    前言 在项目的进行中有时会碰到需要去了解由第三方所开发的程序代码或者因为年久已经遗失原始码的程序,由于因为是别人写的所以我们并没有原始码可以直接阅读,碰到这种情况我们就需要去反编译这些程序及 DLL ...

  3. c语言—栈区,堆区,全局区,文字常量区,程序代码区 详解

    转:http://www.cnblogs.com/xiaowenhui/p/4669684.html 一.预备知识—程序的内存分配 一个由C/C++编译的程序占用的内存分为以下几个部分1.栈区(sta ...

  4. 零基础入门C/C++实现你的浪漫表白:浪漫流星雨表白程序

    想要讨女朋友欢心也巩固自己所学的知识,各位小伙伴有自己的想法了吗?准备好想要怎样实施了吗?有什么美好的计划了吗?如果没有的话那么别慌,我知道,在座的各位肯定都是有自己的心仪的姑娘,那么今天就教大家一招 ...

  5. 程序代码中退出函数exit()与返回函数return ()的区别

    程序代码中退出函数exit()与返回函数return ()的区别   exit(0):正常运行程序并退出程序:   exit(1):非正常运行导致退出程序:   return():返回函数,若在主函数 ...

  6. 每周一书-编写高质量代码:改善C程序代码的125个建议

    首先说明,本周活动有效时间为2016年8月28日到2016年9月4日.本周为大家送出的书是由机械工业出版社出版,马伟编著的<编写高质量代码:改善C程序代码的125个建议>. 编辑推荐 10 ...

  7. 如何快速读懂大型C++程序代码

    要搞清楚别人的代码,首先,你要了解代码涉及的领域知识,这是最重要的,不懂领域知识,只看代码本身,不可能搞的明白.其次,你得找各种文档:需求文档(要做什么),设计文档(怎么做的),先搞清楚你即将要阅读是 ...

  8. 通过反汇编C语言小程序学习Liunx汇编语言

    大家好!    我是来自山东师范大学的吴乐.    今天在<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 ...

  9. Linux下简单C语言小程序的反汇编分析

    韩洋原创作品转载请注明出处<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 写在开始,本文为因为参加MOO ...

随机推荐

  1. Java|今天起,别再扯订阅和回调函数

    编程史上有两个令人匪夷所思的说辞,一个是订阅,一个是回调函数. 我想应该还有很多同学为“事件的订阅”和“回调函数”所困扰,因为事情本来就不应该按这个套路来解释. 多直白,所谓的“回调函数”你完全可以线 ...

  2. java的基础知识文件操作和标识符

    1.文件夹的操作 dir :显示当前文件夹中的所有文件和文件夹. cd 路径:  进入到指定的路径. cd ..  : 回到上一级目录 cd  \ : 回到当前目录的跟目录 md 文件夹名  创建一个 ...

  3. IDEA+Tomcat+JRebel热部署

    在完成idea工程简单应用后,接下来实现热部署. 简单应用地址:http://wibiline.iteye.com/admin/blogs/2072454 一.安装JRebel插件 1. 在线安装 F ...

  4. 淘宝SDK扒出来的CURL调用含文件上传代码

    <?php function curl($url,$postFields=null){ $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$url); c ...

  5. Redis 做消息队列

    一般来说,消息队列有两种场景,一种是发布者订阅者模式,一种是生产者消费者模式.利用redis这两种场景的消息队列都能够实现.定义: 生产者消费者模式:生产者生产消息放到队列里,多个消费者同时监听队列, ...

  6. .Net程序员之不学Java做安卓开发:Android Studio中的即时调试窗口

    对学.Net的人来说,JAVA开发是一场噩梦. .net中的即时窗口,调试时直接在里面写代码,对程序中的各种方法/属性进行调用,很方便. Android Studio中找了好久,参考如下网址,也有类似 ...

  7. JeeSite学习笔记~代码生成原理

    1.建立数据模型[单表,一对多表,树状结构表] 用ERMaster建立数据模型,并设定对应表,建立关联关系 2.系统获取对应表原理 1.怎样获取数据库的表 genTableForm.jsp: < ...

  8. 编译链接 C++

    预处理之后的源文件被称为一个编译单位,也即编译器的工作对象.为了使编译能够进行,程序员必须提供各种程序其他部分的声明来孤立分析一个编译单位.所有名字空间,类,函数都应该在他们所在的编译单位中有声明,所 ...

  9. 享元模式 - Flyweight

    Flyweight(享元模式) 定义 GOF:运用共享技术有效地支持大量细粒度的对象. GOF的定义比较专业化,通俗来说,当你有大量相似的实例时,你把其中相同的实例取出来共享. 例子 在你的游戏场景中 ...

  10. maven web项目中web.xml

    web.xml 不是web工程必须的. web.xml文件用来配置那些东西:欢迎页,servlet,filter等. web.xml文件中定义了多少种标签元素,web.xml 中就可以出现它的模式文件 ...