好玩的图形函数

#include<windows.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>


#define WIN_WIDTH 800
#define WIN_HIGH 600




void CALLBACK timerproc(HWND, UINT, UINT, DWORD){
	setlinecolor(RGB(rand() % 256, rand() % 256, rand() % 256));
}



void main(){
	HWND hwnd;


	
	int x1, y1, x2, y2;
	int mx1, mx2, my1, my2;
	srand((int)time(0));
	x1 = rand() % WIN_WIDTH;
	y1 = rand() % WIN_HIGH;
	x2 = rand() % WIN_WIDTH;
	y2 = rand() % WIN_HIGH;


	mx1 = rand() % 8 - 4;
	my1 = rand() % 8 - 4;
	mx2 = rand() % 8 - 4;
	my2 = rand() % 8 - 4;
    a.top = -1;
	initgraph(WIN_WIDTH, WIN_HIGH);
	setlinecolor(RED);
	hwnd = GetHWnd();
	SetTimer(hwnd, 1, 5000, timerproc);
	MoveWindow(hwnd, 300, 20, WIN_WIDTH, WIN_HIGH, true);
	while (1){
		x1 += mx1;
		x2 += mx2;
		y1 += my1;
		y2 += my2;


		if (x1<0 || x1>WIN_WIDTH) {  mx1 = -mx1; x1 += mx1; }
		if (x2<0 || x2>WIN_WIDTH) {  mx2 = -mx2; x2 += mx2; }
		if (y1<0 || y1>WIN_HIGH) {  my1 = -my1; y1 += my1; }
		if (y2<0 || y2>WIN_HIGH) {  my2 = -my2; y2 += mx2; }
		line(x1,y1,x2,y2);
		Sleep(10);
	}
	_getch();
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值