85
\$\begingroup\$

As you probably know, there is a war going on in Ukraine. I noticed that it seems nobody has posted a Ukrainian flag challenge yet, so I thought I'd do it myself in support of Ukraine.

The Challenge

Here is the flag: Flag of Ukraine

  • The flag is divided horizontally across the middle into two equally sized stripes.
  • Stripe colors: (0, 87, 183) or #0057B7 (blue, top) and (255, 215, 0) or #FFD700 (yellow, bottom).
  • Colors must be exact if possible, otherwise use the closest available blue and yellow.
  • The image can be saved to a file or piped raw to STDOUT in any common image file format, or it can be displayed in a window.
  • The image must be sized at a 3:2 ratio, and at least 78 by 52 pixels.
  • Alternatively, output a block of text at least 78 characters wide made of non-whitespace characters that depicts the flag, using ANSI color codes to color it. (Use standard blue and yellow.)
  • Built-in flag images, flag-drawing libraries, or horrendously upscaling the Ukrainian flag emoji are prohibited.

This is , so shortest code wins!

\$\endgroup\$
16
  • 1
    \$\begingroup\$ If the ANSI color code option is chosen, what aspect ratio should we assume each character has? \$\endgroup\$
    – Nitrodon
    Mar 19, 2022 at 16:38
  • 1
    \$\begingroup\$ @Nitrodon You may assume each character is a square. \$\endgroup\$
    – Ginger
    Mar 19, 2022 at 17:43
  • 2
    \$\begingroup\$ @des54321 It must be exact. \$\endgroup\$
    – Ginger
    Mar 19, 2022 at 18:53
  • 7
    \$\begingroup\$ Unless I'm misunderstanding the QBasic answer already posted, I think that answer has inexact colors due to limitations of the language, but it is certainly likely other ancient languages could also have too-limited color-spaces to display the correct colors \$\endgroup\$
    – des54321
    Mar 19, 2022 at 19:42
  • 3
    \$\begingroup\$ Related: codegolf.stackexchange.com/questions/230438/create-a-pride-flag \$\endgroup\$
    – tsh
    Mar 20, 2022 at 5:10

82 Answers 82

8
\$\begingroup\$

C (GCC), 78 bytes

main(i){puts("P6\n78 52\n255");for(;i<4057;)printf(i++<2029?"%cW\xb7":"\xff\xd7%c",0);}

Attempt This Online! (code in Base64)

Outputs a PPM image to STDOUT.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Good answer! For those wondering how to save the image, they can run the compiled binary and redirect the output to a file. For example: /home/user/compiledflag > /home/user.flag.ppm. \$\endgroup\$ Mar 22, 2022 at 15:45
  • 1
    \$\begingroup\$ And for those wondering how to view the image, PPM is a format supported by most *NIX image tools, such as GIMP or the default GNOME Image Viewer (and many other, these are the ones installed on my system). :) \$\endgroup\$
    – matteo_c
    Mar 22, 2022 at 16:13
  • \$\begingroup\$ -7 bytes \$\endgroup\$
    – ceilingcat
    Mar 27, 2022 at 17:46
8
\$\begingroup\$

C (gcc), 126 115 109 bytes

  • -6 thanks to ceilingcat
  • -6 thanks to AZTECCO
  • -3 by using gold which seems to work instead of #FFD700

Produces an XPM image. If there's another indexed colour format that is smaller to produce from C, I'd be very interested!

i;a(c){for(i=2730;i--;putchar(i%91?c:10));}f(){puts("! XPM2\n90 60 2 1\na c #0057B7\nb c gold");a(97);a(98);}

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Nice one! Some savings by using only putchar, please check if I didn't broken the dimensions \$\endgroup\$
    – AZTECCO
    Mar 21, 2022 at 21:10
  • \$\begingroup\$ 108 bytes \$\endgroup\$
    – gastropner
    May 4, 2022 at 20:57
8
\$\begingroup\$

JavaScript/HTML 117 112 102 100 98 bytes

c=c.getContext`2d`
f=k=>c.fillRect(0,(c.fillStyle=k)>c?33:0,99,33)
f`gold`,f`#0057b7`
<canvas id=c>

With continued help from @Samathingamajig and @pxeger's answer

  1. <canvas id=c> is invalid HTML when missing an end tag but at least Chromium-Edge and Firefox create the element anyway.

  2. c=c.getContext`2d` is using template literal syntax,


