当前位置: 首页 > article >正文

圣诞将至—C语言圣诞树代码来啦

文章目录

  • 圣诞将至—C实现语言圣诞树
  • 源码

圣诞将至—C实现语言圣诞树

圣诞树

在这里插入图片描述

源码

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <windows.h>
#include <time.h>
#define PI 3.14159265359
char love[20][43] = {
    "111111111111111111111111111111111111111111",
    "111111111111110000111111100001000111111111",
    "110000000000000000011111100011000111111111",
    "110000111001110001111111000110001111111111",
    "111100010000110000111111100011000000000011",
    "111100001000100011111110000100011111100011",
    "100000000000000000001110000100011111000111",
    "100000000000000000011100000000110001000111",
    "100011100011111000110000000000110001111111",
    "111011100011111100111111000111110001111111",
    "111000000000000000111111000110000000001111",
    "111111000111111111111111000110000000000111",
    "111110001111111111111111000100010001000111",
    "111000000000000001111111000000010001100011",
    "111000000011000011111111000000110001100001",
    "110001110000000111111111000001110001110111",
    "100011111000011111111111000111110001111111",
    "111110000000000000011111000111000001111111",
    "111000000111110000011111000111000011111111",
    "111111111111111111111111111111111111111111"
};

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;
    for (float r = 0.0f; r < 0.8f; r += 0.02f)
        d = opUnion(d, sdCircle(T, 0.05f * scale * (0.95 - r)));
    if (n > 0)
        for (int t = -1; t <= 1; t += 2)
        {
            float tt = theta + t * 1.8f;
            float ss = scale * 0.9f;
            for (float 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 < 19; i++, y++)
    {
        x = 60;
        for (j = 0; j < 42; j++, x++)
        {
            gotoxy(x, y);
            if (love[i][j] == '1')
            {
                putchar(' ');
            }
            else {
                SetColor(0x06);
                putchar('*');
            }
        }
    }
    for (n = 0; n++ < 365;)
    {
        showsnow();
    }
    gotoxy(0, 40);
    getchar();
    return 0;
}

http://www.kler.cn/news/161166.html

相关文章:

  • VIR-SLAM代码分析3——VIR_VINS详解之estimator.cpp/.h
  • Wnmp本地搭建结合内网穿透实现远程访问本地Wnmp服务
  • 使用VS Code远程开发MENJA小游戏并通过内网穿透分享本地游戏到公网
  • NR重写console.log 增加时间信息
  • 在Linux上安装KVM虚拟机
  • 冒泡排序详解
  • Android 记录一些Framework开发的命令
  • Think in Java之多态
  • 2024年网络安全比赛--系统渗透测试(超详细)
  • vue.js el-table 动态单元格列合并
  • 数据库压力测试方法小结
  • TiDB专题---2、TiDB整体架构和应用场景
  • YashanDB练习SQL
  • CFLAGS、CXXFLAGS、FFLAGS、FCFLAGS、LDFLAGS、LD_LIBRARY_PATH区别
  • 高效的单行python脚本
  • C++ 指针进阶
  • Python-函数详解(局部、全局变量)
  • Springboot resource 下的excel
  • keep-alive 是 Vue 的一个内置组件,用于缓存其他组件的实例,以避免重复渲染和销毁,它可以在需要频繁切换的组件之间提供性能优化
  • Antd search input无中框
  • 2次MD5加密——用于分布式对话
  • 种下一棵栀子花
  • 先验概率和后验概率
  • KubeSphere Marketpalce 上新!Databend Playground 助力快速启动数据分析环境
  • 交叉验证以及scikit-learn实现
  • axios创建实例对象,发送ajax请求,配置baseUrl
  • 2024 年前端技术发展大趋势一览
  • idea本地调试hadoop 遇到的几个问题
  • 【灰度发布】APP如何实现灰度发布
  • 网络运维与网络安全 学习笔记2023.12.3