帮我写一个c++玫瑰代码
时间: 2024-06-13 21:05:21 浏览: 160
以下是一个简单的C++玫瑰代码,它可以在控制台中打印出一个玫瑰的形状:
```c++
#include <iostream>
#include <cmath>
using namespace std;
int main() {
const double PI = 3.14159265358979323846;
const int WIDTH = 80;
const int HEIGHT = 40;
const double SCALE = 0.05;
const double MIN_X = -2.5;
const double MAX_X = 2.5;
const double MIN_Y = -2.5;
const double MAX_Y = 2.5;
for (int y = HEIGHT; y >= 0; y--) {
for (int x = 0; x < WIDTH; x++) {
double real_x = x * (MAX_X - MIN_X) / WIDTH + MIN_X;
double real_y = y * (MAX_Y - MIN_Y) / HEIGHT + MIN_Y;
double z = exp(-real_x * real_x - real_y * real_y) * sin(10 * sqrt(real_x * real_x + real_y * real_y) + 4 * atan2(real_y, real_x));
int intensity = (int)((z + 1) / 2 * 10);
cout << " .:-=+*#%@"[intensity]; }
cout << endl;
}
return 0;
}
```
阅读全文