The legal tricks-Learn Your Self

Latest gadgets,softwares,hardware,reviews,programming and campuses, game cheats ext......

A Simple 2D-Drawing Program

Problem Statement : A Simple 2D-Drawing Program

Programming Language : C Graphics

Program Code :

#include
#include
#include
#define ESC 0x1b
void drcir(int,int,int);
void drarc(int,int,int);
void main()
{
int a,b,c,d,e,f,curcolor=3;
int gdriver = DETECT,gmode;
initgraph(&gdriver,&gmode,"c:\tc\bgi");
verybegin:
sound(333);
delay(100);
sound(222);
delay(100);
sound(250);
delay(100);
sound(33);
delay(100);
sound(111);
delay(100);
sound(222);
delay(100);
sound(333);
delay(100);
sound(3333);
delay(100);
nosound();
gotoxy(25,1);
printf("2d Drawing");
gotoxy(18,5);
printf("A Simple Program");
gotoxy(18,6);
printf("This is used for drawing circles,arcs,rectangle,");
gotoxy(18,7);
printf("lines and many more...");
printf("The Controls For The Two-Dimensional Drawing");
printf("N(Up Arrow) = North");
printf("S(Down Arrow) = South");
printf("E(Right Arrow) = East");
printf("W(Left Arrow) = West");
printf("F(Page Up) = North-East");
printf("X(Home) = North-West");
printf("D(Page Down) = South-East");
printf("Z(End) = South-West");
printf("J = Current Position");
printf("B = Help(This Screen)");
printf("R(Insert) = Reset");
printf("T = Color Change(0-9)");
printf("C = Circle");
printf("A = Arc");
printf("ESC = Quit");
getch();
begin:
curcolor=3;
a = getmaxx() / 2;
b = getmaxy() / 2;
cleardevice();
start:
putpixel(a,b,curcolor);
c=getch();
sound(100);
delay(20);
nosound();
if(c==ESC)
{
goto end;
}
switch(c)
{
case 'N':
case 'n':
case 'H':
case 'h':
c=a;
d=b-1;
a=c;
b=d;
goto start;
case 'S':
case 's':
case 'P':
case 'p':
c=a;
d=b+1;
a=c;
b=d;
goto start;
case 'E':
case 'e':
case 'M':
case 'm':
c=a+1;
d=b;
a=c;
b=d;
goto start;
case 'W':
case 'w':
case 'K':
case 'k':
c=a-1;
d=b;
a=c;
b=d;
goto start;
case 'D':
case 'd':
case 'Q':
case 'q':
c=a+1;
d=b+1;
a=c;
b=d;
goto start;
case 'X':
case 'x':
case 'G':
case 'g':
c=a-1;
d=b-1;
a=c;
b=d;
goto start;
case 'Z':
case 'z':
case 'O':
case 'o':
c=a-1;
d=b+1;
a=c;
b=d;
goto start;
case 'F':
case 'f':
case 'I':
case 'i':
c=a+1;
d=b-1;
a=c;
b=d;
goto start;
case 'R':
case 'r':
goto begin;
case 'J':
case 'j':
f=curcolor+1;
putpixel(a,b,f);
gotoxy(1,2);
printf("X=%d,Y=%d",a,b);
sound(100);
getch();
gotoxy(1,2);
printf(" ");
nosound();
goto start;
case 'C':
case 'c':
drcir(a,b,curcolor);
goto start;
case 'A':
case 'a':
drarc(a,b,curcolor);
goto start;
case 'T':
case 't':
gotoxy(1,2);
printf("Enter color code:");
e=getche();
curcolor=e;
setcolor(curcolor);
gotoxy(1,2);
printf(" ");
goto start;
case 'B':
case 'b':
cleardevice();
goto verybegin;
default:
goto start;
}
end:
cleardevice();
closegraph();
}
void drcir(int x,int y,int ccolor)
{
int r;
gotoxy(1,2);
printf("Enter Radius of Circle:");
scanf("%d",&r);
gotoxy(1,2);
printf(" ");
setcolor(ccolor);
circle(x,y,r);
}
void drarc(int x,int y,int ccolor)
{
int r,sa,ea;
gotoxy(1,2);
printf("Enter Radius:");
scanf("%d",&r);
gotoxy(1,2);
printf(" ");
gotoxy(1,2);
printf("Enter Starting Angle:");
scanf("%d",&sa);
gotoxy(1,2);
printf(" ");
gotoxy(1,2);
printf("Enter Ending Angle:");
scanf("%d",&ea);
gotoxy(1,2);
printf(" ");
setcolor(ccolor);
arc(x,y,sa,ea,r);
}

