Computer graphics program to make a moving car

0
817

Computer graphics program in Python and C++

Python

from graphics import *
 
WIDTH, HEIGHT = 800, 400
RADIUS = 40
 
def main():
   win = GraphWin('Experiment 2-3', WIDTH, HEIGHT)
 
   st = Rectangle(Point(75, 25), Point(145, 50))
   st.draw(win)
   st.setFill('red')
   s = Rectangle(Point(50, 50), Point(175, 100))
   s.draw(win)
   s.setFill('blue'
   c1 = Circle(Point(75, 100), 10)
   c1.draw(win)
   c1.setFill('black')
   c2 = Circle(Point(145, 100), 10)
   c2.draw(win)
   c2.setFill('black')
   l = Line(Point(0,112), Point(WIDTH, 112))
   l.draw(win)
   while s.getCenter().getX() < WIDTH - RADIUS:
       s.move(5, 0)
       st.move(5,0)
       c1.move(5,0)
       c2.move(5,0)
   win.getMouse()
   win.close()
main()
computer graphics moving car

C++

#include​<graphics.h>
#include​<stdio.h>
void​​ movecar​(){​
int​​ i​ = ​0​;
​int​​ j​ = ​0​;
​while​(!​kbhit​()){
​delay​(​1​);
​cleardevice​();​
rectangle​(​10​ + ​i​, ​50​+​j​, ​110​ + ​i​, ​100​+​j​);​
circle​(​25​+​i​, ​100​+​j​, ​10​);
​circle​(​90​+​i​, ​100​+​j​, ​10​);
​i​++;​
if​ (​i​ == ​getwindowwidth​() ) {​
i​ = ​0​;
​j​+= ​10​;
}
}
}
int​​ main​(){
​int ​​gd​ = ​DETECT​, ​gm​;​
initgraph​(&​gd​, &​gm​, ​""​);​
movecar​();​
getch​();​
closegraph​();
​return​​0​;
}
computer graphics

LEAVE A REPLY