C language: Advanced part of turboc advanced programming [2]: drawing a fractal graph using C language

Source: Internet
Author: User

Http://www.hack86.com/read.php? Tid-20788.html

 

# Include "graphics. H"
# Include "stdlib. H"
# Include "stdio. H"
# Include "fcntl. H"
# Include "Dos. H"
Union regs R;
Struct mouse {
Int getit;
Int x1;
Int Y1;
Int X2;
Int Y2;
} MS;
Void MSB (float, float, Int, INT );
Void mouse_drop (struct mouse * In );
/* Define the mouse drag function, and select a rectangular area by pressing and opening the mouse */
Int data_processor (struct mouse M, float * x0, float * X1, float * y0, float * Y1 );
/* Convert the area selected by the mouse to the area of the MSB Set */
Void mouse_iqr (int * num, int * BX, int * CX, int * dx)
{/* Call the mouse interruption. Here, define the function to call the following functions to reduce repeated programming,
The int86 function (in DOS. h) is used to call the interrupt function. The interrupt Number of the mouse is 33 H */
R. X. Ax = * num;
R. X. bx = * BX;
R. X. Cx = * CX;
R. X. dx = * DX;
Int86 (0x33, & R, & R );
* BX = R. X. bx;
* Cx = R. X. CX;
* Dx = R. X. dx;
* Num = R. X. Ax;
}

Int init_mouse ()
{
/* Click the mouse to check whether the mouse driver is installed. The function number is 0 */
Int num = 0;
Mouse_iqr (& num, & num );
If (num! =-1)
Return 1;
Else return 0;
}
Void mouse_show ();
Void mouse_position (int * X, int * Y)
{/* Position of the mouse in the screen */
Int button = 0, num = 3;
Mouse_show ();
Mouse_iqr (& num, & button, x, y );
}
Void mouse_hide ()
{/* Hide the mouse cursor */
Int num = 2;
Mouse_iqr (& num, & num );
}
Void mouse_show ()
{/* Show the mouse cursor */
Int num = 1;
Mouse_iqr (& num, & num );
}
Int mouse_click (int K)
{/* Use the left mouse button (return 1) or right-click (return 2 )*/
Int BX = 0, num = 3;
Mouse_iqr (& num, & BX, & num, & num );
Return (BX & K );
}
Void WaIton (INT buttom)
{/* Wait for the mouse action */
If (buttom = 1)
While (mouse_click (1 ));
If (buttom = 2)
While (mouse_click (2 ));
}
Int mousexy (INT X1, int Y1, int X2, int Y2)
{/* Query whether the mouse is in the area */
Int X, Y;
Mouse_position (& X, & Y );
If (x> X1 & xy1 & yl | M <-1e10) break;
X = xx;
Y = YY;
}
Color = n % 16;
Putpixel (X1 + I, Y1 + J, color );
}
}
}
Void mouse_drop (struct mouse * in)
{
Char out [20];
Int X, Y;
Int oldx, Oldy;
Struct mouse R;
R = * in;
Setwritemode (1 );
Setlinestyle (userbit_line, 0x7777,1 );
Setcolor (15 );
If (R. getit = 1)
{
Mouse_hide ();
Rectangle (R. X1, R. Y1, R. X2, R. Y2 );
Mouse_show ();
Mouse_position (& X, & Y );
R. X1 = X;
R. Y1 = y;
Oldx = X;
Oldy = y;
R. getit = 1;
Mouse_hide ();
Rectangle (X, Y, x, y );
Mouse_show ();
While (mouse_click (1) {mouse_position (& X, & Y );
If (oldx! = X | Oldy! = Y ){
Mouse_hide ();
Rectangle (R. X1, R. Y1, x, y );
Rectangle (R. X1, R. Y1, oldx, Oldy );
Mouse_show ();
Oldx = X;
Oldy = y;
}
If (mouse_click (2 )){
R. getit = 0;
Mouse_hide ();
Rectangle (R. X1, R. Y1, oldx, Oldy );
Mouse_show ();
WaIton (2 );
Break ;}
}
If (R. getit = 1 ){
R. X2 = X;
R. y2 = y;
If (x = R. X1 & R. Y1 = y)
R. getit = 0;
Else
R. getit = 1;
}
Setlinestyle (solid_line, 0, 1 );
* In = R;
WaIton (1 );
Setwritemode (0 );
Setmouse (0, 0, getmaxx (), getmaxy ());
}
Int data_processor (struct mouse M, float * x0,
Float * X1, float * y0, float * Y1)
{
Float D1, L1, D2, L2, D, L;
Float xx0, xx1, yy0, YY1, X, Y;
D1 = * x1-* x0;
L1 = * Y1-* y0;
D2 = 637;
L2 = 477;
Xx0 = M. x1;
Xx1 = M. X2;
Yy0 = M. Y1;
YY1 = M. Y2;
If (xx0 = xx1 | yy0 = YY1) Return (0 );
If (xx0> xx1)
{X = xx0;
Xx0 = xx1;
Xx1 = X;
}
If (yy0> YY1)
{X = yy0;
Yy0 = YY1;
YY1 = X;
}
D = 1;
L = 1;
X = * x0;
Y = * y0;
* X0 = x + (xx0-d) * D1/D2;
* X1 = x + (xx1-d) * D1/D2;
* Y0 = Y + (yy0-l) * L1/L2;
* Y1 = Y + (yy1-l) * L1/L2;
If (* X0 = * X1 | * Y0 = * Y1)
Return (0 );
Else
Return (1 );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.