Skip to content

Commit

Permalink
feat: added source
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakezaf committed Dec 20, 2019
1 parent 306df29 commit a59efd2
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
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!
128 changes: 128 additions & 0 deletions christmas_tree.c
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;
}

0 comments on commit a59efd2

Please sign in to comment.