?? apollo.c
字號:
setcolor ( current_color );
restrict ( 50,35, 598, 423 );
if ( in_range ( out.x.cx, 50, 598 ) && in_range ( out.x.dx, 35, 422))
{
setfillstyle ( SOLID_FILL, WHITE );
hide ( );
bar( out.x.cx, out.x.dx, out.x.cx+7, out.x.dx+7 );
show ( );
delay ( 30 );
}
}while ( out.x.bx == 1 );
}
}
int mouse_on_canvas ( union REGS out)
{
if ( in_range ( out.x.cx, 50, 605 ) && in_range ( out.x.dx, 35, 430))
return 1;
return 0;
}
void air_spray ( void )
{
union REGS in, out;
int xc, yc, x, y, check;
while ( 1 )
{
in.x.ax = 0x0003;
int86 ( 0x33, &in, &out );
delay ( 5 );
setfillstyle ( SOLID_FILL, LIGHTGRAY );
bar ( 0, 431, 640, 475 );
setcolor ( BLACK );
show_coords ( out.x.cx, out.x.dx );
setcolor ( current_color );
scan_menu ( );
if ( tool_selected ( out ) && get_tool ( out.x.cx, out.x.dx ) != 9 )
return;
else if ( in_range ( out.x.cx,625, 635 ) && in_range ( out.x.dx, 7, 17 )&& out.x.bx==1)
exit ( 0 );
else if ( color_selected ( out ) )
show_current_color ( out.x.cx, out.x.dx, out.x.bx );
if ( !in_range ( out.x.cx, 50, 605 ) || !in_range ( out.x.dx, 35, 430))
continue;
xc = out.x.cx;
yc = out.x.dx;
while ( out.x.bx == 1 )
{
xc = out.x.cx;
yc = out.x.dx;
if ( xc > 595 || xc < 65 )
goto next;
if ( yc > 420 || yc < 47 )
goto next;
x = random ( 641 );
y = random ( 481 );
if ( x < xc-10 || x > xc+10 )
continue;
if ( y < yc - 10 || y > yc+10 )
continue;
check = (xc-x)*(xc-x) + (yc-y)*(yc-y) ;
if ( check < 100 )
{
hide ( );
putpixel ( x, y, current_color );
show ( );
}
next: int86 ( 0x33, &in, &out );
}
}
}
void cube ( long double diagonal, int sx, int sy )
{
int a = ( int ) diagonal/1.73;
int cube[8][3];
double cub[8][2];
int i;
cube[0][0] = sx;
cube[0][1] = sy+a;
cube[0][2] = 0;
cube[1][0] = sx;
cube[1][1] = sy+a;
cube[1][2] = a;
cube[2][0] = sx;
cube[2][1] = sy;
cube[2][2] = a;
cube[3][0] = sx;
cube[3][1] = sy;
cube[3][2] = 0;
cube[4][0] = sx+a;
cube[4][1] = sy+a;
cube[4][2] = 0;
cube[5][0] = sx+a;
cube[5][1] = sy+a;
cube[5][2] = a;
cube[6][0] = sx+a;
cube[6][1] = sy;
cube[6][2] = a;
cube[7][0] = sx+a;
cube[7][1] = sy;
cube[7][2] = 0;
for(i=0;i<8;i++)
{
cub[i][0]= cube[i][0]-cube[i][2]*0.5;
if ( cub [i][0] > CANV_X_MAX )
cub[i][0] = CANV_X_MAX;
if ( cub[i][0] < CANV_X_MIN )
cub[i][0] = CANV_X_MIN;
cub[i][1]= cube[i][1]+cube[i][2]*0.5;
if ( cub [i][1] > CANV_Y_MAX )
cub[i][1] = CANV_Y_MAX;
if ( cub[i][1] < CANV_Y_MIN )
cub[i][1] = CANV_Y_MIN;
}
line(cub[0][0],cub[0][1],cub[1][0],cub[1][1]);
line(cub[1][0],cub[1][1],cub[2][0],cub[2][1]);
line(cub[2][0],cub[2][1],cub[3][0],cub[3][1]);
line(cub[3][0],cub[3][1],cub[0][0],cub[0][1]);
line(cub[0][0],cub[0][1],cub[4][0],cub[4][1]);
line(cub[1][0],cub[1][1],cub[5][0],cub[5][1]);
line(cub[2][0],cub[2][1],cub[6][0],cub[6][1]);
line(cub[3][0],cub[3][1],cub[7][0],cub[7][1]);
line(cub[4][0],cub[4][1],cub[5][0],cub[5][1]);
line(cub[5][0],cub[5][1],cub[6][0],cub[6][1]);
line(cub[6][0],cub[6][1],cub[7][0],cub[7][1]);
line(cub[7][0],cub[7][1],cub[4][0],cub[4][1]);
}
void draw_cube ( void )
{
union REGS in,out;
int start_x, start_y, cur_x, cur_y;
long double diagonal;
while ( 1 )
{
in.x.ax = 0x0003;
int86 ( 0x33, &in, &out );
delay ( 5 );
setfillstyle ( SOLID_FILL, LIGHTGRAY );
bar ( 0, 431, 640, 475 );
setcolor ( BLACK );
show_coords ( out.x.cx, out.x.dx );
setcolor ( current_color );
scan_menu ( );
if ( tool_selected ( out ) && get_tool ( out.x.cx, out.x.dx ) != 13 )
return;
else if ( in_range ( out.x.cx,625, 635 ) && in_range ( out.x.dx, 7, 17 )&& out.x.bx==1)
exit ( 0 );
else if ( color_selected ( out ) )
show_current_color ( out.x.cx, out.x.dx, out.x.bx );
if ( !in_range ( out.x.cx, 50, 605 ) || !in_range ( out.x.dx, 35, 430))
continue;
else if ( out.x.bx == 1 )
{
start_x = out.x.cx;
start_y = out.x.dx;
do
{
in.x.ax = 0x0003;
int86 ( 0x33, &in, &out );
hide ( );
setcolor ( 15 - current_color );
setwritemode ( XOR_PUT );
//fixing limits for my drawing
if ( out.x.cx < 50 )
cur_x = 50;
else if ( out.x.cx > 605 )
cur_x = 605;
else
cur_x = out.x.cx;
if ( out.x.dx < 35 )
cur_y = 35;
else if ( out.x.dx > 430 )
cur_y = 430;
else
cur_y = out.x.dx;
// finished fixing the points
//now start drawing
diagonal = sqrt ( (double ) abs((start_x - cur_x) * ( start_x - cur_x ) + ( start_y - cur_y ) * ( start_y - cur_y)));
cube ( diagonal, start_x, start_y);
//finished drawing
show ( );
delay ( 40 );
hide ( );
cube ( diagonal, start_x, start_y );
show ();
setfillstyle ( SOLID_FILL, LIGHTGRAY );
bar ( 0, 431, 640, 475);
setcolor ( BLACK );
show_coords ( out.x.cx, out.x.dx );
setcolor ( 15 - current_color );
} while ( out.x.bx == 1 );
setcolor ( current_color );
setwritemode ( COPY_PUT );
hide ( );
diagonal = sqrtl ( ( double ) abs ((start_x - cur_x) * ( start_x - cur_x ) + ( start_y - cur_y ) * ( start_y - cur_y)));
cube ( diagonal, start_x, start_y );
show ( );
}
}
}
struct node
{
int x;
int y;
struct node *next;
};
struct node *root,*temporary,*last;
void insert(int x,int y)// insert into struct node
{
struct node *temp;
temp= ( struct node*) malloc ( sizeof ( struct node)) ;
if(temp==NULL)
{
closegraph();
printf ( "Out of memory" );
exit(0);
}
temp->x=x;
temp->y=y;
temp->next=NULL;
last->next=temp; // insert at end of list
last=temp;
return;
}
void fill(int x,int y )
{
int color=getpixel(x,y);
int tmp;
int clr = current_color;
if(color==clr )
return;
last=root=( struct node* )malloc ( sizeof ( struct node ));
root->x=x;
root->y=y;
root->next=NULL;
while(root!=NULL)
{
putpixel(x,y,clr);
tmp=getpixel(x,y-1);
if( tmp==color && tmp!=clr && in_range ( x, CANV_X_MIN, CANV_X_MAX ) && in_range ( y-1, CANV_Y_MIN, CANV_Y_MAX ))
{
putpixel(x,y-1,clr);
insert(x,y-1); // add to list
}
tmp=getpixel(x,y+1);
if( tmp==color && tmp!=clr && in_range ( x,CANV_X_MIN, CANV_X_MAX ) && in_range ( y+1, CANV_Y_MIN, CANV_Y_MAX))
{
putpixel(x,y+1,clr);
insert(x,y+1); // add to list
}
tmp=getpixel(x-1,y);
if( tmp==color && tmp!=clr && in_range ( x-1, CANV_X_MIN, CANV_X_MAX ) && in_range ( y, CANV_Y_MIN, CANV_Y_MAX))
{
putpixel(x-1,y,clr);
insert(x-1,y); // add to list
}
tmp=getpixel(x+1,y);
if( tmp==color && tmp!=clr && in_range ( x+1, CANV_X_MIN, CANV_X_MAX ) && in_range ( y, CANV_Y_MIN, CANV_Y_MAX))
{
putpixel(x+1,y,clr);
insert(x+1,y); // add to list
}
temporary=root;
root=root->next; // goto next node
free ( temporary ); // release
x=root->x;
y=root->y;
}// end while
}
void fill_color ( void )
{
int x, y;
union REGS in, out;
while ( 1 )
{
in.x.ax = 0x0003;
int86 ( 0x33, &in, &out );
delay ( 5 );
setfillstyle ( SOLID_FILL, LIGHTGRAY );
bar ( 0, 431, 640, 475 );
setcolor ( BLACK );
show_coords ( out.x.cx, out.x.dx );
setcolor ( current_color );
scan_menu ( );
if ( tool_selected ( out ) && get_tool ( out.x.cx, out.x.dx ) != 7 )
return;
else if ( in_range ( out.x.cx,625, 635 ) && in_range ( out.x.dx, 7, 17 )&& out.x.bx==1)
exit ( 0 );
else if ( color_selected ( out ) )
show_current_color ( out.x.cx, out.x.dx, out.x.bx );
if ( !in_range ( out.x.cx, 50, 605 ) || !in_range ( out.x.dx, 35, 430))
continue;
else if ( out.x.bx == 1 )
{
x = out.x.cx;
y = out.x.dx;
if ( in_range ( x, CANV_X_MIN, CANV_X_MAX ) && in_range ( y, CANV_Y_MIN, CANV_Y_MAX))
{
hide ( );
fill ( x, y );
show ( );
}
}
}
}
void get_x_shear ( int a )
{
int i,j;
setfillstyle ( SOLID_FILL, WHITE );
bar ( sminx, sminy, smaxx, smaxy );
setcolor ( current_color );
c_c_p = fopen ( "temp", "r" );
i = sminx;
j = sminy;
while ( j < smaxy)
{
if ( in_range ( i, CANV_X_MIN, CANV_X_MAX ) && in_range ( j, CANV_Y_MIN, CANV_Y_MAX))
putpixel( i+a*(smaxy - j ), j , getc (c_c_p) - '0' );
i++;
if ( i == smaxx )
{
j++;
i = sminx;
}
}
}
void shear ( void )
{
int a = 1;
copy_selected_portion ( );
hide ( );
get_x_shear ( a );
show ( );
}
void scale ( void )
{
static int oldx , oldy,pnx, pxx, pny, pxy;
int sx = 0, sy = 0;
int cx, cy, x, y;
int color, i, j;
if ( copied == 0 )
{
copy_selected_portion ( );
oldx = smaxx - sminx;
oldy = smaxy - sminy;
copied = 1;
pnx = sminx;
pny = sminy;
pxx = smaxx;
pxy = smaxy;
delay ( 200 );
return;
}
else
{
hide ( );
copied = 0;
setcolor ( WHITE );
rectangle ( sminx, sminy, smaxx, smaxy );
setcolor ( current_color );
sx = ( smaxx - sminx ) / oldx;
sy = ( smaxy - sminy ) / oldy;
oldx = oldy = 0;
printf ( "%d %d", sx, sy );
c_c_p = fopen ( "temp", "r" );
i = pnx;
j = pny;
x = i;
y = j;
while ( j < pxy )
{
if ( in_range ( i, CANV_X_MIN, CANV_X_MAX ) && in_range ( j, CANV_Y_MIN, CANV_Y_MAX))
{
color = getc ( c_c_p );
for ( cx = 0; cx <= sx; cx++ )
for ( cy = 0; cy <= sy; cy++ )
putpixel ( x+cx, y+cy, color );
x = x+sx;
}
i++;
if ( i == pxx )
{
i = pnx;
j++;
x = i;
y += sy;
}
}
}
show ( );
return;
}
void read_and_write_text ( int x, int y )
{
char ch;
char temp[2] = {'\0'};
int xpos = x, ypos = y;
union REGS in, out;
int line[480];
while ( 1 )
{
in.x.ax = 0x0003;
int86 ( 0x33, &in, &out );
delay ( 5 );
setfillstyle ( SOLID_FILL, LIGHTGRAY );
bar ( 0, 431, 640, 475 );
setcolor ( BLACK );
show_coords ( out.x.cx, out.x.dx );
setcolor ( current_color );
ch = getch ( );
if ( ch == 27 )
return;
else if ( ch == '\r' || xpos+8 > CANV_X_MAX )
{
line[ypos] = xpos;
ypos+=8;
xpos = x;
}
else if ( ch == 8 )
{
if ( xpos < x )
{
ypos-=8;
xpos = line[ypos];
}
else
xpos-=8;
setfillstyle ( SOLID_FILL, WHITE );
bar ( xpos, ypos, xpos+8, ypos+8 );
setcolor ( current_color );
}
else
{
temp[0] = ch;
outtextxy ( xpos, ypos, temp );
xpos+=8;
}
}
}
void text ( void )
{
union REGS in, out;
while ( 1 )
{
in.x.ax = 0x0003;
int86 ( 0x33, &in, &out );
delay ( 5 );
setfillstyle ( SOLID_FILL, LIGHTGRAY );
bar ( 0, 431, 640, 475 );
setcolor ( BLACK );
show_coords ( out.x.cx, out.x.dx );
setcolor ( current_color );
scan_menu ( );
if ( tool_selected ( out ) && get_tool ( out.x.cx, out.x.dx ) != 16 )
return;
else if ( in_range ( out.x.cx,625, 635 ) && in_range ( out.x.dx, 7, 17 )&& out.x.bx==1)
exit ( 0 );
else if ( color_selected ( out ) )
show_current_color ( out.x.cx, out.x.dx, out.x.bx );
if ( !in_range ( out.x.cx, 50, 605 ) || !in_range ( out.x.dx, 35, 430))
continue;
else if ( out.x.bx == 1 )
read_and_write_text (out.x.cx, out.x.dx);
}
}
void init_mouse ( )
{
union REGS in, out ;
int curc;
in.x.ax = 0x0000;
int86 ( 0x33, &in, &out );
set_position ( getmaxx()/2, getmaxy()/2 );
restrict ( 0, 0, getmaxx(), getmaxy());
show();
while ( 1 )
{
draw_tool_bar ( );
setfillstyle ( SOLID_FILL, LIGHTGRAY );
bar ( 0, 430, 640, 475);
show ( );
in.x.ax = 0x0003;
int86 ( 0x33, &in, &out );
scan_menu ( );
if ( color_selected (out) )
show_current_color ( out.x.cx, out.x.dx, out.x.bx );
show_coords ( out.x.cx, out.x.dx );
if ( in_range ( out.x.cx,625, 635 ) && in_range ( out.x.dx, 7, 17 )&& out.x.bx==1)
exit ( 0 );
if ( tool_selected ( out ) )
{
switch ( get_tool ( out.x.cx, out.x.dx ) )
{
case 1 : draw_free_hand ( out );
break;
case 2 : draw_line ( );
break;
case 3 : draw_ellipse ( );
break;
case 4 : draw_rectangle ( );
break;
case 5 : draw_polygon ( );
break;
case 6 : erase ( );
break;
case 7 : fill_color ( );
break;
case 8 : brush = 1;
draw_free_hand ( out );
brush = 0;
break;
case 9 : air_spray ( );
break;
case 10:sminx = smaxy = sminy = smaxx = 0;
setlinestyle ( DOTTED_LINE, 0, 1);
current_line_style = DOTTED_LINE;
curc = current_color;
select_flag = 1;
draw_rectangle ( );
select_flag = 0;
setwritemode ( XOR_PUT);
setcolor ( 15 - BLACK );
hide ( );
rectangle ( sminx, sminy, smaxx, smaxy );
setlinestyle ( SOLID_LINE, 0, 1 );
setwritemode ( COPY_PUT );
current_line_style = SOLID_LINE;
current_color = curc;
setcolor ( current_color );
draw_tool_bar ( );
show ( );
break;
case 11:trans_flag = 1;
translate ( );
trans_flag = 0;
break;
case 12:rotate ( );
break;
case 13:draw_cube ( );
break;
case 14:shear ( );
break;
case 15:scale ( );
break;
case 16:text ( );
break;
default : break;
}
}
delay ( 60 );
}
}
void show_coords ( int x,int y )
{
char str[40];
itoa ( x, str, 10 );
outtextxy (580, 440, str);
outtextxy ( 605, 440, "," );
itoa ( y, str, 10 );
outtextxy (612, 440, str );
}
int in_range ( int val, int lim1, int lim2 )
{
return ( val>=lim1 && val <=lim2 );
}
void set_position ( int x, int y )
{
union REGS in, out;
in.x.cx = x;
in.x.dx = y;
int86 ( 0x33, &in, &out );
return;
}
void restrict ( int xmin, int ymin, int xmax, int ymax )
{
union REGS in, out;
in.x.ax = 0x0007;
in.x.cx = xmin;
in.x.dx = xmax;
int86 ( 0x33, &in, &out );
in.x.ax = 0x0008;
in.x.cx = ymin;
in.x.dx = ymax;
int86 ( 0x33, &in, &out );
return;
}
void show ( void )
{
union REGS in, out;
in.x.ax = 0x0001;
int86 ( 0x33, &in, &out );
return;
}
void hide ( void )
{
union REGS in, out;
in.x.ax = 0x0002;
int86 ( 0x33, &in, &out );
return;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -