圣诞树C语言代码(完整)

 C语言圣诞树代码还在东找西找?

 这里看,这里看

直接复制、粘贴就行

完整代码

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <windows.h>
#include <time.h>
#define PI 3.14159265359
#define L1 16*4+1    //4代表4个字
#define L2 16*3+1    //3代表3个字
char love[17][L1] = {
"1111111111111111111111111111011111101111011111111111111111011111",
"1100000000000111101111111110001111101111011111111111111100001111",
"1110111111101111110100001000111111101111011111111110000011111111",
"1111001110011111110111101110111111101111011101111110111111111111",
"1111110101111111111111011110111110100100000000111110111011111111",
"1111111011111111111110111110111110101011011101111110111011111111",
"1111110100111111000100001010001110101111011101111101111011111011",
"1111001111001111110111101010111101101111011101111000000000000001",
"1100111011110001110101101010111111101111011101111111111011111111",
"0011111011011011110110101010111111100000000000011111111011111111",
"1110000000001111110111011010111111101111011111111111011011011111",
"1111111011111111110101011000001111101110101111111111011011101111",
"1111111011111111110011001111111111101110110111111110111011110111",
"1111111011111011110110110111111111101101111011111101111011110011",
"0000000000000001111101111011100111101011111100011011101011111011",
"1111111111111111111011111100001111100111111110111111110111111111",
};
char names[17][L2] = {
"111111101111111111111111100011111111111110001111",
"111111101111111111100000011111111110000001111111",
"111111101111111111111110111111111111111011111111",
"111111101111111111111110111110111111111011111011",
"111111101111111100000000000000010000000000000001",
"111110101011111111111110111111111111111011111111",
"111110101101111111110110110110111111011011011011",
"111101101110111111110110110100111111011011010011",
"111101101111011110000110110011111000011011001111",
"111011101111101111110110110111111111011011011111",
"110111101111101111110110110111011111011011011101",
"101111101111111111000110110111011100011011011101",
"111111101111111100110110111000010011011011100001",
"111111101111111111111110111111111111111011111111",
"111110101111111111111110111111111111111011111111",
"111111011111111111111110111111111111111011111111",
};

void gotoxy(int x, int y)
{
	HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
	COORD pos = { x,y };
	SetConsoleCursorPosition(hout, pos);
}

void SetColor(int color)
{
	if (color == 0)color = 0x04;
	HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hCon, color);
}

void showsnow()
{
	SetColor(rand() % 16);
	int x = rand() % 120;
	int y = rand() % 40;
	gotoxy(x, y);
	putchar('*');
}

float sx, sy;
float sdCircle(float px, float py, float r)
{
	float dx = px - sx, dy = py - sy;
	return sqrtf(dx * dx + dy * dy) - r;
}
float opUnion(float d1, float d2)
{
	return d1 < d2 ? d1 : d2;
}
#define T px+scale*r*cosf(theta),py+scale*r*sin(theta)
int ribbon()
{
	float x = (fmodf(sy, 0.1f) / 0.1f - 0.5f) * 0.5f;
	return sx >= x - 0.05f && sx <= x + 0.05f;
}
float f(float px, float py, float theta, float scale, int n)
{
	float d = 0.0f,r;
	int t;
	for (r = 0.0f; r < 0.8f; r += 0.02f)
		d = opUnion(d, sdCircle(T, 0.05f * scale * (0.95 - r)));
	if (n > 0)
		for (t = -1; t <= 1; t += 2)
		{
			float tt = theta + t * 1.8f;
			float ss = scale * 0.9f;
			for (r = 0.2f; r < 0.8f; r += 0.1f)
			{
				d = opUnion(d, f(T, tt, ss * 0.5f, n - 1));
				ss *= 0.8f;
			}
		}
	return d;
}

int main(int argc, char* argv[])
{
	system("mode con cols=120 lines=42");
	srand((int)time(NULL));
	SetConsoleCP(437);
	SetConsoleOutputCP(437);
	int n = argc > 1 ? atoi(argv[1]) : 3;
	float zoom = argc > 2 ? atof(argv[2]) : 1.0f;
	for (sy = 0.8f; sy > 0.0f; sy -= 0.02f / zoom, putchar('\n'))
	{
		for (sx = -0.35f; sx < 0.35f; sx += 0.01f / zoom)
		{
			if (f(0, 0, PI * 0.5f, 1.0f, n) < 0.0f)
			{
				if (sy < 0.1f)
				{
					SetColor(rand() % 16);
					putchar('\3');
				}
				else {
					if (ribbon()) {
						putchar('=');
					}
					else {
						SetColor(rand() % 16);
						putchar('\3');
					}
				}
			}
			else {
				putchar(' ');
			}
		}
	}

	int i, j;
	int x, y = 3;
	for (i = 0; i < 17-1; i++, y++)
	{
		x = 53;
		for (j = 0; j < L1-1; j++, x++)
		{
			gotoxy(x, y);
			if (love[i][j] == '1')
			{
				putchar(' ');
			}
			else {
				SetColor(0x06);
				putchar('*');
			}
		}
	}
	y = 22;
	for (i = 0; i < 17 - 1; i++, y++)
	{
		x = 60;
		
		for (j = 0; j < L2 - 1; j++, x++)
		{
			gotoxy(x, y);
			if (names[i][j] == '1')
			{
				putchar(' ');
			}
			else {
				SetColor(0x06);
				putchar('*');
			}
		}
	}
	for (n = 0; n++ < 365;)
	{
		showsnow();
	}
	gotoxy(0, 40);
	getchar();
	return 0;
}

但是如何自定义文字呢?

这就需要文字转为点阵

莫慌!!!

我都给你们准备好了 

然后复制,把代码里的内容替换就行了

切记!!一定要替换 L1、L2中的‘字数’(不然显示会有影响!!)

 

 文件、代码、文字点阵生成器链接

链接:https://pan.baidu.com/s/1WM4-LEnoWku-gVzvXeYiOw 
提取码:SFYM

如果圣诞树显示有问题

  • 12
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值