📄 chakri.cpp
字号:
#include<graphics.h>
#include<dos.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
#include<time.h>
#include<stdlib.h>
union REGS i,o;
int initmouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
return (o.x.ax);
}
void showmptr()
{
i.x.ax=1;
int86(0x33,&i,&o);
return;
}
void hidemptr()
{
i.x.ax=2;
int86(0x33,&i,&o);
}
void getmpos(int *button,int *x,int *y)
{
i.x.ax=3;
int86(0x33,&i,&o);
*button=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
return;
}
void restrictmptr(int x1,int y1,int x2,int y2)
{
i.x.ax=7;
i.x.cx=x1;
i.x.dx=x2;
int86(0x33,&i,&o);
i.x.ax=8;
i.x.cx=y1;
i.x.dx=y2;
int86(0x33,&i,&o);
return;
}
#include<math.h>
void spiral(int xcen,int ycen,float rad)
{
int x,y;
float r,dr=0.01;
while(r<rad) {
x = r * cos(r);
y = r * sin(r);
putpixel(x+xcen,y+ycen,0);
r = r + dr;
}
}
/*cardoid(int x,int y,int r)
{
double th,r1,dt;
int x1,y1,x2,y2;
r = r ? r:1;
dt = 1.0/r;
x1 = (x-r) + 2 * r;
y1 = y;
th = 0.0;
x -= r;
for(;th < 6.28; th += dt) {
r1 = r * (1 + cos(th));
putpixel(x1,y1,0);
x1 = x + r1 * cos(th);
y1 = y + r1 * sin(th);
}
return 0;
}*/
void inter()
{
int i,j,maxx,maxy;
maxx = getmaxx();
maxy = getmaxy();
cleardevice();
/*outline box*/
rectangle(0,1,maxx,maxy);
/* providing gray shade*/
setfillstyle(1,LIGHTGRAY);
bar(1,0,638,6);
bar(2,39,637,65);
setcolor(WHITE);
line(3,39,636,39);
line(2,39,2,65);
setcolor(BLACK);
line(3,65,636,65);
line(637,39,637,65);
/* drawing quit boxes*/
setcolor(WHITE);
line(612,43,630,43);
line(612,43,612,61);
setcolor(BLACK);
line(631,43,631,62);
line(612,62,630,62);
/* quit cross */
setcolor(BLACK);
line(617,48,627,58);
line(618,47,628,57);
line(627,48,617,58);
line(626,47,616,57);
/* tool bar */
bar(2,67,68,442);
setcolor(WHITE);
line(2,67,2,441);
line(2,66,68,66);
/*tool buttons-white*/
line(9,72,9,339);
line(9,71,60,71);
line(36,72,36,339);
line(9,302,61,302);
for(i=110;i<281;i+=38)
line(9,i,60,i);
line(61,350,61,420);
line(10,420,61,420);
/* tool buttons- gray */
setcolor(BLACK);
line(61,71,61,339);
line(9,301,61,301);
line(35,71,35,340);
line(9,340,61,340);
for(i=109;i<281;i+=38)
line(9,i,61,i);
line(9,350,9,420);
line(9,350,60,350);
/*line button*/
line(31,78,17,102);
/*ellipse and circle button */
circle(22,128,9);
/* rubberbanding rectangle button*/
rectangle(14,153,30,180);
/* 3d button */
bar3d(40,275,51,296,6,1);
/* free hand button */
for(i=0;i<3;i++)
line(58-i,159,51-i,173);
line(51,155,44,170);
line(52,155,45,170);
for(i=0;i<7;i++)
line(44,170+i,50-i,173+i);
line(51,155,57,159);
line(51,173,44,179);
line(44,170,44,178);
/* erase button */
line(40,82,48,98);
line(40,83,48,75);
line(48,75,56,90);
line(56,90,48,98);
line(56,90,56,96);
line(48,98,48,103);
line(48,104,56,96);
line(40,83,41,93);
line(47,104,41,91);
setcolor(YELLOW);
for(i=0;i<6;i++)
line(42+i,83-i,47+i,92-i);
line(47,94,53,88);
line(41,86,46,96);
line(42,91,45,98);
/* paint a region button */
setcolor(BLACK);
rectangle(41,125,56,131);
rectangle(47,125,50,114);
line(41,130,56,130);
setcolor(YELLOW);
for(i=0;i<6;i+=2)
line(42,126+i,55,126+i);
line(48,124,48,115);
line(49,124,49,115);
setcolor(WHITE);
for(i=0;i<15;i+=2)
line(42+i,132,43+i,138);
/* clear screen button */
setfillstyle(1,WHITE);
bar(42,231,55,255);
setcolor(BLACK);
rectangle(42,231,55,255);
settextstyle(2,1,4);
outtextxy(42,234,"cls");
setfillstyle(1,LIGHTGRAY);
/* background colour button */
setfillstyle(1,WHITE);
bar(13,268,31,295);
setfillstyle(1,BLACK);
bar(18,275,26,287);
rectangle(13,268,31,295);
setfillstyle(1,LIGHTGRAY);
bar(3,444,637,477);
setcolor(LIGHTGRAY);
rectangle(9,350,61,420);
/* text font button */
setcolor(YELLOW);
settextstyle(4,0,4);
line(11,257,20,230);
line(13,257,22,230);
line(15,257,24,230);
line(17,257,26,230);
line(19,257,28,230);
line(21,257,30,230);
line(23,257,32,230);
line(25,257,34,230);
setcolor(WHITE);
line(2,444,2,477);
/* fill pattern style palette */
line(633,460,633,446);
line(330,460,633,460);
for(i=0;i<260;i+=25)
line(355+i,447,355+i,460);
setcolor(BLACK);
line(330,446,633,446);
line(330,446,330,459);
/* FILLING THE FILL PATTERN STYLE PALETTE */
for(i=1,j=0;i<11&&j<290;i++,j+=25) {
setfillstyle(i,i);
bar(357+j,447,379+j,459);
}
setfillstyle(11,11);
bar(607,447,632,459);
for(i=0;i<260;i+=25)
line(356+i,447,356+i,459);
/* help area */
line(330,462,633,462);
line(330,462,330,474);
setcolor(WHITE);
line(330,475,633,475);
line(633,475,633,462);
/* drawing area */
setfillstyle(1,WHITE);
bar(71,67,637,442);
/* spiral button */
spiral(47,320,14.8);
/* jango look */
setcolor(0);
rectangle(8,345,61,364);
setcolor(15);
line(8,364,61,364);
line(61,345,61,364);
setfillstyle(1,10);
bar(10,347,60,363);
setcolor(BLACK);
rectangle(9,387,61,438);
setcolor(15);
line(9,438,61,438);
line(61,387,61,438);
/* printing headings*/
setfillstyle(1,BLACK);
setcolor(BLACK);
bar(2,8,638,39);
line(1,39,638,39);
setcolor(MAGENTA);
settextstyle(1,0,2);
outtextxy(225,10,"GRAPHICS PACKAGE");
settextstyle(1,0,1);
setcolor(BLACK);
outtextxy(100,42,"File");
outtextxy(220,42,"Edit");
outtextxy(340,42,"View");
outtextxy(460,42,"Credits");
/* filling the color palette */
for(j=0,i=0;j<400&&i<8;j+=31,i++) {
setfillstyle(1,i);
bar(70+j,446,99+j,459);
}
for(j=0,i=8;j<400&&i<16;j+=31,i++) {
setfillstyle(1,i);
bar(70+j,461,99+j,474);
}
/* drawing the color palette */
setcolor(WHITE);
line(69,475,317,475);
line(317,446,317,475);
line(4,475,65,475);
line(66,446,66,475);
line(15,462,15,450);
line(41,458,48,458);
line(15,449,41,449);
line(24,462,24,471);
line(69,460,316,460);
for(i=100;i<316;i+=31)
line(i,446,i,474);
setcolor(BLACK);
line(49,458,49,471);
line(49,471,24,471);
line(15,462,40,462);
line(41,449,41,462);
line(4,446,65,446);
line(4,446,4,474);
line(69,446,316,446);
line(69,461,316,461);
line(69,446,69,474);
for(i=101;i<316;i+=31)
line(i,446,i,474);
setfillstyle(1,LIGHTGRAY);
bar(71,67,72,442);
bar(71,67,637,68);
arc(22,322,0,180,8);
/* polygon button */
line(49,194,40,212);
line(49,194,57,212);
line(49,195,41,212);
line(49,195,56,212);
line(40,212,57,212);
line(40,213,57,213);
/* ellipse button */
ellipse(22,204,0,360,8,14);
ellipse(22,204,0,360,7,13);
/* default colour and pattern button */
setfillstyle(1,9);
bar(16,450,39,460);
rectangle(28,464,45,468);
if(initmouse()==0) {
closegraph();
restorecrtmode();
printf("mouse driver not loaded");
exit(1);
}
restrictmptr(1,39,maxx-1,maxy-1);
showmptr();
}
help(int x,int y)
{
setcolor(BLACK);
settextstyle(2,0,4);
if((x>70 && x<316) && (y>447 && y<473))
outtextxy(340,462,"To choose a colour .");
else if((x>331 && x<633) && (y>447 && y<459))
outtextxy(340,462,"To choose a pattern .");
else if((x>10 && x<34)&&(y>72&&y<108))
outtextxy(340,462,"To draw a line .");
else if ((x>37&&x<61)&&(y>72&&y<108))
outtextxy(340,462,"Eraser .");
else if((x>10&&x<34)&&(y>110&&y<148))
outtextxy(340,462,"To draw a circle .");
else if((x>37&&x<61)&&(y>110&&y<148))
outtextxy(340,462,"To paint an area .");
else if((x>10&&x<34)&&(y>150&&y<186))
outtextxy(340,462,"To draw a rectangle .");
else if((x>37&&x<61)&&(y>150&&y<186))
outtextxy(340,462,"Free hand drawing .");
else if((x>37&&x<61)&&(y>190&&y<224))
outtextxy(340,462,"To draw a polygon .");
else if((x>10&&x<34)&&(y>190&&y<224))
outtextxy(340,462,"To draw an ellipse .");
else if((x>10&&x<34)&&(y>230&&y<261))
outtextxy(340,462,"To draw styled line pattern .");
else if((x>37&&x<61)&&(y>230&&y<261))
outtextxy(340,462,"Press to clear the screen .");
else if((x>10&&x<34)&&(y>262&&y<298))
outtextxy(340,462,"To change background colour");
else if((x>37&&x<61)&&(y>262&&y<298))
outtextxy(340,462,"To view 3D figures .");
else if((x>10&&x<34)&&(y>303&&y<339))
outtextxy(340,462,"To draw a arc .");
else if((x>36&&x<61)&&(y>303&&y<339))
outtextxy(340,462,"To draw a spiral .");
else if((x>1&&x<71)&&(y>368&&y<384))
outtextxy(340,462,"Time display .");
else if((x>612&&x<631)&&(y>43&&y<60))
outtextxy(340,462,"To exit from the program .");
else if((x>14&&x<40)&&(y>450&&y<461))
outtextxy(340,462,"Displays selected colour .");
else if((x>24&&x<50)&&(y>463&&y<471))
outtextxy(340,462,"Displays selected pattern .");
else {
setfillstyle(1,LIGHTGRAY);
bar(331,463,503,474);
}
return 0;
}
/* drawing the wheel */
#include<math.h>
#include<graphics.h>
int malla=0;
void wheel(int x1,int y1,float angle)
{
float a;
circle(x1,y1,88);
for(a=0.0;a<M_PI;a+=M_PI/6)
line(x1+88*cos(a+angle),y1+88*sin(a+angle),x1-88*cos(a+angle),y1-88*sin(a+angle));
}
/* rotating the wheel */
rotwheel()
{
int i,j,x,y,butt,x1,y1,ch;
float angle,delta=M_PI/20;
setcolor(BLACK);
setfillstyle(1,0);
bar(73,70,636,442);
x1 = 169;
y1 = 353;
angle = 0;
wheel(x1,y1,angle);
while(butt!=1) {
setcolor(BLACK);
wheel(x1,y1,angle);
setcolor(BLUE);
if(x1<520) {
x1+=delta*50;
angle+=delta;
if(angle>2*M_PI)
angle-=2*M_PI;
}
else {
x1=169;
}
wheel(x1,y1,angle);
delay(100);
getmpos(&butt,&x,&y);
}
return 0 ;
}
/* to select color from palette - left click */
int selecolor(int x3[],int x4[],int x,int y,int button)
{
int culur,i,j=8;
for(i=0;i<8;i++) {
if((x>x3[i]&&x<x4[i])&&(y>447&&y<458)&&(button&1==1))
culur=i;
else if((x>x3[i]&&x<x4[i])&&(y>462&&y<475)&&(button&1==1))
culur=i+j;
}
return culur;
}
/* to change color of palette- left click */
changcol(int cbut)
{
setfillstyle(1,cbut);
bar(16,450,39,460);
return 0 ;
}
/* to select pattern from palette*/
int selepat(int x1[],int x2[],int x,int y,int *cbu,int button)
{
int i,pattu;
for(i=0;i<12;i++)
if((x>x1[i]&&x<x2[i])&&(y>447&&y<458)&&(button&1==1))*cbu=i;
return *cbu;
}
/* to change style of pattern - left click */
chngpat(int cbu)
{
if(cbu==0) {
setfillstyle(1,LIGHTGRAY);
bar(42,459,47,469);
bar(25,463,41,469);
rectangle(28,464,45,468);
}
else {
setfillstyle(cbu,cbu);
bar(42,459,47,469);
bar(25,463,41,469);
}
return 0;
}
struct s {
unsigned int sx;
unsigned int sy;
unsigned int sc;
} a[5000];
int index=0,cbut,array[10],select[4],cbut1,bkgrnd;
void storepixel(int x,int y)
{
a[index].sx=x;
a[index].sy=y;
if((a[index].sc=getpixel(x,y))!=cbut)
index++;
}
int sgn(int a)
{
if(a>0)
return 1;
if(a<0)
return -1;
return 0;
}
void bresline(int x1,int y1,int x2,int y2)
{
int d,x,y,xincr,yincr,dy,dx;
dx=x2-x1;
dy=y2-y1;
xincr=sgn(dx);
yincr=sgn(dy);
dx=dx<0? -dx :dx;
dy=dy<0? -dy:dy;
x=x1;
y=y1;
if(dx>dy) {
d=2*dy-dx;
while(x!=x2) {
storepixel(x,y);
if((x>73&&x<638)&&(y>69&&y<443))
if(malla==0) {
putpixel(x,y,cbut);
}
if(d>0) {
y+=yincr;
d-=2*dx;
}
x+=xincr;
d+=2*dy;
}
if((x>73&&x<638)&&(y>69&&y<443))
if(malla==1) {
line(x,y,x+2,y+30);
}
}
else {
d=2*dx-dy;
while(y!=y2) {
storepixel(x,y);
if((x>73&&x<638)&&(y>69&&y<443))
if(malla==0) {
putpixel(x,y,cbut);
}
if(d>0) {
x+=xincr;
d-=2*dy;
}
y+=yincr;
d+=2*dx;
}
if((x>73&&x<638)&&(y>69&&y<443))
if(malla==1) {
line(x,y,x+2,y+30);
}
}
return;
}
void brescircle(int xc,int yc,int r)
{
int x=0,y=r,d=1-r;
while(y>=x) {
storepixel(xc+x,yc+y);
if((xc+x>73&&xc+x<638)&&(yc+y>69&&yc+y<443))
putpixel(xc+x,yc+y,cbut);
storepixel(xc+x,yc-y);
if((xc+x>73&&xc+x<638)&&(yc-y>69&&yc-y<443))
putpixel(xc+x,yc-y,cbut);
storepixel(xc-x,yc+y);
if((xc-x>73&&xc-x<638)&&(yc+y>69&&yc+y<443))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -