【VC++开源代码栏目提醒】:网学会员VC++开源代码为您提供情人节的红玫瑰c语言代码 - 编程语言参考,解决您在情人节的红玫瑰c语言代码 - 编程语言学习中工作中的难题,参考学习。
情人节的红玫瑰 作者krissi 2012年2月14日情人节就要来临了西班牙程序员 Roman Cortes 用纯 javascript 脚本编写了红色玫瑰花。
现在这个精彩的程序经 krissi 移植到了
vc 上。
以下是执行效果 完整的
vc 源
代码如下 //////////////////////////////////////////////////////////////////// // 程序名称情人节的玫瑰 // 编译环境
VC6.0 /
VC2010EasyX 2011惊蛰版 // 原 作 者西班牙程序员 Roman Cortes // 原 程 序http://js1k.com/2012-love/demo/1022 javascript 版本 // 移植作者krissi // 最后修改2012-2-13 // 注程序中的很多精简变量名都沿用原 javascript 中的变量名。
// include include include // 定义全局变量 int rosesize 500 int h -250 // 定义结构体 struct DOT double x double y double z double r // 红色 double g // 绿色 // b蓝色 通过 r 计算 // 计算点 bool calcdouble a double b double c DOT d double j n o w z ifc 60 // 花柄 d.x sina 7 13 5 / 0.2 powb 4 4 - sinb 50 d.y b rosesize 50 d.z 625 cosa 7 13 5 / 0.2 powb 4 4 b 400 d.r a 1 - b / 2 d.g a return true double A a 2 - 1 double B b 2 - 1 ifA A B B 1 ifc 37 // 叶 j intc 1 n j 6 : 4 o 0.5 / a 0.01 cosb 125 3 - a 300 w b h d.x o cosn w sinn j 610 - 390 d.y o sinn - w cosn 550 - j 350 d.z 1180 cosB A 99 - j 300 d.r 0.4 - a 0.1 pow1 - B B -h 6 0.15 - a b 0.4 cosa b / 5 powcoso a 1 B 0 w : -w / 25 30 0.1 1 - B B d.g o / 1000 0.7 - o w 0.000003 return true ifc 32 // 花萼 c c 1.16 - 0.15 o a 45 - 20 w b b h z o sinc w cosc 620 d.x o cosc - w sinc d.y 28 cosB 0.5 99 - b b b 60 - z / 2 - h d.z z d.r b b 0.3 pow1 - A A 7 0.15 0.3 b d.g b 0.7 return true // 花 o A 2 - b 80 - c 2 w 99 - cosA 120 - cosb -h - c 4.9 cospow1 - b 7 50 c 2 z o sinc w cosc 700 d.x o cosc - w sinc d.y B 99 - cospowb 7 50 - c / 3 - z / 1.35 450 d.z z d.r 1 - b / 1.2 0.9 a 0.1 d.g pow1 - b 20 / 4 0.05 return true return false // 主函数 void main // 定义变量 short zBuffer int x y z zBufferIndex DOT dot // 初始化 initgraph640 480 // 创建绘图窗口 setbkcolorWHITE // 设置背景色为白色 cleardevice // 清屏 // 初始化 z-buffer zBuffer new shortrosesize rosesize memsetzBuffer 0 sizeofshort rosesize rosesize forint j 0 j 2000 _kbhit j // 按任意键退出 forint i 0 i 10000 i // 减少是否有按键的判断 ifcalcdoublerand / RAND_MAX doublerand / RAND_MAX rand 46 / 0.74 dot z intdot.z 0.5 x intdot.x rosesize / z - h 0.5 y intdot.y rosesize / z - h 0.5 if y rosesize continue zBufferIndex y rosesize x ifzBufferzBufferIndex zBufferzBufferIndex z zBufferzBufferIndex z // 画点 int r intdot.r h if r 0 r 0 if r 255 r 255 int g intdot.g h if g 0 g 0 if g 255 g 255 int b intdot.r dot.r -80 if b 0 b 0 if b 255 b 255 putpixelx 50 y - 20 RGBr g b Sleep1 // 退出 delete zBuffer _getch closegraph 原作者 Roman Cortes 对这段程序的讲解贴在了自己的博客http://www.romancortes.com/blog/1k-rose/ 想要学习的同学可以点过去看看。
http://www.easyx.cn/