├── README.md
└── 2d transformations.C
/README.md:
--------------------------------------------------------------------------------
1 | # 2D Transformations in CG
2 | 2D Transformations in Computer Graphics
3 |
4 | ## Get the Code
5 |
6 | ```
7 | $ git clone https://github.com/CodAffection/2D-Transformations-in-CG.git
8 | ```
9 |
10 | ## How it works ?
11 |
12 | :tv: Video tutorial on this same topic
13 | Url : https://youtu.be/WRrUUyyg5xg
14 |
15 |
18 |
19 |
20 | | :bar_chart: | List of Tutorials | | :moneybag: | Support Us |
21 | |--------------------------:|:---------------------|---|---------------------:|:-------------------------------------|
22 | | Angular |http://bit.ly/2KQN9xF | |Paypal | https://goo.gl/bPcyXW |
23 | | Asp.Net Core |http://bit.ly/30fPDMg | |Amazon Affiliate | https://geni.us/JDzpE |
24 | | React |http://bit.ly/325temF | |
25 | | Python |http://bit.ly/2ws4utg | | :point_right: | Follow Us |
26 | | Node.js |https://goo.gl/viJcFs | |Website |http://www.codaffection.com |
27 | | Asp.Net MVC |https://goo.gl/gvjUJ7 | |YouTube |https://www.youtube.com/codaffection |
28 | | Flutter |https://bit.ly/3ggmmJz| |Facebook |https://www.facebook.com/codaffection |
29 | | Web API |https://goo.gl/itVayJ | |Twitter |https://twitter.com/CodAffection |
30 | | MEAN Stack |https://goo.gl/YJPPAH | |
31 | | C# Tutorial |https://goo.gl/s1zJxo | |
32 | | Asp.Net WebForm |https://goo.gl/GXC2aJ | |
33 | | C# WinForm |https://goo.gl/vHS9Hd | |
34 | | MS SQL |https://goo.gl/MLYS9e | |
35 | | Crystal Report |https://goo.gl/5Vou7t | |
36 | | CG Exercises in C Program |https://goo.gl/qEWJCs | |
37 |
--------------------------------------------------------------------------------
/2d transformations.C:
--------------------------------------------------------------------------------
1 | //Author : youtube channel - Dotnet Mob
2 | //Date : 05-Nov-15
3 | //Description : Program for 2D transformations
4 | //For More :https://www.youtube.com/c/DotnetMob
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | # define ROUND(a) ((int)(a+0.5))
11 | # define absx(x) x+320
12 | # define absy(y) 240-y
13 | void DrawCordinates()
14 | {
15 | line(320,0,320,640);
16 | line(0,240,640,240);
17 | }
18 | void main()
19 | {
20 | int gd=DETECT,gm;
21 | int ang,sx,sy,c,k=0,x1,y1,sh,shx,shy,c1;
22 | int poly[20],choice,i,tdx,tdy,shchoice;
23 | int x,y;
24 | clrscr();
25 | initgraph(&gd,&gm,"C:\\TurboC3\\bgi");
26 | DrawCordinates();
27 | poly[0]=absx(20);
28 | poly[1]=absy(20);
29 | poly[2]=absx(70);
30 | poly[3]=absy(20);
31 | poly[4]=absx(70);
32 | poly[5]=absy(70);
33 | poly[6]=absx(20);
34 | poly[7]=absy(70);
35 | poly[8]=poly[0];
36 | poly[9]=poly[1];
37 | drawpoly(5,poly);
38 | printf("This square will be used for 2D transaformations in this program\nPress Any Key To Continue...");
39 | getch();
40 | closegraph();
41 | do
42 | {
43 | clrscr();
44 | printf("\n****************MENU***************\n");
45 | printf("\n1.Translation\n2.Rotation\n3.Scaling\n4.Reflection\n5.Exit");
46 | printf("\nEnter your choice : ");
47 | scanf("%d",&choice);
48 | switch(choice)
49 | {
50 | case 1:
51 | clrscr();
52 | initgraph(&gd,&gm,"c:\\turboc3\\bgi");
53 | DrawCordinates();
54 | drawpoly(5,poly);
55 | printf("\nEnter translation vectors (tx,ty):");
56 | scanf("%d%d",&tdx,&tdy);
57 | for(i=0;i<8;i=i+2)
58 | {
59 | poly[i]=poly[i]+tdx;
60 | poly[i+1]-=tdy;
61 | }
62 | poly[8]=poly[0];
63 | poly[9]=poly[1];
64 | setcolor(RED);
65 | drawpoly(5,poly);
66 | getch();
67 | closegraph();
68 | break;
69 | case 2:
70 | clrscr();
71 | initgraph(&gd,&gm,"c:\\turboc3\\bgi");
72 | DrawCordinates();
73 | drawpoly(5,poly);
74 | printf("\nEnter rotation angle:");
75 | scanf("%d",&ang);
76 | for(i=0;i<8;i=i+2)
77 | {
78 | int tx= poly[i]-320;
79 | poly[i]=320+((poly[i]-320)*cos(ang*0.01744)-(240-poly[i+1])*sin(ang*0.01744));
80 | poly[i+1]=240-((240-poly[i+1])*cos(ang*0.01744)+(tx)*sin(ang*0.01744));
81 | }
82 | poly[8]=poly[0];
83 | poly[9]=poly[1];
84 | setcolor(RED);
85 | drawpoly(5,poly);
86 | getch();
87 | closegraph();
88 | break;
89 | case 3:
90 | clrscr();
91 | initgraph(&gd,&gm,"c:\\turboc3\\bgi");
92 | DrawCordinates();
93 | drawpoly(5,poly);
94 | printf("\nEnter scaling vectors (tx,ty):");
95 | scanf("%d%d",&sx,&sy);
96 | for(i=2;i<8;i=i+2)
97 | {
98 | poly[i]=poly[i]*sx+poly[0]*(1-sx);
99 | poly[i+1]=poly[i+1]*sy+poly[1]*(1-sy);
100 | }
101 | poly[8]=poly[0];
102 | poly[9]=poly[1];
103 | setcolor(RED);
104 | drawpoly(5,poly);
105 | getch();
106 | closegraph();
107 | break;
108 | case 4:
109 | clrscr();
110 | initgraph(&gd,&gm,"c:\\turboc3\\bgi");
111 | DrawCordinates();
112 | drawpoly(5,poly);
113 | printf("\n1.Y-axis\n2.X-axis\n3.exit\n");
114 | scanf("%d",&c1);
115 | switch(c1)
116 | {
117 | case 1:
118 | for(k=0;k<8;k=k+2)
119 | {
120 | x1=poly[k];
121 | y1=poly[k+1];
122 | poly[k]=320-(x1-320);
123 | poly[k+1]=y1;
124 | }
125 | poly[8]=poly[0];
126 | poly[9]=poly[1];
127 | setcolor(RED);
128 | drawpoly(5,poly);
129 | getch();
130 | break;
131 | case 2:
132 | for(k=0;k<8;k=k+2)
133 | {
134 | x1=poly[k];
135 | y1=poly[k+1];
136 | poly[k]=x1;
137 | poly[k+1]=240-(y1-240);
138 | }
139 | poly[8]=poly[0];
140 | poly[9]=poly[1];
141 | setcolor(RED);
142 | drawpoly(5,poly);
143 | getch();
144 | break;
145 | case 3:
146 | break;
147 |
148 | }
149 | closegraph();
150 | break;
151 | case 5:
152 | exit(0);
153 | }
154 | }while(choice!=6);
155 | }
156 |
157 |
158 |
--------------------------------------------------------------------------------