Skip to content

Instantly share code, notes, and snippets.

@coldcue
Created April 9, 2015 18:56
Show Gist options
  • Save coldcue/967c0ff177da3f9e40c2 to your computer and use it in GitHub Desktop.
Save coldcue/967c0ff177da3f9e40c2 to your computer and use it in GitHub Desktop.
#include <stdio.h>
/* The struct of the rectangles */
typedef struct {
float x;
float y;
float width;
float height;
char* fill;
} rect;
/* The struct of the points */
typedef struct {
int x;
int y;
} point;
/* Definition of the rectangle types */
rect h_marker = {236, 22, 8, 7, "#E6E7E8"};
rect m_marker = {238, 26, 4, 3, "#939598"};
rect h_hand = {237, 115, 6, 150, "#007BC3"};
rect m_hand = {238, 55, 4, 220, "#00AEEF"};
rect s_hand = {239, 27.5, 2, 245, "#89BBE5"};
/* Definition of the numbers' coordinates */
point numbers[] = {{224,58},{128,83},{58,154},{40,251},{66,348},{136,418},{232,444},{327,418},{397,348},{423,250},{397,154},{327,83}};
/* Prints the header of the SVG file */
void addHeader()
{
printf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
printf("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
printf("<svg version=\"1.1\" id=\"base\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\"\n");
printf(" width=\"480px\" height=\"480px\" viewBox=\"0 0 480 480\" enable-background=\"new 0 0 480 480\" xml:space=\"preserve\">\n");
printf("<rect fill=\"#58595B\" width=\"480\" height=\"480\"/>\n");
printf("<circle fill=\"#414042\" stroke=\"#00AEEF\" stroke-width=\"5\" stroke-miterlimit=\"10\" cx=\"240\" cy=\"240\" r=\"220\"/>\n");
printf("<circle fill=\"none\" stroke=\"#00AEEF\" stroke-width=\"2\" stroke-miterlimit=\"10\" cx=\"240\" cy=\"240\" r=\"210\"/>\n");
printf("<circle fill=\"#A7A9AC\" cx=\"240\" cy=\"240\" r=\"10\"/>\n");
printf("<text transform=\"matrix(1 0 0 1 179 321)\" fill=\"#606161\" font-family=\"'ArialMT'\" font-size=\"24\">VIKCLOCK</text>\n");
printf("<text transform=\"matrix(1 0 0 1 196 343)\" fill=\"#6D6E71\" font-family=\"'ArialMT'\" font-size=\"12\">by Andrew Szell</text>\n");
}
/* Prints the footer */
void addFooter()
{
printf("</svg>");
}
/* Prints a rectangle */
void addRect(rect* obj, float rotation)
{
printf("<rect x=\"%.1f\" y=\"%.1f\" width=\"%.1f\" height=\"%.1f\" fill=\"%s\" ", obj->x, obj->y, obj->width, obj->height, obj->fill);
if(rotation != 0)
printf("transform=\"rotate(%.2f 240 240)\" ", rotation);
printf("/>\n");
}
/* Prints a number */
void addNumber(point* p, int n)
{
printf("<text transform=\"matrix(1 0 0 1 %d %d)\" fill=\"#D1D3D4\" font-family=\"'ArialMT'\" font-size=\"28\">%d</text>\n", p->x, p->y, n);
}
int main()
{
int hour, min, sec;
float a_hour, a_min, a_sec;
scanf("%d %d %d", &hour, &min, &sec);
/* Calculate the angle of the hands */
a_hour = (60*hour+min)/2;
a_min = 6*(min);
a_sec = 6*sec;
addHeader();
/* Generate the markers */
for(int i = 0; i<60; i++) {
if(i%5==0)
addRect(&h_marker, i*6);
else
addRect(&m_marker, i*6);
}
/* Generate the numbers */
for(int i = 0; i<12; i++)
addNumber(&numbers[11-i],i+1);
/* Generate the hands */
addRect(&h_hand,a_hour);
addRect(&m_hand,a_min);
addRect(&s_hand,a_sec);
addFooter();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment