-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# Christmas-Tree | ||
|
||
A little C program made to draw a Christmas tree | ||
|
||
Merry Christmas everyone! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <time.h> | ||
#include <unistd.h> | ||
|
||
void clrscr() | ||
{ | ||
system("@cls||clear"); | ||
} | ||
|
||
void printRandLeaf() | ||
{ | ||
char leaftypes[5] = {'.', '*', '+', 'o', 'O'}; | ||
int temp = rand() % 4; | ||
|
||
// Giving preference to * | ||
if (temp == 1) | ||
printf("%c ", leaftypes[rand() % 5]); | ||
else | ||
printf("%c ", leaftypes[1]); | ||
} | ||
|
||
void printRandSpace() | ||
{ | ||
char spacetypes[3] = {' ', '*', '+'}; | ||
int temp = rand() % 10; | ||
|
||
// Giving preference to * | ||
if (temp == 1) | ||
printf("%c", spacetypes[rand() % 3]); | ||
else | ||
printf("%c", spacetypes[0]); | ||
} | ||
|
||
void triangle(int f, int n, int toth) | ||
{ | ||
int i, j, k = 2 * toth - 2; | ||
|
||
for (i = 0; i < f - 1; i++) | ||
k--; | ||
|
||
for (i = f - 1; i < n; i++) | ||
{ | ||
|
||
printf("*"); | ||
|
||
for (j = 0; j < k; j++) | ||
printRandSpace(); | ||
|
||
k = k - 1; | ||
|
||
for (j = 0; j <= i; j++) | ||
printRandLeaf(); | ||
|
||
for (j = 0; j < k + 1; j++) | ||
printRandSpace(); | ||
|
||
printf("*"); | ||
|
||
printf("\n"); | ||
} | ||
} | ||
|
||
void printTree(int h) | ||
{ | ||
int start = 1, stop = 0, diff = 3, i; | ||
|
||
for (i = 0; i < (h * 2) - 8; i++) | ||
printf(" "); | ||
|
||
printf("Merry Christmas!\n"); | ||
|
||
for (i = 0; i < (h * 4); i++) | ||
printf("*"); | ||
|
||
printf("\n"); | ||
|
||
while (stop < h + 1) | ||
{ | ||
stop = start + diff; | ||
triangle(start, stop, h); | ||
diff++; | ||
start = stop - 2; | ||
} | ||
} | ||
|
||
void printLog(int n) | ||
{ | ||
int i, j, k = 2 * n - 4; | ||
|
||
for (i = 1; i <= 4; i++) | ||
{ | ||
printf("*"); | ||
|
||
// space handler | ||
for (j = 0; j < k; j++) | ||
printRandSpace(); | ||
|
||
for (j = 1; j <= 6; j++) | ||
printf("#"); | ||
|
||
for (j = 0; j < k; j++) | ||
printRandSpace(); | ||
|
||
printf("*"); | ||
|
||
printf("\n"); | ||
} | ||
|
||
for (j = 0; j < (k * 2) + 8; j++) | ||
printf("*"); | ||
|
||
printf("\n"); | ||
} | ||
|
||
int main() | ||
{ | ||
srand(time(NULL)); | ||
int ht = 20; | ||
|
||
clrscr(); | ||
|
||
printTree(ht); | ||
|
||
printLog(ht); | ||
|
||
return 0; | ||
} |