用break语句,随机选择今天吃什么;c++打印3D爱心

#include<iostream>
using namespace std;
int main() {
	
	int num = 0;
	cout << "请输入任意一个正整数:" << endl;
	cin >> num;
	num = num % 26 + 1;

	switch (num)
	{
	case 1:
		cout << "您今天吃" << "Snail Rice-flour Noodles" << endl;
		break;
	case 2:
		cout << "您今天吃" << "Rice Noodle" << endl;
		break;
	case 3:
		cout << "您今天吃" << "Shrimp" << endl;
		break;
	case 4:
		cout << "您今天吃" << "Clay oven rolls" << endl;
		break;
	case 5:
		cout << "您今天吃" << "Fried bread stick" << endl;
		break;
	case 6:
		cout << "您今天吃" << "Boiled dumplings" << endl;
		break;
	case 7:
		cout << "您今天吃" << "Steamed dumplings" << endl;
		break;
	case 8:
		cout << "您今天吃" << "Steamed buns" << endl;
		break;
	case 9:
		cout << "您今天吃" << "Steamed sandwich" << endl;
		break;
	case 10:
		cout << "您今天吃" << "Rice and vegetable roll" << endl;
		break;
	case 11:
		cout << "您今天吃" << "Stinky Tofu" << endl;
		break;
	case 12:
		cout << "您今天吃" << "Hot and Sour Rice Noodles" << endl;
		break;
	case 13:
		cout << "您今天吃" << "Duck Blood Soup with Vermicelli" << endl;
		break;
	case 14:
		cout << "您今天吃" << "Sweet and Sour Spare Ribs" << endl;
		break;
	case 15:
		cout << "您今天吃" << "Baozi Stuffed with Juicy Pork" << endl;
		break;
	case 16:
		cout << "您今天吃" << "Cold Rice Noodles" << endl;
		break;
	case 17:
		cout << "您今天吃" << "Spicy Crayfish" << endl;
		break;
	case 18:
		cout << "您今天吃" << "Lamb Kebabs with Cumin" << endl;
		break;
	case 19:
		cout << "您今天吃" << "Wonton Soup in Hot and Spicy Sauce" << endl;
		break;
	case 20:
		cout << "您今天吃" << "Proper Street Kebabs" << endl;
		break;
	case 21:
		cout << "您今天吃" << "Beijing Roast Duck" << endl;
		break;
	case 22:
		cout << "您今天吃" << "Malatang" << endl;
		break;
	case 23:
		cout << "您今天吃" << "Grilled Cold Noodles" << endl;
		break;
	case 24:
		cout << "您今天吃" << "Shaxian Snacks" << endl;
		break;
	case 25:
		cout << "您今天吃" << "Pita Bread Soaked in Lamb Soup" << endl;
		break;
	case 26:
		cout << "您今天吃" << "Tofu Pudding" << endl;
		break;
	}
	system("pause");
	return 0;
}

运行结果截图

#include<stdio.h>
#include<math.h>
#include<windows.h>
#include<tchar.h>

float f(float x, float y, float z) {
    float a = x * x + 9.0f / 4.0f * y * y + z * z - 1;
    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;
}

int main() {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0C);
    HANDLE o = GetStdHandle(STD_OUTPUT_HANDLE);
    _TCHAR buffer[25][80] = { _T(' ') };
    _TCHAR ramp[] = _T(".:-=+*#%@");
    int count = 0;
    int count1 = 0;
    //system("color F4");
    for (float t = 0.0f;; t += 0.1f) {
        int sy = 0;
        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++][0];
            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++ = ' ';
            }
        }

        for (sy = 0; sy < 25; sy++) {
            COORD coord = { 0, sy };
            SetConsoleCursorPosition(o, coord);
            WriteConsole(o, buffer[sy], 79, NULL, 0);
        }
        if (count <= 10) {
            printf("马祥涛,天天开心,永远爱我 ———.Mua~\n");//表白内容 
            printf("                                                          ");
            printf("                                                          ");
            printf("                                                  By 喵~");// 表白者的名字 
            count++;
        }
        else {
            printf("You Are My Best Lover.\n");
            printf("            LOVE~");
            count++;
            if (count >= 20) {
                count = 0;
            }
        }
        Sleep(33);
    }
}

爱心结果

在C语言中直接编写3D粒子爱心形状的完整源代码是比较复杂的,因为这通常涉及到图形渲染库如OpenGL或DirectX等。这里简单提供一个概念性的示例,你可以通过学习基本的3D图形编程和绘制几何体的知识来实现: ```c #include <GL/glut.h> // 粒子结构体 typedef struct { float x, y, z; // 粒子位置 float size, life; // 粒子大小和生命周期 glColor4f color; // 颜色 } Particle; void draw_heart(Particle* particles, int count) { glBegin(GL_QUADS); // 开始四边形顶点 for (int i = 0; i < count; ++i) { glVertex3f(particles[i].x, particles[i].y, particles[i].z); // 画出爱心的四个部分,这里的坐标和颜色需要调整以形成心形 glVertex3f(particles[i + 1].x, particles[i].y, particles[i].z); glVertex3f(particles[i + 1].x, particles[i + 1].y, particles[i].z); glVertex3f(particles[i].x, particles[i + 1].y, particles[i].z); } glEnd(); } void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // 设置背景颜色 glClearColor(0.5f, 0.8f, 1.0f, 1.0f); glLoadIdentity(); // 绘制每颗粒子 for (int i = 0; i < NUM_PARTICLES; ++i) { Particle p; // 更新粒子位置、大小等属性并设置颜色 // ... draw_heart(&p, 1); // 因为爱心由单个四边形构成,所以传入1个粒子即可 } glutSwapBuffers(); // 刷新到屏幕 } int main(int argc, char** argv) { glutInit(&argc, argv); glutCreateWindow("3D Heart Particle System"); glEnable(GL_DEPTH_TEST); // 深度测试,让粒子有立体感 // 初始化其他设置... glutDisplayFunc(display); glutIdleFunc(display); // 持续更新直到窗口关闭 glutMainLoop(); return 0; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值