Slava Ukraini!

\$\endgroup\$
12
  • \$\begingroup\$ You can remove 2 bytes with <canvas id=c> \$\endgroup\$ Mar 21, 2022 at 15:16
  • \$\begingroup\$ Another 2 bytes removed with c=c.getContext`2d` \$\endgroup\$ Mar 21, 2022 at 15:31
  • \$\begingroup\$ Yet another 2 bytes removed with c.fillRect(0,y,78,26) \$\endgroup\$ Mar 21, 2022 at 15:37
  • 1
    \$\begingroup\$ Again another 2 bytes removed with f=k=>c.fillRect(0,(c.fillStyle=k)>'$'?33:0,99,33) \$\endgroup\$ Mar 22, 2022 at 2:09
  • 1
    \$\begingroup\$ Hoping to get it to be below 100 chars, but all my changes are either staying the same or increasing. \$\endgroup\$ Mar 22, 2022 at 2:40
8
\$\begingroup\$

Batch, 93 bytes

@for %%i in (44 103)do @for /l %%j in (1,1,12)do @set/p=␛[%%im%PATH:~,80%<nul
@set/p=␛[m<nul

Assumes a default 80×25 screen with a PATH variable of at least 80 characters (this is true on a default Windows 10 installation). The last line is to stop the prompt appearing in yellow which wouldn't be a line of at least 78 non-whitespace characters and would therefore be illegal.

Note that is used to represent the nonprintable `` (good luck copying and pasting that).

\$\endgroup\$
8
\$\begingroup\$

HTML, 73 bytes

<p style=aspect-ratio:3/2;background:linear-gradient(#0057B7+50%,gold+50%

Thanks to @pxeger for pointing out that you can remove the quotes and not close the tag.

\$\endgroup\$
1
  • \$\begingroup\$ -3 bytes with the usual HTML abuse: <p style=aspect-ratio:3/2;background:linear-gradient(#0057B7+50%,gold+50% \$\endgroup\$
    – pxeger
    Mar 22, 2022 at 16:57
7
\$\begingroup\$

Coding, 84 bytes

>p
(width:78px;border-top:26px solid #FFD700;border-bottom:26px solid #0057B7)@style

borrowing from the CSS answer.

\$\endgroup\$
1
7
\$\begingroup\$

PostScript, 191 bytes

Prints the flag starting at 1"x1"; 3"x2" in size. This is my first try at a PostScript submission, so it's probably not the smallest possible.

%!
/i{72 mul}def/c{255 div}def/b{newpath moveto 3 i 0 i rlineto 0 i 1 i rlineto -3 i 0 i rlineto closepath fill}def 0 87 c 183 c setrgbcolor 0 i 1 i b 1 215 c 0 setrgbcolor 0 i 0 i b showpage
\$\endgroup\$
7
\$\begingroup\$

Bash (+ Image Magick) 69 67 64 characters

The following command will output the required file on standard output (as a PNM picture) if Image Magick is installed. Since I had some issues with binary value 0 in both RGB color codes, I replaced it with 1 instead:

convert - -scale 78x52\! -<<<$'P6 1 2 255 \x01W\xb7\xff\xd7\x01'
\$\endgroup\$
2
  • \$\begingroup\$ See Digital Trauma's tip on using here-string to reduce the length. \$\endgroup\$
    – manatwork
    Mar 23, 2022 at 12:17
  • \$\begingroup\$ @manatwork Thank you, done! \$\endgroup\$ Mar 23, 2022 at 13:06
7
\$\begingroup\$

PaperScript, 80 bytes

R=Path.Rectangle
R(1,1,99,33).fillColor="#0057b7"
R(1,34,99,33).fillColor="gold"

Try it here!

\$\endgroup\$
7
\$\begingroup\$

Commodore 64 machine code, 36 33 31 bytes

Code

.C:c000  78          SEI
.C:c001  A9 80       LDA #$80
.C:c003  A0 97       LDY #$97
.C:c005  8D 11 D0    STA $D011
.C:c008  2C 11 D0    BIT $D011
.C:c00b  F0 FB       BEQ $C008
.C:c00d  2C 11 D0    BIT $D011
.C:c010  D0 FB       BNE $C00D
.C:c012  8C 20 D0    STY $D020
.C:c015  CC 12 D0    CPY $D012
.C:c018  D0 FB       BNE $C015
.C:c01a  CE 20 D0    DEC $D020
.C:c01d  D0 E9       BNE $C008
.c01f  
(C:$c01f) g c000

Output

Output

Edit 1: Found a way to reuse the stx$d020 without introducing flickering. Geometry change: +1 raster scan line of blue, -1 of yellow. Tweaked saturation and brightness settings on the virtual CRT to obtain nicer colors.

Edit 2: Got rid of one register and saved two bytes.

Edit 3: Edit 2 reintroduced the overscan flicker, argh! This is fixed now. Geometry change: another extra line of blue at the expense of a line of yellow. Ditched the virtual CRT tweak, this is the output with the external palette called "VICE".

\$\endgroup\$
6
  • \$\begingroup\$ colors look a bit bleached compared to the specification, but I assume that this is the closest a commodore 64 can do? \$\endgroup\$
    – des54321
    Apr 10, 2022 at 20:32
  • \$\begingroup\$ I really hope you have a working commodore 64 to run this on. \$\endgroup\$
    – user108721
    Apr 10, 2022 at 20:33
  • \$\begingroup\$ Yep. The emulator can use custom palettes tho. \$\endgroup\$ Apr 10, 2022 at 20:34
  • \$\begingroup\$ I don't have a working c64, sorry :/ \$\endgroup\$ Apr 10, 2022 at 20:34
  • \$\begingroup\$ fair enough, given how old it is theres a good chance a c64 doesnt even have a well-specified color pallete \$\endgroup\$
    – des54321
    Apr 10, 2022 at 20:38
7
\$\begingroup\$

Processing, 92 Bytes

void setup(){size(78,52);background(#0057B7);}void draw(){fill(#FFD700);rect(0,26,78,26);}

Output

Ukranian Flag

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to Code Golf, and nice answer! \$\endgroup\$ Jun 26, 2022 at 0:13
7
\$\begingroup\$

Nim + pixie, 139 bytes

import pixie
let
 i=78.newImage 52
 c=i.newContext
i.fill rgb(0,87,183)
c.fillStyle=rgb(255,215,0)
c.fillRect 0,26,78,26
i.writeFile"c.png"

Outputs to the file c.png.

enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ You can replace newImage(78,52) with 78.newImage 52. \$\endgroup\$
    – xigoi
    Mar 17, 2023 at 16:47
6
\$\begingroup\$

Windows PowerShell / PowerShell Core, 50 bytes

Only works in a PowerShell host.

,'blue'*9+,'yellow'*9|%{Write-Host('█'*78)-f $_}

Output (bit outdated because code was edited):

output

I also reposted this code in my GitHub Gist.

Try it online not available, because it cannot render colors (so none of the flag is shown for tio.run).

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Welcome to Code Golf, and nice answer. \$\endgroup\$ Mar 27, 2022 at 19:06
  • 1
    \$\begingroup\$ 50 bytes with non-whitespace characters. ,'blue'*9+,'yellow'*9|%{Write-Host('█'*78)-f $_}. Only works in a PowerShell host. \$\endgroup\$
    – mazzy
    Mar 28, 2022 at 6:36
6
\$\begingroup\$

PostScript, 55 43 bytes

00000000: 3188 0238 5b2e 3030 3288 0030 202d 2e30  1..8[.002..0 -.0
00000010: 3036 8800 325d 2800 57b7 ffd7 2992 a333  06..2](.W...)..3
00000020: 2063 6f6c 6f72 696d 6167 65               colorimage

Tokenized version of:

1 2 8[.002 0 0 -.006 0 2]<0057b7ffd7>stopped 3 colorimage

The original solution without binary tokens was a bit shorter at 55 bytes:

1 2 8[.002 0 0 -.006 0 2]<0057b7ffd7>false 3 colorimage

These all use a stretched a 1x2 bitmap. To view, run through Ghostscript. output

\$\endgroup\$
1
5
\$\begingroup\$

MSWLogo, I'm assuming 173 167 bytes.

to f :a :b :c :y
setpos(list 0 :y)
setpc(list :a :b :c)
repeat 2[fd 26 rt 90 fd 72 rt 90]
setpos(list 1 :y+1)
setfc(list :a :b :c)
fill
end
f 225 215 0 0 f 0 87 153 26

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ MSWLego? Didn't know they were doing code golf \$\endgroup\$
    – Ginger
    Mar 21, 2022 at 15:00
  • \$\begingroup\$ @Ginger lol. saw a Scratch answer and I just thought to myself: "Let's do this in Logo" \$\endgroup\$
    – badatgolf
    Mar 22, 2022 at 1:12
5
\$\begingroup\$

Dyalog APL,55 byte

(⊂'P3 78 52 255 ',⍕,⍉2028/(3⍴256)⊤22455 16766720)∘⎕NPUT

Write a plain text PPM image to provided filename.

Sample

$ cat out.ppm
P3 78 52 255 0 87 183 0 87 183 0 87 183 0 87 183 0 87 183 0 87 183 0 87
183 0 87 183 0 87 183 0 87 183 0 87 183 0 87 183 0 87 183 0 87 183 0 87
...
183 0 87 183 0 87 183 0 87 183 0 87 183 0 87 183 0 87 183 0 87 183 0 87
183 0 87 183 255 215 0 255 215 0 255 215 0 255 215 0 255 215 0 255 215 0
255 215 0 255 215 0 255 215 0 255 215 0 255 215 0 255 215 0 255 215 0
255 215 0 255 215 0 255 215 0 255 215 0 255 215 0 255 215 0 255 215 0
...

\$\endgroup\$
5
\$\begingroup\$

C++, GCC 227216 chars

Hardly golf considering the language/tools, but still worth a try

#import<boost/gil/extension/io/pnm.hpp>
int n;int main(){boost::gil::rgb8_image_t i{999,666};for_each_pixel(view(i),[](auto&p){n++/999<333?p={0,87,183}:p={255,215,0};});write_view("U",view(i),boost::gil::pnm_tag{});}

It's not even obfuscated if reformatted:

#import <boost/gil/extension/io/pnm.hpp>
int n;
int main() {
    boost::gil::rgb8_image_t i{999, 666};
    for_each_pixel(view(i), [](auto& p) {
        n++ / 999 < 333 ? p = {0, 87, 183} : p = {255, 215, 0};
    });
    write_view("U", view(i), boost::gil::pnm_tag{});
}

The U file is in PNM format, meaning no link dependencies. Built with GCC-10 results in 19K binary.

Live On Compiler Explorer

Resulting file:

U: Netpbm image data, size = 999 x 666, rawbits, pixmap

enter image description here

\$\endgroup\$
2
  • 1
    \$\begingroup\$ 216 bytes \$\endgroup\$
    – gastropner
    May 4, 2022 at 21:34
  • \$\begingroup\$ @gastropner Hah. Who'dve-thunk that you can simply #import header files :) Also, nice with the ternary around the assignment expression. \$\endgroup\$
    – sehe
    May 4, 2022 at 21:54
5
\$\begingroup\$

Applesoft Basic, 88 bytes

1Y=0
2M=13
3GR
4COLOR=2
5HLIN0,38ATY
6Y=Y+1
7IFY<M GOTO5
8COLOR=13
9M=26
10Y=13
11GOTO5

Kind of cheating because it only is 39:26. I don't know if this is actually valid but it works here. A high res but worse color answer for 93 bytes:

1Y=0
2M=26
3HGR
4HCOLOR=6
5HPLOT0,Y TO78,Y
6Y=Y+1
7IFY<M GOTO5
8HCOLOR=5
9M=52
10Y=26
11GOTO5
\$\endgroup\$
5
\$\begingroup\$

Perl 5, 36 bytes

$#a=78;print".[${_}m@a
"x13for 44,43

Try it online!

Outputs using ANSI escape sequences.

\$\endgroup\$
4
  • \$\begingroup\$ For some reason, the link seems to show an 'L'-shaped flag with a long extension at the bottom right. Is this just a side-effect of the 'code sandbox'? \$\endgroup\$ May 11, 2022 at 12:58
  • \$\begingroup\$ @DominicvanEssen Yeah, it's a side effect of ANSI escape codes being used in a window that's not long enough for the content, the same happens in a local terminal if you're most of the way down. It's annoying. I did briefly look at auto-sizing STDOUT for code-sandbox, but it would need to be resized before the content makes it there... \$\endgroup\$ May 11, 2022 at 14:44
  • \$\begingroup\$ @DominicvanEssen Thanks for the nudge, I've just made a fix so that the xterm window will resize on input (not sure how quickly the cache is invalidated on GitHub pages, but thanks again for the prompt!) \$\endgroup\$ May 11, 2022 at 19:53
  • \$\begingroup\$ Works perfectly now. Nice one. \$\endgroup\$ May 11, 2022 at 20:50
5
\$\begingroup\$

ARM Thumb machine code, Game Boy Advance, 36 bytes

04 20 00 06 05 49 01 80 48 06 09 0c 44 18 04 4a
13 0c 89 1e 42 52 63 52 fb d1 fe e7 03 04 00 96
40 59 5f 03

Thumb function that runs at a 4 byte aligned address.

ok the colors are actually a bit darker due to the GBA's messed up gamma

Assembler source:

    .syntax unified
    .arch armv4t
    .globl ukraine
    .thumb
    .thumb_func
    // Runs at a 4 byte aligned address
    .p2align 2,0
ukraine:
    // 0x04000000 = REG_DISPCNT
    movs    r0, #0x04
    lsls    r0, r0, #24
    // Load packed halfword constants
    ldr     r1, consts
    // REG_DISPCNT = MODE_3 | BG2_ENABLE
    // Set to display mode 3, enable BG2 layer
    strh    r1, [r0]
    // r0 = 0x...0403 << 25 = 0x06000000 = VRAM address
    lsls    r0, r1, #25
    // Shift in loop counter/offset (0x9600)
    lsrs    r1, r1, #16
    // r4 = 0x06009600 = second half of screen
    adds    r4, r0, r1
    // Load packed colors
    ldr     r2, colors
    // Unpack
    lsrs    r3, r2, #16
    // Double memset16 loop
.Lloop:
    // Decrement counter, set flags
    subs    r1, r1, #2
    // Store blue
    strh    r2, [r0, r1]
    // Store yellow
    strh    r3, [r4, r1]
    // Loop while not 0
    bne     .Lloop
    // Idle spin
.Lspin:
    b       .Lspin

    .p2align 2,0
consts:
    // MODE_3 | BG2_ENABLE
    // Also used for vram address
    .hword  0x0403
    // Half of the screen in halfwords
    .hword  240 * (160 / 2) * 2

    // Converts r8, g8, b8 to RGB5
    .macro RGB8 r, g, b
        .hword  ((\r >> 3) << 0)  | ((\g >> 3) << 5) | ((\b >> 3) << 10)
    .endm

colors:
    RGB8    0, 87, 183   // blue
    RGB8    255, 215, 0  // yellow

This function switches the GBA to display mode 3, where VRAM is treated as a flat bitmap of 16-bit RGB5 pixels. This is the easiest to manipulate as there is no need for tilemaps or palettes, I can just fill VRAM with colors.

\$\endgroup\$
5
\$\begingroup\$

Game Boy Color assembly, 99 97 bytes

Must be placed at $0150, to which it is jumped from $0100 (standard Game Boy stuff).

0E 40 3C E0 41 E6 02 E0 FF 76 F2 CB BF E2 3E 80
E0 68 21 69 FF AF 36 60 36 59 77 77 77 77 36 5F
36 03 3E 40 06 02 21 00 98 CD AB 01 3E 20 06 00
CD AB 01 AF 57 04 CD AB 01 04 CD AB 01 3E 10 42
26 80 CD AB 01 3E 20 06 FF CD AB 01 3E 30 70 23
72 23 BD 20 F9 F2 CB FF E2 18 FE 70 23 BD 20 FB
C9

Disassembly:

ROMCode:
    ld c, $40
; first we turn off the LCD so the LCD doesn't tell our mother[board] that it's their turn to access the VRAM

; wait for LCD Status to be at vblank to avoid hardware damage
; removing this "saves" eight bytes
; this is also our non-CGB/GBA/SGB2 filter: those will hang, because the way their A register is initialized, this will put them in an endless halt
.vblankWait:
    inc a ; on CGB and compatible, A is initialized to $11. in fact, that is how software is supposed to detect CGB compatibility.
    ldh [$ff41], a
    and $02
    ldh [$ffff], a
    db $76 ; halt. saves byte over "halt", which auto-inserts nop
           ; if you do this in a project, beware the halt bug.

; turn off the LCD
    ldh a, [c]
    res 7, a
    ldh [c], a

; now we fill the palette.

; the palette ram is indirectly accessed using a control register with an address and auto-increment bit and a data register
    ld a, $80
    ldh [$ff68], a
    ld hl, $ff69
    xor a

    ld [hl], $60
    ld [hl], $59
rept 4
    ld [hl], a
endr
    ld [hl], $5f
    ld [hl], $03

; now we fill the tile map.
    ld a, $40
    ld b, 2
    ld hl, $9800
    call FillWithB

    ld a, $20
    ld b, 0
    call FillWithB

    xor a
    ld d, a ; for later
    inc b
    call FillWithB

    inc b
    call FillWithB

; and now we have tile 0 be all color 0b00, tile 1 be all color 0b11, and tile 2 be all color 0b10
    ld a, $10
    ld b, d
    ld h, $80
    call FillWithB
    
    ld a, $20
    ld b, $ff
    call FillWithB

    ld a, $30
.fillTwoValues:
    ld [hl], b
    inc hl
    ld [hl], d
    inc hl
    cp l
    jr nz, .fillTwoValues

; turn on the LCD
    ldh a, [c]
    set 7, a
    ldh [c], a

; and now that we're done let's spin.
    jr @

FillWithB:
    ld [hl], b
    inc hl
    cp l
    jr nz, FillWithB
    ret

demonstration on BGB

Game Boy Color colors are wonky. It's also 10:7, but that's close enough to 3:2.

Edit 1: Missed completing an optimization I had already partially done (ldh with [c]). -2 bytes.

Edit 2: More safe vblank wait code. No size change.

Edit 3: Edit 2 broke the second halt, which is now replaced with an infinite spin because fixing it requires more code. No size change, +1 embarrassment from not checking thoroughly enough.

\$\endgroup\$
4
\$\begingroup\$

Haskell, 83 81 69 bytes

My first haskell submission.

This code defines a function that prints the flag to stdout using ansi escape codes.

n?s=[1..n]>>s
putStr$"43">>= \c->13?(78?("\27[4"++c:"m \27[m")++"\n")

enter image description here

\$\endgroup\$
4
\$\begingroup\$

SVG, 132 bytes

<svg width="300"height="200"><rect width="300"height="100"fill="#0057b7"/><rect y="100"width="300"height="100"fill="#ffd700"/></svg>

\$\endgroup\$
4
\$\begingroup\$

WP2, 32 bytes

VWtsR1JpSUFBQUJYUlVKUVZsQTRUQlVBQUFBdlRjQU1BQkNRSkVQYjNUUmgvbWUzLzVuVUgvVUEK

WP2 (WebP2) is an image format based on AVIF. It's state-of-the-art in the field of DCT-based image formats, as far as I'm aware. It's also really good at lossless compression.

Encoded in Base64 RFC4648

\$\endgroup\$
4
\$\begingroup\$

Ruby + paint, 73 bytes

You do need the paint gem installed, from rubygems: gem install paint

Update:

Thanks to manatwork for the much shorter:

require'paint';['#0057b7','#ffd700'].map{|c|5.times{puts Paint[?█*37,c]}}

Original attempt (127 bytes):

require'paint';c=['#0057b7','#ffd700'];(0..1).each do |i|;(0..4).each do;(0..36).each do;print Paint['█',c[i]];end;puts;end;end

console output of Ukrainian flag from code.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Nice try, but not really matches the goal of code-golf challenges. May I suggest the mostly equivalent require'paint';['#0057b7','#ffd700'].map{|c|5.times{puts Paint[?█*37,c]}}? \$\endgroup\$
    – manatwork
    Sep 25, 2022 at 12:14
  • \$\begingroup\$ Thanks @manatwork! I haven't used Ruby in a bit, but that's much shorter. \$\endgroup\$ Sep 25, 2022 at 18:26
  • 1
    \$\begingroup\$ You can use a word array to save 2 bytes require'paint';%w(#0057b7 #ffd700).map{|c|5.times{puts Paint[?█*37,c]}} \$\endgroup\$
    – south
    Oct 4, 2022 at 23:31
4
\$\begingroup\$

Lua + LÖVE, 154 characters

l=love
g=l.graphics
c=255
l.window.setMode(78,52)function l.draw()g.setBackgroundColor(0,87/c,183/c)g.setColor(1,215/c,0)g.rectangle("fill",0,26,78,52)end

Sample output:

flag of Ukraina

\$\endgroup\$
4
\$\begingroup\$

C# (.NET), 178 chars

Effective code

var f=new Bitmap(78,52);for(int y=0;y<52;y++)for(int x=0;x<78;x++)if(y>25)f.SetPixel(x,y,Color.FromArgb(255,215,0));else f.SetPixel(x,y,Color.FromArgb(0,87,183));f.Save("f.bmp");

Readable version

using System.Drawing;
namespace UkrainianFlag
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //The effective code could replace the code in this method.

            var blue = Color.FromArgb(0, 87, 183);
            var yellow = Color.FromArgb(255, 215, 0);

            //Create the image holding the flag.
            var flag = new Bitmap(78, 52);

            //Iterate the pixels, row by row.
            for (int y = 0; y < flag.Height; y++)
            {
                for (int x = 0; x < flag.Width; x++)
                {
                    if (y >= flag.Height / 2)
                    {
                        flag.SetPixel(x, y, blue);
                    }
                    else
                    {
                        flag.SetPixel(x, y, yellow);
                    }
                }
            }

            //Store the flag image next to the exe-file.
            flag.Save("flag.bmp");
        }
    }
}

Output

Example file of program output.

\$\endgroup\$
2
  • 3
    \$\begingroup\$ Welcome to Code Golf, and nice answer! \$\endgroup\$ Apr 12, 2022 at 18:18
  • \$\begingroup\$ var f=new Bitmap(78,52);for(int i=0;i<4056;i++)f.SetPixel(i%78,i/78,i>1950?Color.FromArgb(255,215,0):Color.FromArgb(0,87,183));f.Save("f.bmp"); \$\endgroup\$
    – jdt
    Dec 29, 2022 at 15:05
4
\$\begingroup\$

Go, 280 272 269 bytes

import(."image";c"image/color";d"image/draw";p"image/png";."os")
func f(){N,O,a,b:=NewUniform,d.Src,Rect,d.Draw
F:=NewRGBA(a(0,0,78,52))
b(F,a(0,0,78,26),N(c.RGBA{0,87,183,255}),Point{0,0},O)
b(F,a(0,26,78,52),N(c.RGBA{255,215,0,255}),Point{0,26},O)
p.Encode(Stdout,F)}

Attempt This Online!

Apparently Go has a (basic) image processing package in the standard library.

Prints the bytes of a 78-by-52px PNG to STDOUT.

Changelog

  • -12 bytes by @The Thonnu

Explanation

import(."image";c"image/color";d"image/draw";p"image/png";."os")
func f(){                                     // boilerplate
B,Y,N,O:=c.RGBA{0,87,183,255},c.RGBA{255,215,0,255},NewUniform,d.Src
// define some useful variables
// - B and Y are RGBA colors
// - d.Src is how the image will be drawn on: Src replaces the pixels of the image with the source image.
F:=NewRGBA(Rect(0,0,78,52))                   // make a new empty RGBA image
d.Draw(F,Rect(0,0,78,26),N(B),Point{0,0},O)   // draw blue on the top half the image
d.Draw(F,Rect(0,26,78,52),N(Y),Point{0,26},O) // draw yellow on the bottom half of the image
p.Encode(Stdout,F)}                           // encode it as a PNG, and send it to STDOUT
\$\endgroup\$
3
4
\$\begingroup\$

Nibbles, 26.5 bytes (53 nibbles)

"P3 78 52 255 ".\`\~`D256^2028$ FFD7000057B7

Outputs a plain PPM file of 78x52 pixels, depicting the Ukrainian flag using exact colours.

"P3 78 52 255 "         # prepend the string "P3 78 52 255 " onto:
     `D256              # extract data in base 256,
  `\~                   # and divide into 2 chunks,
 \                      # reverse them,
.                       # and map over each
          ^2028$        # repeating it 2028 times. 
FFD7000057B7            # The data.

enter image description here enter image description here

\$\endgroup\$
4
\$\begingroup\$

Octave, 55 bytes

imagesc([5 5 5;4 4 4],climits=[3,5])
colormap(prism(5))

image

My first time posting in Octave! There might be a way to display without having to use climits, or maybe even without changing the default colormap, but I have not found it yet.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.