Clock was the first C application our class had to make. This was where most of our time was spend through period 1 after we learned about CMS like Joomla & WordPress
Everyone started the clock by trying to print the current time on the screen. This was harder than we though, we could find a lot on google, but there seemed to be different ways to do it. But eventually I learned how to do it. When I was able to get the hours, minutes and seconds in seperate variables I went quite crazy by positioning them. Me not knowing better, I hardcoded everything and then proudly showed my clock to my teacher. It even had a few gimmicks like adding an alarm, colors and pointers. But my teacher then told me that I shouldn’t position stuff this way. There was plenty of time left to program this so he told me to look into cosinus & sinus to position everything.
This made me busy for quite a while. At the time I wasn’t even sure how cosinus & sinus would make a circle. So I learned about the cosinus & sinus on youtube. And eventually started to look for example coding. After a while I found a code which can give me the X coordinate and Y coordinate of one point in a circle. I have used this a for loop and eventually got this:
for (i = interval; i <= spread; i += interval){ result = cos (param * PI/180), result2 = sin (param *PI/180); x = result * r + midX, y = result2 * r + midY; //Midden is normaal x38,y10 if (y <= 0){y = y - 1;} xy.X = x; xy.Y = y / 1.5 + 5; SetConsoleCursorPosition(hOut, xy); printf("%d\n",i%spread + low); param += 30; }
Around the end of the period I showed my new clock to my teacher, he said it was better but I used the loop 2 times in the code, it would be nice if I could reduce that to one. I sadly couldn’t do that before the period ended. But I was still pretty proud having the only round clock of the class at that time, and use cosinus & sinus too. I recieved a 10 out of 10 from my teacher.