Simple Program to implement Transformation in Graphics(Translation, Rotation, Scaling & Shearing)
- Get link
- X
- Other Apps
#include <iostream>
#include <conio.h>
#include <graphics.h>
#include <math.h>
using namespace std;
main()
{
int gd = DETECT,gm;
int x1,x2,x3,y1,y2,y3,choice;
cout<<"Enter coordinates of the triangle(x1,y1) : ";
cin>>x1>>y1;
cout<<"Enter coordinates of the triangle(x2,y2) : ";
cin>>x2>>y2;
cout<<"Enter coordinates of the triangle(x3,y13 : ";
cin>>x3>>y3;
cout<<"**********MENU**********";
cout<<"\n1. Translation\n2. Rotation\n3. Scaling\n4. Shearing\n";
cin>>choice;
cout<<"Before transformation: \n";
initgraph(&gd,&gm,"");
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
switch(choice)
{
case 1:
{
int tx,ty;
cout<<"Enter the x- translation factor: ";
cin>>tx;
cout<<"\nEnter the y- translation factor: ";
cin>>ty;
x1=x1+tx;
x2=x2+tx;
x3=x3+tx;
y1=y1+ty;
y2=y2+ty;
y3=y3+ty;
cout<<"After transformation: ";
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
break;
}
case 2:
{
int theta;
cout<<"Enter the rotation angle: ";
cin>>theta;
int x1n,y1n,x2n,y2n,x3n,y3n;
x1n= x1*cos(theta*3.14/180)-y1*sin(theta*3.14/180);
y1n= x1*sin(theta*3.14/180)+y1*cos(theta*3.14/180);
x2n= x2*cos(theta*3.14/180)-y2*sin(theta*3.14/180);
y2n= x2*sin(theta*3.14/180)+y2*cos(theta*3.14/180);
x3n= x3*cos(theta*3.14/180)-y3*sin(theta*3.14/180);
y3n= x3*sin(theta*3.14/180)+y3*cos(theta*3.14/180);
cout<<"After Rotation: ";
line(x1n,y1n,x2n,y2n);
line(x2n,y2n,x3n,y3n);
line(x3n,y3n,x1n,y1n);
break;
}
case 3:
{
int sx,sy;
cout<<"Enter the x- scaling factor: ";
cin>>sx;
cout<<"\nEnter the y- scaling factor: ";
cin>>sy;
x1=x1*sx;
x2=x2*sx;
x3=x3*sx;
y1=y1*sy;
y2=y2*sy;
y3=y3*sy;
cout<<"After transformation: ";
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
break;
}
case 4:
{
int shx,shy;
int x1s,y1s,x2s,y2s,x3s,y3s;
cout<<"Enter the x- shearing factor: ";
cin>>shx;
cout<<"\nEnter the y- shearing factor: ";
cin>>shy;
x1s=x1+y1*shx;
x2s=x2+y2*shx;
x3s=x3+y3*shx;
y1s=y1+x1*shy;
y2s=y2+x2*shy;
y3s=y3+x3*shy;
cout<<"After transformation: ";
line(x1s,y1s,x2s,y2s);
line(x2s,y2s,x3s,y3s);
line(x3s,y3s,x1s,y1s);
break;
}
}
getch();
}
OUTPUT:
Run 1:
Run 2:
Run 3:
Run 4:
- Get link
- X
- Other Apps
Popular posts from this blog
Download and install MATLAB R2017a in Ubuntu 18.04 | Linux Free | Cracked
HOW TO SETUP CODE BLOCKS FOR GRAPHICS PROGRAMS
How to setup... Download Code::Blocks from here . You have to download the codeblocks-17.12mingw-setup.exe or codeblocks-17.12mingw nosetup.zip file. The first file(highlighted) is the install-able setup and the other one(highlighted) is portable zip file(not need to install). If you are beginners you prefer the first one. After the installation you locate the code blocks at location C:\Program Files (x86)\CodeBlocks or at C:\Program Files\CodeBlocks. You have to download the graphics file from this link . Extras this zip file, it includes three files (two header files & a library file). Now copy the graphics.h & winbgim.h header files and paste at location C:\Program Files (x86)\CodeBlocks\MinGW\include And copy the libbgi.a file at location C:\Program Files (x86)\CodeBlocks\MinGW\lib Now open the code blocks and follow the steps: 1. Left click on "Settings (menu item)" in "Start here - Code::B...
Smile emoji using graphics in Java using Applet
import java.awt.*; import java.awt.event.*; import java.applet.*; public class Smile extends Applet { public void paint(Graphics g) { setBackground(Color.BLACK); g.setColor(Color.YELLOW); g.fillOval(30,50,100, 100); g.setColor(Color.BLACK); g.fillOval(55,75,10, 10); g.fillOval(95,75,10, 10); g.drawArc(60, 85, 40,40,-30,-120); } } /* <applet code="Smile.class" width="200" height="200"> </applet> */ OUTPUT:
Comments
Post a Comment