Mouse Program,Error

The output is disjoint...i dunno why? plz comment

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream.h>
#include <graphics.h>
#include <dos.h>

union REGS in,out;

void showMouse(){
	in.x.ax=1;
	int86(0x33,&in,&out);
}

void getMousePos(int &x,int &y){
	in.x.ax=3;
	int86(0x33,&in,&out);
	if(out.x.bx==1){
		x=out.x.cx;
		y=out.x.dx;
		delay(1);
	}
}

int menu(){
	int color;
	cout<<"\nSelect color of brush:"<<endl;
	cout<<"1.Dark Blue\n2.Green\n3.Light Blue\n4.Red\n5.Pink\n6.Orange\n7.White\n8.Grey\n9.Purple\n10.Lime Green"<<endl;
	cout<<"Your Choice:";
	cin>>color;
	return color;
}

void main(){
	int gd=DETECT,gm,x,y,color;
	initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
	color=menu();
	showMouse();
	cleardevice();
	while(!kbhit()){
		getMousePos(x,y);
		putpixel(x,y,color);
	}
	closegraph();
}


Compiled in Turbo C++ (ikr its ancient)
Last edited on
My comment is that you haven't explained what it does that you don't like.
Moschops the output is not a continous line as i thought it would be and i dunno why it is...hope thats clear
The mouse moves constantly. Your code looks at the mouse position, and then spends some time colouring in a pixel. When your code looks at the mouse again, it has moved. A long way. All the pixels the mouse moved over while your code wasn't looking might as well have never happened.
Rather than drawing a pixel, you could try drawing short line segments.
I'm not sure what functions are available in your <graphics.h>.

Maybe you have:
moveto(x,y) set current pen position
lineto(x,y) draw line to x,y or something like that.
moschops and chervil ty
Topic archived. No new replies allowed.