C (gcc), 280 278 277 275 268 265 bytes
(Non-printables are in hex)
#define r(s...)printf(R"X(<rect x="%d" y="%d" transform="rotate(%d,%1$d,%2$d)" width="%d" height="9" fill="#%x"/>)X",s,63,90,34,c)
c=0xbcbbbb,*p=L"b4P=\n313191f1b(\r(2007";main(){r(!r(9),88,!puts("<svg>"),78,c);for(r(78);*p;)r(*p++,*p++,*p++,44,0xf48024);puts("</svg>");}
Try it online!
- -2 bytes by using 180 degree rotation, using
*p++
, and reordering the LUT for GCC's reverse ordering.
- -1 byte for blatant
for
loop optimization 🤦
- -2 bytes for abusing the return value of
printf
and puts
for 0
- -7 bytes using C++-style raw literals thanks to p1131
- -3 bytes abusing vararg macros thanks again to p1131
I beat Python, I feel somewhat accomplished. Edit: said words now taste salty.
With macros expanded and commented
// LUT is encoded as a raw wide string literal
// expanded
LUT[] =
// Rot, y, x
180, 80, 61, // first is upside down to avoid an inconvenient null byte
10, 51, 19,
25, 31, 27,
40, 13, 40,
50, 0, 55,
0 // implicit null terminator
};
c = 0xbcbbbb, *p = L"...";
main()
{
// Note that GCC evaluates function parameters
// from right to left, so these are bottom line up 😖
printf(
// GCC supports raw string literals in C mode
// We use this to avoid \"
R"X(<rect x="%d" y="%d" transform="rotate(%d,%1$d,%2$d)" width="%d" height="9" fill="#%x"/>)X",
// !printf == 0 for non-empty strings
// x = 0
// Called second
!printf(
"<rect ...>",
9, // x
63, // y
90, // rot
34, // width
c // color
),
88, // y
// Called first
// rot = 0
!puts("<svg>"),
78, // width
c, // Color
// garbage arguments left in that printf doesn't use
63, 90, 34, c
);
// Loop through our LUT for the 5 orange bars
for (
// Typical printf optimization
printf("<rect ...>", 78, 63, 90, 34, c);
// loop until null terminator
*p;
)
// More eval order abuse
printf(
"<rect ...>",
*p++, // x = p[2]
*p++, // y = p[1]
*p++, // rot = p[0]
44, // width
0xf48024, // color
63, 90, 34, c // garbage
);
// Closing tag
puts("</svg>");
}
Ungolfed: (different order, but clean)
#include <stdio.h>
// Note that macro compression is used to save a few bytes.
// Color constants
static const int GRAY = 0xbcbbbb;
static const int ORANGE = 0xf48024;
// encoded raw as a string in the golfed code
static const int LUT[] = {
// x, y, rotation
17, 71, 0,
19, 51, 10,
27, 31, 25,
40, 13, 40,
55, 0, 50,
0 // null terminate
};
// golfed version uses a macro
static void rect(
int x,
int y,
int width,
int color,
int rotation
)
{
// This could definitely be golfed better if I figure out the arithmetic for positioning
printf("<rect "
"x=\"%d\" "
"y=\"%d\" "
"width=\"%d\" "
"height=\"9\" "
"fill=\"#%x\" "
// rotate at top left corner
"transform=\"rotate(%d,%1$d,%2$d)\""
"/>", x, y, width, color, rotation);
}
int main(void)
{
// Print SVG header
puts("<svg>");
// Loop through all 5 lines
for (const int *ptr = LUT; *ptr != 0; ptr += 3) {
rect(/*x*/ ptr[0], /*y*/ ptr[1], /*width*/ 44, /*color*/ ORANGE, /*rotation*/ ptr[2]);
}
// Output the box
rect(/*x*/ 9, /*y*/ 63, /*width*/ 34, /*color*/ GRAY, /*rotation*/ 90);
rect(/*x*/ 0, /*y*/ 88, /*width*/ 78, /*color*/ GRAY, /*rotation*/ 0);
rect(/*x*/ 78, /*y*/ 63, /*width*/ 34, /*color*/ GRAY, /*rotation*/ 90);
// Output closing SVG tag
puts("</svg>");
}
This outputs the following SVG file to standard output when run (whitespace added to make it readable):
<svg>
<rect x="9" y="63" transform="rotate(90,9,63)" width="34" height="9" fill="#bcbbbb"/>
<rect x="0" y="88" transform="rotate(0,0,88)" width="78" height="9" fill="#bcbbbb"/>
<rect x="78" y="63" transform="rotate(90,78,63)" width="34" height="9" fill="#bcbbbb"/>
<rect x="61" y="80" transform="rotate(180,61,80)" width="44" height="9" fill="#f48024"/>
<rect x="19" y="51" transform="rotate(10,19,51)" width="44" height="9" fill="#f48024"/>
<rect x="27" y="31" transform="rotate(25,27,31)" width="44" height="9" fill="#f48024"/>
<rect x="40" y="13" transform="rotate(40,40,13)" width="44" height="9" fill="#f48024"/>
<rect x="55" y="0" transform="rotate(50,55,0)" width="44" height="9" fill="#f48024"/>
</svg>
Stack snippet containing raw output:
<svg>
<rect x="9" y="63" transform="rotate(90,9,63)" width="34" height="9" fill="#bcbbbb"/><rect x="0" y="88" transform="rotate(0,0,88)" width="78" height="9" fill="#bcbbbb"/><rect x="78" y="63" transform="rotate(90,78,63)" width="34" height="9" fill="#bcbbbb"/><rect x="61" y="80" transform="rotate(180,61,80)" width="44" height="9" fill="#f48024"/><rect x="19" y="51" transform="rotate(10,19,51)" width="44" height="9" fill="#f48024"/><rect x="27" y="31" transform="rotate(25,27,31)" width="44" height="9" fill="#f48024"/><rect x="40" y="13" transform="rotate(40,40,13)" width="44" height="9" fill="#f48024"/><rect x="55" y="0" transform="rotate(50,55,0)" width="44" height="9" fill="#f48024"/></svg>
C (gcc), boring semi-cheating version, 236 231 bytes
main(){puts(R"(<svg><path fill="#bcbbbb" d="M9 63v25H0V63zM0 88h78v9H0zm78-25v25h-9V63z"/><path fill="#f48024" d="M61 80H17v-9h44zM19 51l43 8-1 9-44-8zm8-20l40 19-4 8-40-19zm13-18l34 28-6 7-34-28zM55 0l28 34-7 5L48 6z"/></svg>)");}
Try it online!
-5 bytes for using raw string literals as well.
This is literally just SVGOMG on the lowest setting, so I don't take credit for it. I can't even tell what it is doing.
It does have much lower precision, though.
<svg>
<path fill="#bcbbbb" d="M9 63v25H0V63zM0 88h78v9H0zm78-25v25h-9V63z"/>
<path fill="#f48024" d="M61 80H17v-9h44zM19 51l43 8-1 9-44-8zm8-20l40 19-4 8-40-19zm13-18l34 28-6 7-34-28zM55 0l28 34-7 5L48 6z"/>
</svg>
<svg><path fill="#bcbbbb" d="M9 63v25H0V63zM0 88h78v9H0zm78-25v25h-9V63z"/><path fill="#f48024" d="M61 80H17v-9h44zM19 51l43 8-1 9-44-8zm8-20l40 19-4 8-40-19zm13-18l34 28-6 7-34-28zM55 0l28 34-7 5L48 6z"/></svg>