Computer graphics program in Python graphics.py and c++ graphics.
Python
from graphics import *
win = GraphWin("Translate Rectangle", 600, 600)
print("Corner 1")
x1=int(input("Enter x"))
y1=int(input("Enter y"))
c1=Point(x1, y1)
print("Corner 2")
x2=int(input("Enter x"))
y2=int(input("Enter y"))
c2 = Point(x2, y2)
r = Rectangle(c1, c2)
r.draw(win)
dx=int(input("Translation tx"))
dy=int(input("Translation ty"))
x1+=dx
x2+=dx
y1+=dy
y2+=dy
c1 = Point(x1,y1)
c2 = Point(x2, y2)
rt=Rectangle(c1, c2)
rt.draw(win)
win.getMouse()
win.close()
C++
#include<bits/stdc++.h>
#include<graphics.h>
#include<conio.h>
using namespace std;
int main(){
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
int mx = getwindowwidth();
int my = getwindowheight();
int left = mx / 2 - 100;
int top = my / 2 - 100;
int right = mx / 2 + 100;
int bottom = my / 2;
rectangle(left, top, right, bottom);
cout << "Enter translation factors ";
int a, b;
cin >> a >> b;
cleardevice();
rectangle(left + a , top + b, right + a, bottom + b);
getch();
closegraph();
return 0;
}
Before Translation
After Translation: