1 Attachment(s)
Making html shapes with C
So basically I have to write a C program that, when opening the html file in a browser, looks essentially like this:
Attachment 13717
(Size, position, color of the shapes doesn't matter so long as I have one of each shape and the box surrounding them. Words up top dont matter either.)
This is what I have so far:
Code:
#include <stdio.h>
#include <stdlib.h>
#define FILENAME ("A4P1.html")
void circle(FILE* ofp){
int cx, cy, r, red, g, b;
float a;
cx = 150;
cy = 80;
r = 90;
red = 225;
g = 69;
b = 133;
a = 1.0;
fprintf(ofp, "\t\t\t<circle cx=\"%d\" cy=\"%d\" r=\"%d\" fill=\"rgba(%d,%d,%d,%0.1f)\"?>\n", cx, cy, r, red, g, b, a);
}
void square(FILE* ofp){
int x, y, width, height, r, g, b;
float a;
x = 50;
y = 150;
width = 100;
height = 100;
r = 0;
g = 225;
b = 225;
a = 0.8;
fprintf(ofp, "\t\t\t<square x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"rgba(%d,%d,%d,%0.1f)\"?>\n", x, y, width, height, r, g, b, a);
}
void ellipse(FILE* ofp){
int cx, cy, rx, ry, r, g, b;
float a;
cx = 200;
cy = 100;
rx = 175;
ry = 75;
r = 0;
g = 0;
b = 255;
a = 0.6;
fprintf(ofp, "\t\t\t<ellipse cx=\"%d\" cy=\"%d\" rx=\"%d\" ry=\"%d\" fill=\"rgba(%d,%d,%d,%0.1f)\"?>\n", cx, cy, rx, ry, r, g, b, a);
}
void box(FILE* ofp){
int x, y, width, height, r, g, b;
float a;
x = 0;
y = 0;
width = 500;
height = 300;
r = 255;
g = 51;
b = 153;
a = 1.0;
fprintf(ofp, "\t\t\t<box x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"rgba(%d,%d,%d,%0.1f)\"?>\n", x, y, width, height, r, g, b, a);
}
void rect(FILE* ofp){
int x, y, width, height, r, g, b;
float a;
x = 200;
y = 200;
width = 300;
height = 75;
r = 255;
g = 0;
b = 0;
a = 1.0;
fprintf(ofp, "\t\t\t<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"rgba(%d,%d,%d,%0.1f)\"?>\n", x, y, width, height, r, g, b, a);
}
int main(void) {
FILE* ofp = NULL;
printf("We are about to create a file called %s for writing into it\n", FILENAME);
ofp = fopen(FILENAME, "w");
if (ofp == NULL) {
printf("Cannot open output file %s\n", FILENAME);
exit(EXIT_FAILURE); // exit() is defined in <stdlib.h>
} /* if */
printf("We created the file %s successfully for writing\n", FILENAME);
fprintf(ofp, "<!DOCTYPE html>\n");
fprintf(ofp, "<html>\n");
fprintf(ofp, "\t<head>\n");
fprintf(ofp, "\t\t<title>A4P1.html</title>\n");
fprintf(ofp, "\t</head>\n");
fprintf(ofp, "\t<body>\n");
fprintf(ofp, "\t\t<p>Happy Thanksgiving!</p>\n");
fprintf(ofp, "\t\t<svg width=\"500\" height=\"300\">n");
fprintf(ofp, "\t\t\t<defs>\n");
fprintf(ofp, "\t\t\t\t<clipPath id=\"myframe\">\n");
fprintf(ofp, "\t\t\t\t<rect x=\"0\" y=\"0\" width=\"500\" height=\"300\">\n");
fprintf(ofp, "\t\t\t\t</clipPath>\n");
fprintf(ofp, "\t\t\t</defs>\n");
box(ofp);
rect(ofp);
circle(ofp);
ellipse(ofp);
square(ofp);
fprintf(ofp, "\t\t</svg>\n");
fprintf(ofp, "\t</body>\n");
fprintf(ofp, "</html>\n");
printf("We wrote HTML5 code into the file %s successfully\n", FILENAME);
fclose(ofp);
printf("We closed the file %s successfully\n", FILENAME);
return EXIT_SUCCESS;
} /*main*/
Anyways i can get the individual shapes, but I don't know how to get all the shapes to appear at once...
I also can't get the box thing to work...
Any help would be appreciated! :)