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

    

  是时候准备出手了!

    

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

    

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

    

看了网上好多都是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. PHP 分页函数

    如果如下:

  2. JS /JQuery 获取变量为数字时 容易出错 可能不是数字类型

    Javascript内置函数,原型为parseInt ( String s , [ int radix ] ),用于解析一个字符串,并返回一个整数. var $prod_kucun=$(this).n ...

  3. 弹出popwindow 背景变暗

    先看下效果图吧 代码如下 package com.example.administrator.popwindowdemo.view; import android.app.Activity; impo ...

  4. paramiko模块的安装

    1.找到自己python安装的目录(默认路径:C:\Users\zhangliyuan\AppData\Local\Programs\Python\Python35) 注:cmd中所有命令 2.进入S ...

  5. C# EXCEL导入 混合列文字为空,找不到可安装的 ISAM的解决办法

    C# EXCEL导入 混合列文字为空,找不到可安装的 ISAM的解决办法 使用C#导入 Excel数据到 DataTable,如果连接串中只写 Excel 8.0,则正常的字符列,数值列都没有问题,但 ...

  6. 关于C#的微信开发的入门记录一

    在之前老是看到一些微信开发的例子,但是作为初学者会有很多问题,之前我也找了很多帖子,但是最终也没能解决,现在刚好手里有一个项目,总结一下分享给准备做却动不了手的朋友们,本文只是以我个人的经验作为浅谈( ...

  7. System.Dynamic.ExpandoObject 类型的简单使用

    该类型可以实现的是动态添加属性和移除属性,有点类似 js 中对象的操作,非常灵活 static void Main(string[] args) { dynamic obj = new System. ...

  8. mysql 命令行还原备份数据库

    通常数据库还原备份可以通过navicat等数据库管理工具进行,只需要简单的导出导入就行了,但遇到有索引外键的数据库,数据库管理工具运行.sql文件会报错,这时候可以尝试命令行导入,亲测可以成功 MyS ...

  9. ubuntu 下emacs 配置

    (set-language-environment 'Chinese-GB) (set-keyboard-coding-system 'utf-8) (set-clipboard-coding-sys ...

  10. ABP理论学习之授权(Authorization)

    返回总目录 本篇目录 介绍 定义权限 检查权限 使用AbpAuthorize特性 使用IPermissionChecker Razor视图 客户端(Javascript) 权限管理者 介绍 几乎所有的 ...