{"id":44,"date":"2009-05-27T00:16:45","date_gmt":"2009-05-26T18:46:45","guid":{"rendered":"http:\/\/vikku.info\/codesnippets\/?p=44"},"modified":"2009-05-27T22:47:35","modified_gmt":"2009-05-27T17:17:35","slug":"free-hand-drawnig-in-c-graphics","status":"publish","type":"post","link":"http:\/\/vikku.info\/codesnippets\/c-graphics\/free-hand-drawnig-in-c-graphics\/","title":{"rendered":"free hand drawing in c graphics"},"content":{"rendered":"<p>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&#8230; 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&#8230;<\/p>\n<p>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&#8230;<\/p>\n<pre lang=\"C\">\r\n\r\n#include<graphics.h>\r\n#include<bios.h>\r\n#include<dos.h>\r\n\r\nvoid getxy();\r\n\r\nint prevx,prevy,mousex,mousey,butt=1;\r\n\r\nvoid main()\r\n{\r\n\tint x=DETECT,y;\r\n\r\n\tinitgraph(&x,&y,\"\"); \r\n       \/\/ path to EGAVGA.BGI if this is not in your current directory\r\n\r\n\t_AX=0;\r\n\tasm int 33h\r\n\r\n\tsetcolor(15);\r\n\r\n\twhile(inportb(0x60)!=1)\r\n\t{\r\n\t\tgetxy();\r\n\r\n\t\tif(butt==1)\r\n\t\t{\r\n\t\t\t_AX=2;\r\n\t\t\tasm int 33h\r\n\r\n\t\t\tline(mousex-1,mousey-1,prevx-1,prevy-1);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\t_AX=1;\r\n\t\t\tasm int 33h\r\n\t\t}\r\n\t}\r\n\r\n\tclosegraph();\r\n}\r\n\r\nvoid getxy()\r\n{\r\n\t_AX=3;\r\n\tasm int 33h;\r\n\r\n\tprevx=mousex;\r\n\tprevy=mousey;\r\n\r\n\tmousex=_CX;\r\n\tmousey=_DX;\r\n\tbutt=_BX;\r\n\r\n\tgotoxy(2,2);\r\n\tprintf(\"%3d   %3d   %2d\",mousex,mousey,butt);\r\n}\r\n\r\n<\/pre>\n<p>_AX=0 &#8211; Initialize mouse<br \/>\n_AX=1 &#8211; show mouse pointer<br \/>\n_AX=2 &#8211; hide mouse pointer<br \/>\n_AX=3 &#8211; get coordinates and the return values will be in cs and dx.<\/p>\n<p>The while loop executes till the esc key is pressed<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230; so my idea is to draw but this approach was not much effective because if you move the mouse fast you will not get [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11],"tags":[],"_links":{"self":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/44"}],"collection":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/comments?post=44"}],"version-history":[{"count":8,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/44\/revisions"}],"predecessor-version":[{"id":65,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/44\/revisions\/65"}],"wp:attachment":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/media?parent=44"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/categories?post=44"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/tags?post=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}