3D graphics in C

Problem Statement : 3D graphics in C

Programming Language : C Graphics

Program Code :

3D graphics in C

#include
#include
#include
void mainscreenin17408(int sx,int sy,int ex,int ey);
void mainscreenin27408(int sx,int sy,int ex,int ey);
void dia7408();
void main()
{
int gd=DETECT,gm;
int sx,sy,ex,ey;
initgraph(&gd,&gm,"e:\tc\bgi");
sx=15;
sy=10;
ex=630;
ey=470;
mainscreenin17408(sx,sy,ex,ey);
mainscreenin27408(sx,sy,ex,ey);
dia7408();

getch();
}


void mainscreenin17408(int sx,int sy,int ex,int ey)
{
setfillstyle(1,7);
bar(sx,sy,ex,ey);
setfillstyle(1,7);
setcolor(15);
line(sx,sy,sx,ey);
line(sx,sy,ex,sy);
line(sx,sy,sx,ey);
line(sx,sy,ex,sy);
setcolor(0);
line(ex,sy,ex,ey);
line(ex,sy,ex,ey);
line(sx,ey,ex,ey);
line(sx,ey,ex,ey);


settextstyle(0,0,0);
setfillstyle(1,1);
bar(sx+2,sy+2,ex-2,sy+20);
setcolor(13);
settextstyle(8,0,1);
outtextxy(sx+190,sy-5,"IC 7408-AND GATE");
//for x
setfillstyle(1,7);
bar(ex-15,sy+4,ex-4,sy+15);
setcolor(15);
line(ex-15,sy+4,ex-4,sy+4);
line(ex-15,sy+4,ex-15,sy+15);
setcolor(0);
line(ex-15,sy+15,ex-4,sy+15);
line(ex-4,sy+4,ex-4,sy+15);
setcolor(1);
settextstyle(0,0,1);
outtextxy(ex-13,sy+5,"x");
setfillstyle(1,7);
}

void mainscreenin27408(int sx,int sy,int ex,int ey)
{
sx=sx+15;
sy=sy+24;
ex=ex-17;
ey=ey-9;
setcolor(0);

line(sx,sy,sx,ey);
line(sx,sy,ex,sy);
line(sx,sy,sx,ey);
line(sx,sy,ex,sy);
setcolor(15);
line(ex,sy,ex,ey);
line(ex,sy,ex,ey);
line(sx,ey,ex,ey);
line(sx,ey,ex,ey);


}

