1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include <conio.h>
#include "myheader.h" of link list stack
#define TRUE 1
#define FALSE 0
#define RESET 0
int main()
{
Stack S = NULL;
int x0, x1, x2, x3, y0, y1, y2, y3;
int startx, starty;
int polygonCounter;
initwindow(800, 800);
int m = 0;
setcolor(4);
while(m < 100)
{
while(!ismouseclick(WM_MBUTTONDOWN))
{
if(ismouseclick(WM_LBUTTONDOWN))
{
getmouseclick(WM_LBUTTONDOWN, x0, y0);
PushStack(&x0, S);
PushStack(&y0, S);
if(polygonCounter == 0)
{
startx = x0;
starty = y0;
}
polygonCounter++;
while(!ismouseclick(WM_LBUTTONDOWN))
{
setcolor(4);
y0 = PopStack(S);
x0 = PopStack(S);
x1 = mousex();
y1 = mousey();
line(x0, y0, x1, y1);
PushStack(&x0, S);
PushStack(&y0, S);
if(polygonCounter > 1)
{
y3 = PopStack(S);
x3 = PopStack(S);
y2 = PopStack(S);
x2 = PopStack(S);
line(x2, y2, x3, y3);
PushStack(&x2, S);
PushStack(&x2, S);
PushStack(&x3, S);
PushStack(&x3, S);
}
delay(50);
setcolor(0);
line(x0, y0, x1, y1);
if(ismouseclick(WM_RBUTTONDOWN))
{
setcolor(0);
y3 = PopStack(S);
x3 = PopStack(S);
y2 = PopStack(S);
x2 = PopStack(S);
line(x3, y3, x2, y2);
PushStack(&x2, S);
PushStack(&y2, S);
polygonCounter--;
clearmouseclick(WM_RBUTTONDOWN);
}
if(ismouseclick(WM_MBUTTONDOWN))
{
y0 = PopStack(S);
x0 = PopStack(S);
delay(50);
setcolor(3);
line(x0, y0, startx, starty);
PushStack(&x0, S);
PushStack(&y0, S);
}
}
}
}
x0 = RESET;
x1 = RESET;
x2 = RESET;
x3 = RESET;
y0 = RESET;
y1 = RESET;
y2 = RESET;
y3 = RESET;
startx = RESET;
starty = RESET;
setcolor(4);
clearmouseclick(WM_LBUTTONDOWN);
clearmouseclick(WM_RBUTTONDOWN);
clearmouseclick(WM_MBUTTONDOWN);
m++;
}
system("PAUSE");
return 0;
}
|