free hand drawing in c graphics

C Graphics Add comments

I wrote a program to draw on the screen using putpixel which will plot a pixel at x,y,colorvalue where x,y is the location which you can get from the mouse interrupts… so my idea is to draw but this approach was not much effective because if you move the mouse fast you will not get the desired shape…

so i read a technique which is actually the original way of drawing using the mouse using the lineto function which will not break the path where as using putpixel will break…

 
#include<graphics.h>
#include<bios.h>
#include<dos.h>
 
void getxy();
 
int prevx,prevy,mousex,mousey,butt=1;
 
void main()
{
	int x=DETECT,y;
 
	initgraph(&x,&y,""); 
       // path to EGAVGA.BGI if this is not in your current directory
 
	_AX=0;
	asm int 33h
 
	setcolor(15);
 
	while(inportb(0x60)!=1)
	{
		getxy();
 
		if(butt==1)
		{
			_AX=2;
			asm int 33h
 
			line(mousex-1,mousey-1,prevx-1,prevy-1);
		}
		else
		{
			_AX=1;
			asm int 33h
		}
	}
 
	closegraph();
}
 
void getxy()
{
	_AX=3;
	asm int 33h;
 
	prevx=mousex;
	prevy=mousey;
 
	mousex=_CX;
	mousey=_DX;
	butt=_BX;
 
	gotoxy(2,2);
	printf("%3d   %3d   %2d",mousex,mousey,butt);
}

_AX=0 - Initialize mouse
_AX=1 - show mouse pointer
_AX=2 - hide mouse pointer
_AX=3 - get coordinates and the return values will be in cs and dx.

The while loop executes till the esc key is pressed

Leave a Reply

Entries RSS