void dia7408()
{
int x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6,x7,y7,i;
setcolor(0);
rectangle(61,83,410,259);//body
setfillstyle(1,9);
floodfill(107,137,0);
arc(62,166,270,90,16);
setfillstyle(1,6);
floodfill(68,165,0);
//for drawing leads
x1=62;
y1=67;
x2=84;
y2=83;
x3=73;
y3=73;
for(i=0;i<8;i++)//for upper part
{
rectangle(x1,y1,x2,y2);
x1+=46;
x2+=46;
setfillstyle(1,14);
floodfill(x3,y3,0);
x3+=46;
}
x1=62;
y1=259;
x2=84;
y2=275;
x3=72;
y3=267;
for(i=0;i<8;i++)//for lower part
{
rectangle(x1,y1,x2,y2);
x1+=46;
x2+=46;
setfillstyle(1,14);
floodfill(x3,y3,0);
x3+=46;
}
//end of ic's pin
//start of ic internal configuration

outtextxy(70,264,"1");
outtextxy(65,289,"A1");
outtextxy(116,264,"2");
outtextxy(112,289,"B1");
outtextxy(163,264,"3");
outtextxy(161,289,"Y1");
outtextxy(207,264,"4");
outtextxy(205,289,"A2");
outtextxy(253,264,"5");
outtextxy(250,289,"B2");
outtextxy(299,264,"6");
outtextxy(297,289,"Y2");
outtextxy(343,264,"7");
outtextxy(340,289,"GND");
outtextxy(390,264,"8");
outtextxy(387,289,"Y");
outtextxy(65,74,"16");
outtextxy(62,55,"Vcc");
outtextxy(111,74,"15");
outtextxy(112,54,"A4");
outtextxy(158,74,"14");
outtextxy(159,54,"B4");
outtextxy(204,74,"13");
outtextxy(205,54,"Y4");
outtextxy(250,74,"12");
outtextxy(248,54,"A3");
outtextxy(295,74,"11");
outtextxy(297,54,"B3");
outtextxy(340,74,"10");
outtextxy(337,54,"Y3");
outtextxy(394,74,"9");
outtextxy(387,54,"bv");
settextstyle(1,0,4);
setlinestyle(0,0,3);
setcolor(15);
line(440,60,599,60);
line(440,60,440,220);
setcolor(0);
line(440,220,599,220);
line(599,220,599,60);
setlinestyle(1,0,1);
setfillstyle(1,0);
setcolor(0);
bar(447,63,592,90);
settextstyle(1,0,1);
setcolor(14);
outtextxy(460,68,"RESULTS");

setcolor(2);

for(y1=102,i=0;i<4;i++)
{
circle(462,y1,10);
setfillstyle(1,4);
floodfill(462,y1,2);
y1+=30;
}

setlinestyle(0,0,1);

setcolor(15);
line(120,400,190,400);
line(120,400,120,450);
setcolor(0);
line(120,450,190,450);
line(190,450,190,400);
setcolor(0);
outtextxy(130,410,"Index");
setcolor(15);
line(250,400,320,400);
line(250,400,250,450);
setcolor(0);
line(250,450,320,450);
line(320,450,320,400);
outtextxy(260,410,"Exit");
settextstyle(1,0,3);
setcolor(RED);
outtextxy(150,320,"PIN DIAGRAM");
setlinestyle(0,0,3);
line(150,350,297,350);

setlinestyle(0,0,3);
setcolor(15);
line(420,270,600,270);
line(420,270,420,440);
setcolor(0);
line(420,440,600,440);
line(600,440,600,270);

bar(422,272,596,310);
setcolor(14);
outtextxy(425,280,"Truth Table");
setcolor(MAGENTA);
setlinestyle(0,0,1);
line(430,320,590,320);
line(430,320,430,430);
line(430,430,590,430);
line(590,430,590,320);
line(530,320,530,430);
setcolor(BROWN);
settextstyle(0,0,1);
outtextxy(460,330,"INPUTS");
outtextxy(540,330,"OUTPUT");
setcolor(MAGENTA);
line(430,345,590,345);//for line after input and output
line(480,345,480,430);//line for middle
setcolor(12);
outtextxy(450,355,"L");
outtextxy(500,355,"L");
outtextxy(560,355,"L");
outtextxy(450,375,"L");
outtextxy(500,375,"H");
outtextxy(560,375,"L");
outtextxy(450,395,"H");
outtextxy(500,395,"L");
outtextxy(560,395,"L");
outtextxy(450,415,"H");
outtextxy(500,415,"H");
outtextxy(560,415,"H");
setcolor(MAGENTA);
line(430,370,590,370);
line(430,390,590,390);
line(430,410,590,410);
line(430,430,590,430);

}

3D diagram of an IC

Problem Statement : 3D diagram of an IC

Programming Language : C Graphics

Program Code :



