C语言代码输入练习

贡献者:user0113 类别:英文 时间:2019-07-27 10:12:01 收藏数:68 评分:-0.5
返回上页 举报此文章
请选择举报理由:




收藏到我的文章 改错字
// src: codebus, yangw
// build: vc6, easyx 2011
//
#include <graphics.h>
#include <conio.h>
#define ITERATIONS 1000
#define MAXCOLOR 64
struct COMPLEX
{double re;
double im;
};
COMPLEX operator * (COMPLEX a, COMPLEX b)
{COMPLEX c;
c.re = a.re * b.re - a.im * b.im;
c.im = a.im * b.re + a.re * b.im;
return c;
}COMPLEX operator + (COMPLEX a, COMPLEX b)
{COMPLEX c;
c.re = a.re + b.re;
c.im = a.im + b.im;
return c;
}int Color[MAXCOLOR];
void InitColor()
{int h1 = 240, h2 = 30;
for(int i=0; i<MAXCOLOR/2; i++)
{Color[i] = HSLtoRGB((float)h1, 1.0f, i * 2.0f / MAXCOLOR);
Color[MAXCOLOR-1-i] = HSLtoRGB((float)h2, 1.0f, i * 2.0f / MAXCOLOR);
}}void Draw(double fromx, double fromy, double tox, double toy)
{COMPLEX z, c;
int x, y, k;
for(x = 0; x < 640; x++)
{c.re = fromx + (tox - fromx) * (x / 640.0);
for(y = 0; y < 480; y++)
{c.im = fromy + (toy - fromy) * (y / 480.0);
z.re = z.im = 0;
for(k = 0; k < ITERATIONS; k++)
{if ( z.re * z.re + z.im * z.im > 4.0 ) break;
z = z * z + c;
}putpixel(x, y, (k >= ITERATIONS) ? 0 : Color[k % MAXCOLOR]);
}}}int main()
{initgraph(640, 480);
InitColor();
double fromx, fromy, tox, toy;
fromx = -2.1; tox = 1.1;
fromy = -1.2; toy = 1.2;
Draw(fromx, fromy, tox, toy);
MOUSEMSG m;
bool isLDown = false;
int selfx, selfy, seltx, selty;
while(!kbhit())
{m = GetMouseMsg();
switch(m.uMsg)
{case WM_MBUTTONUP:
fromx = -2.1; tox = 1.1;
fromy = -1.2; toy = 1.2;
Draw(fromx, fromy, tox, toy);
break;
case WM_MOUSEMOVE:
if (isLDown)
{rectangle(selfx, selfy, seltx, selty);
seltx = m.x;
selty = m.y;
rectangle(selfx, selfy, seltx, selty);
}break;
case WM_LBUTTONDOWN:
setcolor(WHITE);
setwritemode(R2_XORPEN);
isLDown = true;
selfx = seltx = m.x;
selfy = selty = m.y;
rectangle(selfx, selfy, seltx, selty);
break;
case WM_LBUTTONUP:
rectangle(selfx, selfy, seltx, selty);
setwritemode(R2_COPYPEN);
isLDown = false;
seltx = m.x;
selty = m.y;
if (selfx == seltx || selfy == selty) break;
int tmp;
if (selfx > seltx) {tmp = selfx; selfx = seltx; seltx = tmp;}
if (selfy > selty) {tmp = selfy; selfy = selty; selty = tmp;}
if ( (seltx - selfx) * 0.75 < (selty - selfy) )
{selty += (3 - (selty - selfy) % 3);
selfx -= (selty - selfy) / 3 * 4 / 2 - (seltx - selfx) / 2;
seltx = selfx + (selty - selfy) / 3 * 4;
}else
{seltx += (4 - (seltx - selfx) % 4);
selfy -= (seltx - selfx) * 3 / 4 / 2 - (selty - selfy ) / 2;
selty = selfy + (seltx - selfx ) * 3 / 4;
}double f, t;
f = fromx + (tox - fromx) * selfx / 640;
t = fromx + (tox - fromx) * seltx / 640;
fromx = f;
tox = t;
f = fromy + (toy - fromy) * selfy / 480;
t = fromy + (toy - fromy) * selty / 480;
fromy = f;
toy = t;
Draw(fromx, fromy, tox, toy);
break;
}}getch();
closegraph();
}
声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。
文章热度:
文章难度:
文章质量:
说明:系统根据文章的热度、难度、质量自动认证,已认证的文章将参与打字排名!

本文打字排名TOP20

登录后可见

用户更多文章推荐