0% found this document useful (0 votes)
166 views15 pages

Train C

The document discusses creating a moving train animation in C using graphics libraries. It provides an overview of graphics programming in C and describes how to draw basic shapes like lines, rectangles, and circles to represent the train and track. The algorithm involves initializing graphics, creating train and track objects, and continuously updating the animation in a loop by moving the train and redrawing it. Coding examples are given to demonstrate how to implement the animation. Common challenges mentioned are achieving smooth animation, maintaining coordinate accuracy, compatibility issues, and adding realistic details.

Uploaded by

ashishtruf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
166 views15 pages

Train C

The document discusses creating a moving train animation in C using graphics libraries. It provides an overview of graphics programming in C and describes how to draw basic shapes like lines, rectangles, and circles to represent the train and track. The algorithm involves initializing graphics, creating train and track objects, and continuously updating the animation in a loop by moving the train and redrawing it. Coding examples are given to demonstrate how to implement the animation. Common challenges mentioned are achieving smooth animation, maintaining coordinate accuracy, compatibility issues, and adding realistic details.

Uploaded by

ashishtruf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

UNITED INSTITUTE OF MANAGEMENT

Topic- Make a Moving


Train
MCA 1 Year || Section A || Group No. - 12
st

PRESENTED BY: PRESENTED TO:


• Anshikaa Mr. Ashutosh Pandey
• Garima Singh Assistant Professor
• Jagriti UIM
• Mohammad Anas
• Kaish Aalam
Content
• Introduction
• Overview of Graphics in C
• Drawing Basic Shapes
• Algorithm
• Coding
• Common Challenges
Introduction
• Creating a moving train in C requires the use of a graphics library in Turbo
C/C++.
• These libraries provide the necessary functions for drawing shapes, lines, and
managing the animation loop.
• This project offers a practical application of fundamental programming concepts
and serves as a stepping stone for those interested in game development,
computer graphics, and GUI programming.
• Through this project, you'll grasp the basics of graphics programming, learn to
manipulate pixels, and gain insights into animation techniques.
• The hands-on experience gained can be applied to a wide range of applications,
making it an excellent exercise for programmers at various skill levels.
• Graphics programming in C involves creating visual elements on a computer
screen using dedicated graphics libraries.
Overview of Graphics in C
• Unlike console-based programs, which are text-driven, graphics programs deal
with pixels and provide a platform for creating interactive and visually engaging
applications.
• C offers various graphics libraries, and one commonly used in the context of this
presentation is “graphics.h”.
• This library, often associated with Turbo C, provides a simple set of functions
for drawing basic shapes, lines, and manipulating pixels on the screen.
• Functions like ‘line()’ , ‘circle()’ , ‘rectangle’ , and more are the functions that
act as tool in toolkit for creating and shaping the visual elements of the program.
• Understanding pixel manipulation is fundamental to creating intricate graphics
and animations.
• Graphics programming is often platform-dependent, and some functions might
not work uniformly across different systems.
Drawing Basic Shapes
• Line Drawing: The ‘line()’ function allows you to draw straight lines between
two specified points. Understanding how to draw lines is crucial for creating the
framework of various elements in your graphics program. For example, the body
of the train can be constructed using lines.
• Rectangle Drawing: The ‘rectangle()’ functions is used to draw rectangles,
which are essential for creating the main body and cars of the train. Rectangles
provide a simple way to represent solid structures in your graphical environment.
• Circle Drawing: The ‘circle()’ function is employed to draw circles and arcs.
This can be useful for creating wheels and other rounded components of the
train. Understanding circle drawing is essential for adding a touch of realism to
your graphical elements.
• Shapes drawn using graphics functions can be outlined or filled with color. The
‘setcolor()’ functions allow you to set the color for your shapes. This adds a layer
of depth and visual appeal to your graphical elements.
Algorithm
• Initialize the graphics driver and mode.
• Create the train object. This could be a simple sprite, or a more complex
model.
• Create the track object. This could be a simple line, or a more complex model.
• Create a loop that will continuously update the animation.
• In the loop, move the train object along the track.
• Draw the train object and the track object to the screen.
• Wait for a short period of time.
• Repeat steps 5-7 until the animation is complete.
Coding
#include<stdio.h>
#include<conio.h>
#include<graphics.h> Library
#include<stdlib.h>
#include<dos.h>
void main()
{
int i;
int gd= DETECT, gm;
initgraph(&gd, &gm, “c:\\tc\\bgi”;

for(i=0; i<640; i++)


{
cleardevice();
//track
setcolor(7);
(Continue…)
Coding
line(0,450,640,450);
line(0,440,640,440);

//black box
setcolor(11);
rectangle(30+i, 340, 180+i, 350);
rectangle(40+i, 350, 170+i, 425);

//back wheels
setcolor(9);
circle(70+i, 437,12);
circle(140+i, 437,12);

(Continue…)
Coding
//back incircle
setcolor(10);
circle(70+i, 437,8);
circle(140+i, 437,8);
rectangle(70+i, 435, 140+i, 439);

//back window
setcolor(14);
rectangle(55+i, 365, 155+i, 400);
line(83+i, 365, 83+i, 400);
line(122+i, 365, 122+i, 400);

//joint
setcolor(13);
rectangle(170+i, 400, 210+i, 390);
(Continue…)
Coding
//engine
setcolor(10);
rectangle(200+i, 320, 260+i, 330);
rectangle(210+i, 330, 250+i, 400);
rectangle(250+i, 340, 345+i, 425);
rectangle(250+i, 340, 330+i, 410);

//front wheels
setcolor(9);
circle(225+i, 425, 25);
circle(320+i, 437, 12);
circle(280+i, 437, 12);

//front small incircle


setcolor(11);
circle(320+i, 437, 8);
(Continue…)
Coding
circle(280+i, 437,8);
rectangle(320+i, 435, 280+i, 439);

//front big incircle


setcolor(13);
circle(225+i, 425, 15);

//front windows
setcolor(11);
rectangle(220+i, 335, 240+i, 365);

//fire
setcolor(9);
rectangle(300+i, 300, 330+i, 340);
rectangle(290+i, 290, 340+i, 300);
(Continue…)
Coding

//light
setcolor(12);
rectangle(345+i, 360, 355+i, 380);

delay(20);
}
getch();
closegraph();
}
Common Challenges
• Smooth Animation: Achieving smooth animation requires precise timing and
control. Ensuring that the train moves seamlessly without jitter or abrupt transitions
is a common challenge.
• Coordinate System Accuracy: maintaining accuracy in the placement of shapes
within the coordinate system becomes crucial. Small errors can lead to misalignment
and distort the visual representation.
• Compatibility: Traditional graphics libraries like ‘graphic.h’ may face compatibility
issues with modern development environments. Exploring alternative libraries or
adapting your code may be necessary.
• Adding Details: Enhancing your train with details like windows, smoke, and
additional elements can be challenging. Balancing realism with performance is a
delicate task.

You might also like