#include
#include
#include
void liner(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4,int x5,int y5,int i);
void shadow(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4,int x5,int y5,int x6,int y6,int x7,int y7);
void rightlead( int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4,int x5,int y5,int x6,int y6,int x7,int y7,int x8,int y8,int x9,int y9,int x10,int y10,int x11, int y11);
void leftlead();
void identifier();
void bibin();

void main()
{
int gd=DETECT, gm,i=3;
initgraph(&gd,&gm,"c:\tc\bgi");
setbkcolor(6);
cleardevice();
setcolor(i);
line(263,192,108,151);
line(108,151,345,40);
line(263,192,507,68);
line(507,68,345,40);
setfillstyle(1,9);

floodfill(347,49,i);//for upper part
setcolor(i);
line(263,192,269,231);
line(269,231,89,179);
line(89,179,108,151);
setfillstyle(1,9);
floodfill(193,194,i);//for part left light blue
setcolor(i);
line(269,231,524,93);
line(524,93,506,69);
floodfill(454,113,i);//for part side light blue
setcolor(i);
line(269,231,264,260);
line(264,260,101,215);
line(101,215,89,179);
setfillstyle(1,1);//part left for blue
floodfill(193,234,i);
setcolor(i);
line(264,260,514,125);
line(525,94,514,125);
setfillstyle(1,1);
floodfill(489,126,i);
setcolor(i);//part side blue

//end of upperpart

line(102,315,292,383);
line(294,419,292,383);
line(294,419,101,348);
line(102,315,101,348);
setfillstyle(1,1);//lower left
floodfill(154,360,i);
line(542,222,292,383);
line(542,257,542,222);
line(542,257,294,419);
setfillstyle(1,1);
floodfill(480,282,i);//lower side
line(102,315,222,249);
line(407,183,542,222);
setfillstyle(1,1);
floodfill(206,274,i);
line(147,331,146,350);
line(259,390,146,350);
line(258,371,259,390);
line(147,331,411,184);
line(411,184,503,210);
line(503,210,258,371);
setfillstyle(1,13);
floodfill(273,297,i);
//end of base of low part
// start of holes
line(130,311,138,313);
line(138,313,147,307);
line(147,307,139,305);
line(139,305,130,311);
setfillstyle(1,8);
floodfill(139,309,i);
//left 1
liner(176,285,183,287,193,282,186,280,185,284,i);
liner(221,260,229,262,239,257,232,255,230,258,i);
liner(299,362,308,365,315,358,309,357,309,361,i);
liner(347,332,354,335,363,330,357,327,357,330,i);
liner(389,305,396,306,405,301,399,299,399,303,i);
liner(428,280,436,282,444,277,438,276,437,279,i);
liner(467,255,475,257,482,252,476,250,475,255,i);
liner(505,233,511,234,521,229,514,227,513,231,i);
delay(1500);
rightlead(283,225,297,226,301,215,314,220,298,280,317,280,305,282,313,282,305,346,312,343,309,240);
shadow(282,226,294,231,294,281,300,285,301,346,305,346,296,280);
delay(500);
rightlead(333,197,344,200,348,189,360,196,346,253,362,252,350,256,358,255,351,316,358,314,353,221);
shadow(333,197,342,206,343,254,348,258,348,316,351,316,349,315);//for second lead
delay(500);
rightlead(373,175,385,178,391,166,402,172,388,228,404,225,393,232,400,231,394,290,400,287,397,197);
shadow(373,175,383,182,385,229,390,233,391,291,394,290,392,280);
delay(500);
rightlead(417,152,428,155,432,143,442,148,430,205,446,202,435,208,441,207,436,265,441,263,436,178);
shadow(417,152,426,161,426,205,431,211,431,267,436,265,425,155);
delay(500);
rightlead(456,130,466,133,471,122,479,125,469,181,483,180,473,184,479,184,474,239,480,238,475,158);
shadow(456,130,464,137,465,183,471,187,472,241,474,239,473,220);
delay(500);
rightlead(493,110,501,114,506,102,517,107,504,160,519,159,508,163,515,162,509,216,515,216,513,137);
shadow(493,110,499,117,499,162,505,165,505,218,509,216,506,213);
delay(500);
leftlead();
identifier();
getch();
bibin();
}
void liner(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4,int x5,int y5,int i)
{

line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x4,y4);
line(x4,y4,x1,y1);
setfillstyle(1,8);
floodfill(x5,y5,i);//x1,y1 left most then go anticlockwise x5,y5 for fill
}

