注册 登录
编程论坛 C图形专区

[原创]美丽蝴蝶

cdmalcl 发布于 2007-04-26 00:33, 2950 次点击

#include<stdio.h>
#include<math.h>
#include<graphics.h>
#define PI 3.14
int main()
{
float i ,j ,x ,y;
int MAXX2 ,MAXY2;
int gd = DETECT,gm = 0;

initgraph(&gd,&gm,"");

MAXX2 = getmaxx()/2;
MAXY2 = getmaxy()/2;

for(i = -5*PI;i < 5*PI;i +=0.01)
for(j = -5*PI;j < 5*PI;j += 0.01)
{
y = sin(i-j*2)*5+i*j;
x = cos(i*2+j)*y+3*y;
putpixel(x+MAXX2 ,y*j/2+MAXY2 ,((int)abs(i+j)*4)%15+1);
}

getch();
}

17 回复
#2
cdmalcl2007-04-26 01:06

#include<stdio.h>
#include<math.h>
#include<graphics.h>
#define PI 3.14
int main()
{
float i ,j ,x ,y;
int MAXX2 ,MAXY2;
int gd = DETECT,gm = 0;

initgraph(&gd,&gm,"");

MAXX2 = getmaxx()/2;
MAXY2 = getmaxy()/2;

for(i = -6*PI;i < 6*PI;i +=0.02)
for(j = -3*PI;j < 3*PI;j += 0.02)
{
y = sin(i-j*2)*i*3+j*5;
x = cos(i*2+y)*j+2*y;
putpixel(y*i/5+MAXX2 ,MAXY2*1.5-x*j/5 ,((int)abs(i+j)*4)%15+1);
if(kbhit())
exit(0);
}

getch();
}

#3
cdmalcl2007-04-26 01:08
以下是引用cdmalcl在2007-4-26 1:06:53的发言:

#include<stdio.h>
#include<math.h>
#include<graphics.h>
#define PI 3.14
int main()
{
float i ,j ,x ,y;
int MAXX2 ,MAXY2;
int gd = DETECT,gm = 0;

initgraph(&gd,&gm,"");

MAXX2 = getmaxx()/2;
MAXY2 = getmaxy()/2;

for(i = -6*PI;i < 6*PI;i +=0.02)
for(j = -3*PI;j < 3*PI;j += 0.02)
{
y = sin(i-j*2)*i*3+j*5;
x = cos(i*2+y)*j+2*y;
putpixel(y*i/5+MAXX2 ,MAXY2*1.5-x*j/5 ,((int)abs(i+j)*4)%15+1);
if(kbhit())
exit(0);
}

getch();
}

((int)abs(i+j)*4)%3+3



或者

x = cos(2+i*y)*j+2*y;

[此贴子已经被作者于2007-4-26 1:09:34编辑过]

#4
卧龙孔明2007-05-06 20:40
第二个效果不错
#5
蔡蔡2007-05-08 12:46
厉害!厉害!高手,不知我什么时候才能和你们一样`~~~~~
#6
wswwang2007-05-16 22:56
niu
#7
fangfangff2007-06-09 22:38

不错,顶一个!!!!!!!!

#8
killer_l2007-06-10 10:49
TC2.0里无法运行啊

提示BGI Error:Graphics not initialized(use 'intigraph')
#9
a4294993812007-06-16 18:45
我的编译成功后黑了一下就退出来了, 不知道怎么??
可能我的系统原因吧?
我的2003企业版的, 不知道是不是这个原因, 而且在这个系统上无法玩魔兽, ???+
#10
dexingtuohai2007-07-10 17:32

太牛拉,代码那少也写出这么厉害的图

#11
一笔苍穹2007-07-10 17:43
WIN 2003对虚拟DOS的支持不够好。要跑DOS程序还得改一些地方,这个页面里有,你看看行不(里面介绍的是WIN 2000《我在Windows 2000下运行用NEO编译的DOS程序,但发现无法运行里面的实例,为什么?》):
http://www.ds0101.com/neosdk/docs/end/faq.htm
#12
cdmalcl2007-07-10 23:56

董哥 帮我写个WINDOWS下的动画程序呗!
我写这个不是即时的那种!

[CODE]#include <windows.h>
#include <math.h>
#define PI 3.14
int cxClient, cyClient ;
float i, j, x, y ;
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("SineWave") ;
MSG msg ;
WNDCLASS wndclass;
HWND hwnd ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc= WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground= (HBRUSH) GetStockObject (LTGRAY_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox ( NULL, TEXT ("Program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow ( szAppName, TEXT ("美丽蝴蝶"),
WS_OVERLAPPEDWINDOW,
10, 10,
800, 600,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect;
HBRUSH hBrush ;
HBITMAP bit;
HINSTANCE hinst ;

switch (message)
{
case WM_CREATE:
return 0 ;
case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
InvalidateRect (hwnd, NULL, FALSE) ;
return 0;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
for(i = -6*PI;i < 6*PI;i +=0.02)
for(j = -3*PI;j < 3*PI;j += 0.02)
{
y = sin(i-j*2)*i*3+j*5 ;
x = cos(i*2+y)*j+2*y ;
SetPixel(hdc
, y*i/5+cxClient/2
, (cyClient/2)*1.5-x*j/5
, RGB(abs(i*j)%255,abs(2*j*j)%255,abs(i*j*5+i*30)%255)) ;
}
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}[/CODE]

#13
一笔苍穹2007-07-12 16:48
Timer方面的API不难,稍微查点资料就可以完成。
我现在在公司赶工~~~命苦哇
#14
cdmalcl2007-07-12 19:25

我就是用TIMER事件
但是没弄出来

#15
cdmalcl2007-07-12 19:38
关键是重画问题
我不知道用什么好办法记录已经画的图形
#16
if_exist2009-09-30 19:14
点少的话用数组,这个点这么多……
话说真的很漂亮!顶一下
#17
na_14212010-06-05 22:39
五体投地
#18
chfplang2010-06-21 21:23
我滴神啊!
1