Skip to content
43 changes: 43 additions & 0 deletions src/OtherWebSources/Digital Clock/DigitalClock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <graphics.h>
#include <time.h>
#include <dos.h>
#include <string.h>

int main()
{
int gd = DETECT, gm;
int midx, midy;
long current_time;
char timeStr[256];

initgraph(&gd, &gm, "C:\\TC\\BGI");

/* mid pixel in horizontal and vertical axis */
midx = getmaxx() / 2;
midy = getmaxy() / 2;

while (!kbhit())
{
cleardevice();
setcolor(WHITE);
setfillstyle(SOLID_FILL, WHITE);
rectangle(midx - 250, midy - 40, midx + 250, midy + 40);
floodfill(midx, midy, WHITE);
/* Get Current epoch time in seconds */
current_time = time(NULL);
/* store the date and time in string */
strcpy(timeStr, ctime(&current_time));
setcolor(GREEN);
settextjustify(CENTER_TEXT, CENTER_TEXT);
settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 4);

moveto(midx, midy);
/* print current time */
outtext(timeStr);
/* Add delay of 1000 milliseconds(1 second) */
delay(1000);
}

closegraph();
return 0;
}
12 changes: 12 additions & 0 deletions src/OtherWebSources/Digital Clock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Digital Clock