void rightlead( int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4,int x5,int y5,int x6,int y6,int x7,int y7,int x8,int y8,int x9,int y9,int x10,int y10,int x11,int y11)
{
setcolor(15);
line(x1,y1,x3,y3);//for starting line
line(x1,y1,x2,y2);
line(x3,y3,x4,y4);
line(x2,y2,x5,y5);
line(x4,y4,x6,y6);
line(x5,y5,x7,y7);
line(x6,y6,x8,y8);
line(x7,y7,x9,y9);
line(x10,y10,x8,y8);
line(x10,y10,x9,y9);
setfillstyle(1,7);
floodfill(x11,y11,15);
}
void shadow(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4,int x5,int y5,int x6,int y6,int x7,int y7)
{
setcolor(15);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x4,y4);
line(x5,y5,x4,y4);
line(x5,y5,x6,y6);
setfillstyle(1,8);
floodfill(x7,y7,15);
}

void leftlead()
{
setcolor(15);
line(132,224,133,232);
line(133,232,139,236);
line(139,236,140,297);
line(140,297,146,296);
line(146,296,146,237);
line(146,237,152,232);
line(152,232,152,229);
line(152,229,132,224);
setfillstyle(1,7);
floodfill(142,244,15);
line(129,224,128,234);
line(128,234,135,240);
line(135,240,137,298);
line(137,298,140,297);
line(132,224,129,224);
setfillstyle(1,8);
floodfill(131,236,15);



//end of first lead

line(181,237,181,273);
line(181,273,188,272);
line(188,272,188,241);
line(181,237,188,241);

setfillstyle(1,7);
floodfill(185,255,15);


line(177,237,181,239);
line(177,237,179,275);
line(179,275,181,273);
setfillstyle(1,8);
floodfill(179,256,15);
line(221,249,220,253);
line(220,253,226,252);
line(226,252,225,250);
line(225,250,221,249);
floodfill(223,251,15);
}


void identifier()
{

setcolor(6);
arc(196,177,350,160,26);
line(171,168,222,181);
setfillstyle(1,1);
floodfill(200,170,6);
}


void bibin()
{
int midx=320,midy=230;

cleardevice();
setbkcolor(RED);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(GREEN);
settextstyle(5, VERT_DIR, 4);
return ;
}

Bouncing Ball

Problem Statement : Bouncing Ball

Programming Language : C Graphics

Program Code :

#include
#include
#include
#include
#include
void *ball;

void image()
{
//ball
setcolor(RED);
setfillstyle(SOLID_FILL,RED);
fillellipse(10,10,10,10);
ball=malloc(imagesize(0,0,20,20));
getimage(0,0,20,20,ball);
cleardevice();

}


void main()
{
int gm,gd=DETECT;
initgraph(&gd,&gm,"");
int l=getmaxx()/2,r=0,t=0,b=0;
int x=1,y=1;
int s=0,key=0;
int xstep=1,ystep=1;

image();
setbkcolor(GREEN);

while(key!=27)
{


while(!kbhit()){
putimage(l,t,ball,XOR_PUT);
delay(5);
putimage(l,t,ball,XOR_PUT);

if(l>=getmaxx()||l<=0){x*=-1;sound(1000);s=0;xstep=x*(random(4)+1);ystep=y *(random(3)+1);if(l<=0)l=0;else l=getmaxx();}

if(t>=getmaxy()||t<=0){y*=-1;sound(1000);s=0;ystep=y*(random(4)+1);xstep=x *(random(3)+1);if(t<=0)t=0;else t=getmaxy();}
l+=x+xstep;
t+=y+ystep;
s++;
if(s==5)
{nosound();}
}
key=getch();

}
closegraph();
}