Here is a C graphics program to draw tan graph using graphics.h header file. In this program, we will draw tangent graph on screen. We will use putpixel functions of graphics.h header file to color a pixel at (x, y).
C program to draw tan graph using graphics
In this program, we first initialize graphics mode, by passing graphics driver(DETECT), default graphics mode and specifies the directory path where initgraph looks for graphics drivers (*.BGI). Then we will draw a horizontal axis using line function representing the angle in radians. Inside a for loop we calculate the value of tangent for an angle and color the specific pixel using putpixel function. At last we increment the angle by 2.
#include <math.h> #include <graphics.h> #include <dos.h> int main() { int gd = DETECT, gm; int angle = 0; double x, y; initgraph(&gd, &gm, "C:\\TC\\BGI"); line(0, getmaxy() / 2, getmaxx(), getmaxy() / 2); /* generate a sine wave */ for(x = 0; x < getmaxx(); x++) { /* calculate y value given x */ y = 50*tan(angle*3.141/180); y = getmaxy()/2 - y; /* color a pixel at the given position */ putpixel(x, y, 15); delay(50); /* increment angle */ angle+=2; } closegraph(); return 0; }Program Output
Conclusion
In concluding this tutorial, you've embarked on a journey through the captivating realm of graphics programming, specifically creating a tangent graph using Turbo C. By blending mathematical functions with creative expression, you've witnessed the seamless synergy between precision and visual representation. Turbo C, with its nostalgic appeal, served as an ideal canvas for honing fundamental graphics concepts, offering a timeless gateway for programmers into the world of graphical creativity.
As you reflect on the skills acquired in this tutorial, consider the broader implications of graphics programming. The ability to dynamically visualize mathematical functions not only enriches your understanding of the subject but also lays the foundation for more complex graphical endeavors. Turbo C, though vintage, has proven its enduring value as a tool for sparking creativity and curiosity.
Moving forward, expand upon this project by exploring diverse mathematical functions, introducing interactivity, or delving into more intricate graphical representations. Graphics programming is an ever-evolving field, and Turbo C provides a solid foundation upon which you can build your skills.
The beauty of graphics programming lies not just in the lines of code but in the boundless possibilities it opens. Turbo C, a steadfast companion for generations of programmers, continues to inspire creative endeavors. Embrace the skills cultivated in this tutorial, let your imagination soar, and continue exploring the limitless avenues that graphics programming unfolds. Whether you're visualizing mathematical concepts, designing simulations, or crafting interactive applications, Turbo C graphics offers a timeless backdrop for your creative coding pursuits.
Related Topics