[C Program to Make a Digital Clock Using C Graphics](https://www.techcrashcourse.com/2015/08/c-program-make-digital-clock-using-graphics.html)

Here is a C graphics program to make a digital clock using graphics.h header file. In this program, we will make a digital clock that print current Day, Month, Year and Date on screen inside a rectangular box. We will use below mentioned graphics functions in this program. Here, we are using time function of time.h header file to get the current epoch time(epoch time is number of seconds since 1 January 1970, UTC).

We convert epoch time to string representing the localtime in "www mmm dd hh:mm:ss yyyy" format, where www is the weekday, mmm is the month in letters, dd is the day of the month, hh:mm:ss is the time, and yyyy is the year. After printing current date and time on screen, it waits for 1000 milliseconds(1 second) before printing it again on screen.

## Output


![digital_clock](https://user-images.githubusercontent.com/46064269/235937757-35b7523f-86f6-4b65-b933-3d252d056604.gif)
47 changes: 47 additions & 0 deletions src/OtherWebSources/Digital Counter/DigitalCounter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <stdio.h>
#include <graphics.h>
#include <string.h>
#include <dos.h>

int main()
{
int gd = DETECT, gm;
int i, midx, midy, count;
char string[100];
printf("Enter a Number\n");
scanf("%d", &count);
initgraph(&gd, &gm, "X:\\TC\\BGI");

/* get mid positions in x and y-axis */
midx = getmaxx() / 2;
midy = getmaxy() / 2;

for (i = 0; i <= count; i++)
{
/* draws the gray board */
setcolor(WHITE);
setfillstyle(SOLID_FILL, WHITE);
rectangle(midx - 50, midy - 50, midx + 50, midy + 50);
floodfill(midx, midy, WHITE);

/* place the counter inside rectangle */
setcolor(BLUE);
sprintf(string, "%s", "Counter");
settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 5);
settextjustify(CENTER_TEXT, CENTER_TEXT);
outtextxy(midx, midy - 100, "Counter");

/* print the counter value */
sprintf(string, "%d", i);
outtextxy(midx, midy, string);

/* delay for a second(1000 milli second) */
delay(1000);

/* clears screen */
cleardevice();
}

closegraph();
return 0;
}
14 changes: 14 additions & 0 deletions src/OtherWebSources/Digital Counter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Digital Counter

[C Program to Make a Counter Using C Graphics](https://www.techcrashcourse.com/2015/08/c-program-make-digital-counter-graphics.html)

Here is a C graphics program to make a digital counter using graphics.h header file. In this program, we will make a digital counter that counts from 1 to N in interval of 1 seconds(1000 milliseconds). We will use below mentioned graphics functions in this program.

## Output

```bash
Enter a Number
5
```

![digital_counter](https://user-images.githubusercontent.com/46064269/235934686-1170ce99-e4a9-4f76-9eff-f0f1b458e136.gif)
28 changes: 28 additions & 0 deletions src/OtherWebSources/Night Sky copy/NightSky.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <graphics.h>
#include <dos.h>
#include <stdlib.h>

int main()
{
int gd = DETECT, gm;
int i, x, y;
initgraph(&gd, &gm, "C:\\TC\\BGI");

while (!kbhit())
{
/* color 500 random pixels on screen */
for (i = 0; i <= 500; i++)
{
x = rand() % getmaxx();
y = rand() % getmaxy();
putpixel(x, y, 15);
}
delay(500);

/* clears screen */
cleardevice();
}

closegraph();
return 0;
}
11 changes: 11 additions & 0 deletions src/OtherWebSources/Night Sky copy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Twinkling Night Sky Animation

[C Program to Draw Stars in Night Sky Using C Graphics](https://www.techcrashcourse.com/2015/08/c-program-draw-stars-in-night-sky-graphics.html)

Here is the C program to draw stars in night sky using graphics.h header file. In this program, we will randomly select 500 pixels on screen and color them in while. We will use putpixel functions of graphics.h header file to color a pixel at (x, y).

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 randomly select any (x, y) coordinate using rand, getmaxx and getmaxy function and color it using putpixel function. After 500 milliseconds we will clear screen and again paint the screen with stars until presses any key.

## Output

![twinkling_night_star](https://user-images.githubusercontent.com/46064269/235843126-5f61890c-9f41-473c-926a-8c1048250b45.gif)
28 changes: 28 additions & 0 deletions src/OtherWebSources/Night Sky/NightSky.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <graphics.h>
#include <dos.h>
#include <stdlib.h>

int main()
{
int gd = DETECT, gm;
int i, x, y;
initgraph(&gd, &gm, "C:\\TC\\BGI");

while (!kbhit())
{
/* color 500 random pixels on screen */
for (i = 0; i <= 500; i++)
{
x = rand() % getmaxx();
y = rand() % getmaxy();
putpixel(x, y, 15);
}
delay(500);

/* clears screen */
cleardevice();
}

closegraph();
return 0;
}
11 changes: 11 additions & 0 deletions src/OtherWebSources/Night Sky/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Twinkling Night Sky Animation

[C Program to Draw Stars in Night Sky Using C Graphics](https://www.techcrashcourse.com/2015/08/c-program-draw-stars-in-night-sky-graphics.html)

Here is the C program to draw stars in night sky using graphics.h header file. In this program, we will randomly select 500 pixels on screen and color them in while. We will use putpixel functions of graphics.h header file to color a pixel at (x, y).

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 randomly select any (x, y) coordinate using rand, getmaxx and getmaxy function and color it using putpixel function. After 500 milliseconds we will clear screen and again paint the screen with stars until presses any key.

## Output

![twinkling_night_star](https://user-images.githubusercontent.com/46064269/235843126-5f61890c-9f41-473c-926a-8c1048250b45.gif)
20 changes: 20 additions & 0 deletions src/RoughWork/Circle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdio.h>
#include <graphics.h>

int main()
{
int gd = DETECT, gm;
int x, y, radius = 80;
initgraph(&gd, &gm, "C:\\TC\\BGI");
/* Initialize center of circle with center of screen */
x = getmaxx() / 2;
y = getmaxy() / 2;

outtextxy(x - 100, 50, "CIRCLE Using Graphics in C");
/* Draw circle on screen */
circle(x, y, radius);

getch();
closegraph();
return 0;
}
27 changes: 27 additions & 0 deletions src/RoughWork/ConcentricCircles.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <stdio.h>
#include <graphics.h>

int main()
{
int gd = DETECT, gm;
int x, y;
initgraph(&gd, &gm, "C:\\TC\\BGI");
/* Initialize center of circle with center of screen */
x = getmaxx() / 2;
y = getmaxy() / 2;

outtextxy(240, 50, "Concentric Circles");
/* Draw circles on screen */
setcolor(RED);
circle(x, y, 30);
setcolor(GREEN);
circle(x, y, 50);
setcolor(YELLOW);
circle(x, y, 70);
setcolor(BLUE);
circle(x, y, 90);

getch();
closegraph();
return 0;
}
20 changes: 20 additions & 0 deletions src/RoughWork/Eclipse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdio.h>
#include <graphics.h>

int main()
{
int gd = DETECT, gm;
int x, y;
initgraph(&gd, &gm, "X:\\TC\\BGI");
/* Initialize center of ellipse with center of screen */
x = getmaxx() / 2;
y = getmaxy() / 2;

outtextxy(x - 100, 50, "ELLIPSE Using Graphics in C");
/* Draw ellipse on screen */
ellipse(x, y, 0, 360, 120, 60);

getch();
closegraph();
return 0;
}
83 changes: 83 additions & 0 deletions src/RoughWork/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Rough Workbook for practice

## C Program to Draw a Circle Using C 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). It is the first step you need to do during graphics programming. Setting graphics driver as DETECT, means instructing the compiler to auto detect graphics driver. Here we are using getmaxx and getmaxy function to find the center coordinate of the screen.

| **Function** | **Description** |
|:------------:|:-----------------------------------------------------------------------------------------------------------------------|
| initgraph | It initializes the graphics system by loading the passed graphics driver then changing the system into graphics mode. |
| getmaxx | It returns the maximum X coordinate in current graphics mode and driver. |
| getmaxy | It returns the maximum Y coordinate in current graphics mode and driver. |
| outtextxy | It displays a string at a particular point (x,y) on screen. |
| circle | It draws a circle with radius r and centre at (x, y). |
| closegraph | It unloads the graphics drivers and sets the screen back to text mode. |

## Rectangle and Bar Using C Graphics

Here is a C program to draw a rectangle and a bar on screen using graphics.h header file. In this program, we will draw a rectangle and a bar on screen. We will use rectangle and bar functions of graphics.h header file to draw rectangle and bar on screen. Below is the detailed descriptions if these two functions.

- `void rectangle(int xTopLeft, int yTopLeft, int xBottomRight, int yBottomRight);` draws a rectangle on screen. It takes the coordinates of top left and bottom right corners.
- `void bar(int xTopLeft, int yTopLeft, int xBottomRight, int yBottomRight);` draws a rectangle and fill it with current fill pattern and color.

| **Function Argument** | **Description** |
|:---------------------:|:--------------------------------------|
| xTopLeft | X coordinate of top left corner. |
| yTopLeft | Y coordinate of top left corner. |
| xBottomRight | X coordinate of bottom right corner. |
| yBottomRight | Y coordinate of bottom right corner. |


## Eclipse

Here is a C program to draw an eclipse on screen using graphics.h header file. In this program, we will draw an eclipse on screen having centre at mid of the screen. We will use ellipse functions of graphics.h header file to draw eclipse on screen. Below is the detailed descriptions of ellipse function.

```cpp
void ellipse(int xCenter, int yCenter, int startAngle, int endAngle, int xRadius, int yRadius);
```

| **Function Argument** | **Description** |
|:---------------------:|:--------------------------------------------------------------------------------------------|
| xCenter | X coordinate of center of eclipse. |
| yCenter | Y coordinate of center of eclipse. |
| startAngle | Start angle of the eclipse arc. |
| endAngle | End angle of the eclipse arc. It will draw eclipse starting form startAngle till endAngle. |
| xRadius | Horizontal radius of the eclipse. |
| yRadius | Vertical radius of the eclipse. |

To draw a complete eclipse, we should pass start and end angle as 0 and 360 respectively.

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). First of all we will calculate the center co-ordinates of eclipse which is the center of screen bu calling getmaxx and getmaxy function. Then we draw full eclipse by calling ellipse function.

## Concentric Circles

Here is a C graphics program to draw concentric circle on screen using graphics.h header file. In this program, we will draw four circle on screen having centre at mid of the screen and radius 30, 50, 70 and 90 pixels. We will use outtextxy and circle functions of graphics.h header file. Below is the detailed descriptions of graphics functions used in this program.

| **Function** | **Description** |
|:------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| initgraph | It initializes the graphics system by loading the passed graphics driver then changing the system into graphics mode. |
| getmaxx | It returns the maximum X coordinate in current graphics mode and driver. |
| getmaxy | It returns the maximum Y coordinate in current graphics mode and driver. |
| outtextxy | It displays a string at a particular point (x,y) on screen. |
| circle | It draws a circle with radius r and centre at (x, y). |
| setcolor | It changes the current drawing colour. Default colour is white. Each color is assigned a number, like BLACK is 0 and RED is 4. Here we are using colour constants defined inside graphics.h header file. |
| closegraph | It unloads the graphics drivers and sets the screen back to text mode. |


## Output

### Circle

![image](https://user-images.githubusercontent.com/46064269/235942456-a9c7a040-e112-42e7-8658-d6a541d1247b.png)

## Rectangle & Solid Bar

![image](https://user-images.githubusercontent.com/46064269/235945640-5583538a-3cb8-4a01-9220-a6ce8a6253ff.png)

## Eclipse

![image](https://user-images.githubusercontent.com/46064269/235947542-e13292f8-99b8-4d9c-b2d1-39056bcc4149.png)

## Concentric Circles

![image](https://user-images.githubusercontent.com/46064269/235949434-eaa67784-db66-4647-964a-04237902b28c.png)
18 changes: 18 additions & 0 deletions src/RoughWork/RectangleSolidBar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdio.h>
#include <graphics.h>

int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TC\\BGI");

/* Draw rectangle on screen */
rectangle(150, 50, 400, 150);

/* Draw Bar on screen */
bar(150, 200, 400, 350);

getch();
closegraph();
return 0;
}