81
\$\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\$
15
  • 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

72 Answers 72

1 2
3
2
\$\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\$
1
\$\begingroup\$

Ly, 39 bytes

99*:3*&s*:[r009r,]+[r990r,]+'Po9lf2*f3r

Try it online!

This code pushes RGB values compatible with PPM ASCII formatted image into the stack, then creates a minimum PPM header before exiting. The numbers on the stack are printed automatically when the code exits.

Generate width/height numbers, figure out "half the pixels" count

 99*         - Push "81" on stack (will be 1/2 height, 1/3 width)
    :        - Duplicate top of stack
     3*      - Multiple by 3 (yields width)
       &s    - Save stack to backup (needed later for header)
         *   - Multiple to get "half the pixels"
          :  - Duplicate top of stack

Generate blue pixels, pushed onto the stack

 [      ]+  - Loops one per pixel
  r         - Reverse stack
   009      - Push "0 0 9" onto stack
      r     - Reverse to get pixel count back to top
       ,    - Decrement counter

Generate yellow pixels, pushed onto the stack

 [      ]+  - Loops once per pixel
  r         - Reverse stack
   990      - Push "9 9 0" onto stack
      r     - Reverse to get pixel count back to top
       ,    - Decrement counter

Print PPM header

 'Po          - Print "P"
    9         - Push 9 as "max RGB value"
     l        - Load "width and height" from backup cell
      f       - Flip top two entries (width, height)
       2*     - Double to get the height
         f    - Flip top two entries back
          3   - Push 3, the "PPM image type"
           r  - Reverse stack, stack prints automatically
\$\endgroup\$
1
\$\begingroup\$

BBC BASIC, 72 bytes

V. 19,0,16,255,215|25,97,78;26;25,4,78;27;19,0,16,0,87,183;25,97,-78;26;

Output

Output

\$\endgroup\$
1
\$\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\$
1
\$\begingroup\$

JavaScript (Node.js), 94 bytes

Prints a solid flag (or not quite, depending on your font) in the specified rgb colors.

for(i=1;i<4108;i++)process.stdout.write(i%79?`\x1b[38;2;${i<2054?'0;87;183':'255;215;0'}m█`:`
`)
\$\endgroup\$
1
\$\begingroup\$

Ruby with Shoes, 96 characters

Shoes.app(width:78,height:52){background rgb 0,87,183
stroke fill rgb 255,215,0
rect 0,26,78,52}

Sample output:

flag of Ukraina

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

FLTK, 153 characters

Function{}{}{Fl_Window{}{xywh{9 9 78 52}}{Fl_Box{}{xywh{0 0 78 26}box FLAT_BOX color 0x0057b7ff}Fl_Box{}{xywh{0 26 78 52}box FLAT_BOX color 0xffd700ff}}}

Ungolfed:

Function {} {} {
    Fl_Window {} {
        xywh {9 9 78 52}
    } {
        Fl_Box {} {
            xywh {0 0 78 26}
            box FLAT_BOX
            color 0x0057b7ff
        }
        Fl_Box {} {
            xywh {0 26 78 52}
            box FLAT_BOX
            color 0xffd700ff
        }
    }
}

Sample output:

flag of Ukraina

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

J, 52 bytes

viewrgb 52 78$22455,&:(2028&$)16766720[load'viewmat'

image

viewrgb 52 78$22455,&:(2028&$)16766720[load'viewmat'
                                       load'viewmat'  : loads the lib into the session
                                      [               : acts as a statement seperator
              22455,&:(2028&$)16766720                : array of color values
                   ,&:(2028&$)                        : append,appose,shape bonded with
                                                      : 2028 as the left arg which
                                                      : invokes shape on the two args
                                                      : individually and invokes append
                                                      : on the results
        52 78$                                        : creates the color matrix
viewrgb                                               : draw the colors
\$\endgroup\$
1
\$\begingroup\$

C (MSVC) + Win32, 106 bytes

r[4];p(c){FillRect(GetDC(0),r,CreateSolidBrush(c));}main(){*r=600;r[1]=200;p(12344064);r[3]=400;p(55039);}

Draws the flag onto the top window: enter image description here

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

Python (Thonny 4.0 REPL), 419 bytes

print("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAARMAAAC3CAMAAAAGjUrGAAAAD1BMVEUAW7v/1QAAVb+ln3n/2QAG3wIgAAAAzUlEQVR4nO3QsQGAMAzAsBT4/2b2eO0onaAZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACASx62ednmY5vD5qSclJNyUk7KSTkpJ+WknJSTclJOykk5KSflpJyUk3JSTspJOSkn5aSclJNyUk7KSTkpJ+WknJSTclJOykk5KSflpJyUk3JSTspJOSkn5aSclJNyUk7KSTkpJ+WknJSTclJOykk5KSflpJyUk3JSTspJOSkn5aSclJNyUk7KSTkpJ+WknJSTclJOykk5KSflpH7zk2pa0LCuDAAAAABJRU5ErkJggg==")

Longer than a standard answer but ok. Thonny supports printing images if they’re in base64 form.

enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ Your first answer is valid, if a little long (although I'd change the title to something like "Python 3 (Thonny REPL), 419 bytes"; your second answer isn't valid as it's not actually a program which outputs the image. (And the image isn't correctly formatted anyway.) \$\endgroup\$
    – Ginger
    Dec 27, 2022 at 17:10
0
\$\begingroup\$

Python + Pygame (122 bytes)

import pygame.display as p
s=p.set_mode((78,52))
s.fill((0,87,183),(0,0,78,26))
s.fill((255,215,0),(0,26,78,26))
p.flip()

Briefly flashes the flag on the screen before exiting.

enter image description here

\$\endgroup\$
0
\$\begingroup\$

C# (.NET Framework), 163 chars

Shorter version of Björn Larsson's answer.

void Draw(){var f=new Bitmap(78,52);for(int y=0;y<52;y++)for(int x=0;x<78;x++)f.SetPixel(x,y,Color.FromArgb(y>25?255:0,y>25?215:87,y>25?0:183));f.Save("f.bmp");}

Effective version with explanation:

using System.Drawing;

namespace Ukraine {
    internal class Program {
        static void Main() {
            // Create a bitmap.
            var f = new Bitmap(78, 52);

            // Iterate over the bitmap's pixels.
            for (int y = 0; y < 52; y++) {
                for (int x = 0; x < 78; x++) {
                    f.SetPixel(                  // Set the pixel...
                        x, y,                    // at the current x and y...
                        Color.FromArgb(
                            y > 25 ? 255 : 0,    // selecting the R value with a ternary expression...
                            y > 25 ? 215 : 87,   // selecting the G value with a ternary expression...
                            y > 25 ? 0 : 183)    // and selecting the B value with a ternary expression.
                        );
                }
            }

            // Save the bitmap.
            f.Save("f.bmp");
        }
    }
}

Produces an image in the exe's folder:

enter image description here

\$\endgroup\$
3
  • \$\begingroup\$ Welcome to Code Golf! One thing to note is that snippets are not allowed by our rules, so you would have to wrap this in a full program (all the Main stuff and whatnot). \$\endgroup\$
    – Seggan
    Jul 7, 2022 at 16:27
  • 1
    \$\begingroup\$ A function would also be allowed \$\endgroup\$
    – mousetail
    Jul 7, 2022 at 16:30
  • \$\begingroup\$ @Seggan C# supports top-level code nowadays. \$\endgroup\$
    – Steffan
    Sep 25, 2022 at 18:37
1 2
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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