/**************************************************
* Function:玫瑰花
* Compiler:vs2010
* Developer:Zong Zhaopeng
* Date: 5 26 2017
* Version: 1.0
* References:internet
**************************************************/
#include <graphics.h>
#include <conio.h>
#include <math.h>
// 定义全局变量
int rosesize = 500;
int h = -250;
// 定义点结构体
struct DOT
{
// (x,y,z) 坐标
double x;
double y;
double z;
double red; // 红色
double green; // 绿色
// blue(蓝色)通过red计算
};
/**************************************************
* Function:计算点
* Description:绘制玫瑰花:花柄、叶、花萼、花
* Call:
* Call By:
* Database:
* param:a b c d
* Return:bool
**************************************************/
bool calc(double a,double b,double c,DOT &d)
{
double j, n, o, w, z;
// 花柄
if(c > 60)
{
// 玫瑰花曲线
d.x = sin(a * 7) * (13 + 5 / (0.2 + pow(b * 4, 4))) - sin(b) * 50;
d.y = b * rosesize + 50;
d.z = 625 + cos(a * 7) * (13 + 5 / (0.2 + pow(b * 4, 4))) + b * 400;
d.red = a * 1 - b / 2;
d.green = a;
return true;
}
double A = a * 2 - 1;
double B = b * 2 - 1;
if(A * A + B * B < 1)
{
// 叶
if(c > 37)
{
j = (int(c) & 1);
n = j ? 6 : 4;
o = 0.5 / (a + 0.01) + cos(b * 125) * 3 - a * 300;
w = b * h;
d.x = o * cos(n) + w * sin(n) + j * 610 - 390;
d.y = o * sin(n) - w * cos(n) + 550 - j * 350;
d.z = 1180 + cos(B + A) * 99 - j * 300;
d.red = 0.4 - a * 0.1 + pow(1 - B * B, -h * 6) * 0.15 -
a * b * 0.4 + cos(a + b) / 5 + pow(cos((o * (a + 1) +
(B > 0 ? w : -w)) / 25), 30) * 0.1 * (1 - B * B);
d.green = o / 1000 + 0.7 - o * w * 0.000003;
return true;
}
// 花萼 4片
if(c > 32)
{
c = c * 1.16 - 0.15;
o = a * 45 - 20;
w = b * b * h;
z = o * sin(c) + w * cos(c) + 620;
d.x = o * cos(c) - w * sin(c);
d.y = 28 + cos(B * 0.5) * 99 - b * b * b * 60 - z / 2 - h;
d.z = z;
d.red = (b * b * 0.3 + pow((1 - (A * A)), 7) * 0.15 + 0.3) * b;
d.green = b * 0.7;
return true;
}
// 花
o = A * (2 - b) * (80 - c * 2);
w = 99 - cos(A) * 120 - cos(b) * (-h - c * 4.9) + cos(pow(1 - b, 7)) * 50 + c * 2;
z = o * sin(c) + w * cos(c) + 700;
d.x = o * cos(c) - w * sin(c);
d.y = B * 99 - cos(pow(b, 7)) * 50 - c / 3 - z / 1.35 + 450;
d.z = z;
d.red = (1 - b / 1.2) * 0.9 + a * 0.1;
d.green = pow((1 - b), 20) / 4 + 0.05;
return true;
}
return false;
}
// 主函数
int main()
{
// 定义变量
short *zBuffer;
int x, y, z, zBufferIndex;
// 结构变量
DOT dot;
// 初始化
// 创建绘图窗口
initgraph(640, 480);
// 设置背景色为白色
setbkcolor(WHITE);
// 清屏
cleardevice();
// 初始化 z-buffer
zBuffer = new short[rosesize * rosesize];
// 内存清零
memset(zBuffer, 0, sizeof(short) * rosesize * rosesize);
// 按任意键退出
for(int j = 0; j < 2000 && !_kbhit(); j++)
{
for(int i = 0; i < 10000; i++) // 减少是否有按键的判断
{
if(calc(double(rand()) / RAND_MAX, double(rand()) / RAND_MAX, rand() % 46 / 0.74, dot))
{
z = int(dot.z + 0.5);
x = int(dot.x * rosesize / z - h + 0.5);
y = int(dot.y * rosesize / z - h + 0.5);
if (y >= rosesize)
{
continue;
}
zBufferIndex = y * rosesize + x;
if(!zBuffer[zBufferIndex] || zBuffer[zBufferIndex] > z)
{
zBuffer[zBufferIndex] = z;
// 画点
// 取反
int red = ~int((dot.red * h));
if (red < 0)
{
red = 0;
}
if (red > 255)
{
red = 255;
}
int green = ~int((dot.green * h));
if (green < 0)
{
green = 0;
}
if (green > 255)
{
green = 255;
}
int blue = ~int((dot.red * dot.red * -80));
if (blue < 0)
{
blue = 0;
}
if (blue > 255)
{
blue = 255;
}
putpixel(x + 50, y - 20, RGB(red, green, blue));
}
}
}
Sleep(1);
}
// 退出
delete []zBuffer;
getch();
closegraph();
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
C++ win32 绘制玫瑰花
共68个文件
tlog:34个
pdb:4个
manifest:3个
4星 · 超过85%的资源 需积分: 50 74 下载量 187 浏览量
2017-05-31
20:11:54
上传
评论 1
收藏 16.43MB RAR 举报
温馨提示
C++ win32 通过像素点绘制玫瑰花
资源推荐
资源详情
资源评论
收起资源包目录
C++ win32 绘制玫瑰花.rar (68个子文件)
Rose
Rose
main.cpp 4KB
resource.h 986B
Rose.vcxproj 4KB
Rose.vcxproj.filters 1KB
Debug
link.9660-cvtres.write.1.tlog 2B
link.read.1.tlog 3KB
Rose.exe.embed.manifest.res 472B
vc100.pdb 108KB
link-cvtres.read.1.tlog 2B
link.command.1.tlog 2KB
rc.write.1.tlog 402B
Rose.write.1.tlog 0B
CL.write.1.tlog 510B
Rose.vcxprojResolveAssemblyReference.cache 713B
rc.command.1.tlog 614B
link.9660-cvtres.read.1.tlog 2B
cl.command.1.tlog 766B
Rose.log 3KB
link.9660.write.1.tlog 2B
link-cvtres.write.1.tlog 2B
mt.read.1.tlog 422B
main.obj 37KB
mt.write.1.tlog 422B
rc.read.1.tlog 394B
CL.read.1.tlog 14KB
Rose.exe.intermediate.manifest 381B
vc100.idb 363KB
Rose.lastbuildstate 98B
mt.command.1.tlog 424B
Rose_manifest.rc 198B
link.write.1.tlog 1KB
Rose.exe.embed.manifest 406B
link.9660.read.1.tlog 2B
rose.ico 9KB
Rose.vcxproj.user 143B
Release
link.read.1.tlog 3KB
vc100.pdb 100KB
link-cvtres.read.1.tlog 2B
link.command.1.tlog 3KB
rc.write.1.tlog 338B
Rose.res 10KB
Rose.write.1.tlog 0B
CL.write.1.tlog 518B
rc.command.1.tlog 592B
cl.command.1.tlog 786B
Rose.log 3KB
link-cvtres.write.1.tlog 2B
mt.read.1.tlog 642B
main.obj 82KB
mt.write.1.tlog 390B
rc.read.1.tlog 3KB
CL.read.1.tlog 14KB
Rose.exe.intermediate.manifest 381B
Rose.lastbuildstate 100B
mt.command.1.tlog 564B
link.write.1.tlog 906B
Rose.aps 43KB
Rose.rc 3KB
ipch
rose-f18dbd59
rose-bd81199f.ipch 29.38MB
rose-4c680b65.ipch 29.38MB
Rose.sdf 23.77MB
Rose.suo 11KB
Debug
Rose.ilk 782KB
Rose.exe 107KB
Rose.pdb 707KB
Rose.sln 879B
Release
Rose.exe 124KB
Rose.pdb 1.25MB
共 68 条
- 1
资源评论
- _大本营_2017-05-31挺有参考价值的
z2014z
- 粉丝: 17
- 资源: 21
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功