115
\$\begingroup\$

This year's UEFA Euro 2016 is over and besides a couple of negative headlines there has been a very positive surprise as well – the Iceland national football team. Let's draw their national flag.

Input

Well, obviously this challenge has no input.

Output

  • Draw the flag of Iceland in any applicable visual format of at least 100 x 72 pixels or 25 x 18 characters.
  • Save the output to a file or present it instantly – example formats are: images like png, jpg etc., vector graphics, draw on HTML canvas or even use non-whitespace characters for visualization.
  • Use these colors: blue: #0048e0, white: #ffffff and red: #d72828.
  • If your language doesn't support specific color values, use the standard values for red, blue and white from the ANSI color codes.
  • Draw the flag with the correct proportions, as shown in the figure below:

Boilerplate

  • You can write a program or a function. If it is an anonymous function, please include an example of how to invoke it.
  • This is so shortest answer in bytes wins.
  • Standard loopholes are disallowed.

Leaderboard

var QUESTION_ID = 85141; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 41859; // This should be the user ID of the challenge author.
var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;function answersUrl(index) {return "https://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;}function commentUrl(index, answers) {return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;}function getAnswers() {jQuery.ajax({url: answersUrl(answer_page++),method: "get",dataType: "jsonp",crossDomain: true,success: function (data) {answers.push.apply(answers, data.items);answers_hash = [];answer_ids = [];data.items.forEach(function(a) {a.comments = [];var id = +a.share_link.match(/\d+/);answer_ids.push(id);answers_hash[id] = a;});if (!data.has_more) more_answers = false;comment_page = 1;getComments();}});}function getComments() {jQuery.ajax({url: commentUrl(comment_page++, answer_ids),method: "get",dataType: "jsonp",crossDomain: true,success: function (data) {data.items.forEach(function(c) {if (c.owner.user_id === OVERRIDE_USER)answers_hash[c.post_id].comments.push(c);});if (data.has_more) getComments();else if (more_answers) getAnswers();else process();}});}getAnswers();var SCORE_REG = /<h\d>\s*([^\n,]*[^\s,]),.*?(-?\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;var OVERRIDE_REG = /^Override\s*header:\s*/i;function getAuthorName(a) {return a.owner.display_name;}function process() {var valid = [];answers.forEach(function(a) {var body = a.body;a.comments.forEach(function(c) {if(OVERRIDE_REG.test(c.body))body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';});var match = body.match(SCORE_REG);if (match)valid.push({user: getAuthorName(a),size: +match[2],language: match[1],link: a.share_link,});});valid.sort(function (a, b) {var aB = a.size,bB = b.size;return aB - bB});var languages = {};var place = 1;var lastSize = null;var lastPlace = 1;valid.forEach(function (a) {if (a.size != lastSize)lastPlace = place;lastSize = a.size;++place;var answer = jQuery("#answer-template").html();answer = answer.replace("{{PLACE}}", lastPlace + ".").replace("{{NAME}}", a.user).replace("{{LANGUAGE}}", a.language).replace("{{SIZE}}", a.size).replace("{{LINK}}", a.link);answer = jQuery(answer);jQuery("#answers").append(answer);var lang = a.language;if (! /<a/.test(lang)) lang = '<i>' + lang + '</i>';lang = jQuery(lang).text().toLowerCase();languages[lang] = languages[lang] || {lang: a.language, user: a.user, size: a.size, link: a.link, uniq: lang};});var langs = [];for (var lang in languages)if (languages.hasOwnProperty(lang))langs.push(languages[lang]);langs.sort(function (a, b) {if (a.uniq > b.uniq) return 1;if (a.uniq < b.uniq) return -1;return 0;});for (var i = 0; i < langs.length; ++i){var language = jQuery("#language-template").html();var lang = langs[i];language = language.replace("{{LANGUAGE}}", lang.lang).replace("{{NAME}}", lang.user).replace("{{SIZE}}", lang.size).replace("{{LINK}}", lang.link);language = jQuery(language);jQuery("#languages").append(language);}}
body { text-align: left !important}#answer-list {padding: 10px;width: 290px;float: left;}#language-list {padding: 10px;width: 290px;float: left;}table thead {font-weight: bold;}table td {padding: 5px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/Sites/codegolf/all.css?v=617d0685f6f3"><div id="answer-list"><h2>Leaderboard</h2><table class="answer-list"><thead><tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead><tbody id="answers"></tbody></table></div><div id="language-list"><h2>Winners by Language</h2><table class="language-list"><thead><tr><td>Language</td><td>User</td><td>Score</td></tr></thead><tbody id="languages"></tbody></table></div><table style="display: none"><tbody id="answer-template"><tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody></table><table style="display: none"><tbody id="language-template"><tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody></table>

If you can't find your answer, format your language and byte count as explained in the Leaderboard's "Info Section".


This challenge is inspired by Draw the national flag of france.

\$\endgroup\$
18
  • 23
    \$\begingroup\$ Far more challenging would be the flag of my country, who also did a lot better than expected in the Euros this year - Wales. :-) \$\endgroup\$
    – Gareth
    Commented Jul 11, 2016 at 10:54
  • 26
    \$\begingroup\$ @Gareth I'm looking forward to a waterproof specification of the dragon. ;) \$\endgroup\$ Commented Jul 11, 2016 at 11:04
  • 4
    \$\begingroup\$ It looks like the blue in the above image is darker than the actual #0048e0 \$\endgroup\$
    – Luis Mendo
    Commented Jul 11, 2016 at 12:32
  • 11
    \$\begingroup\$ @MartinEnder Does carving it on a stone tablet count? That's waterproof. \$\endgroup\$ Commented Jul 12, 2016 at 11:11
  • 6
    \$\begingroup\$ @MartinEnder Mathematica will have one. \$\endgroup\$
    – gcampbell
    Commented Jul 12, 2016 at 18:57

90 Answers 90

270
\$\begingroup\$

Python 3, 190 172 171 169 167 160 159 147 143 bytes

Using PIL version 1.1.7 which has a deprecated but not removed offset method.

from PIL.ImageDraw import*
i=Image.new('RGB',(25,18),'#d72828')
Draw(i).rectangle((1,1,23,16),'#0048e0',~0)
i.offset(9).resize((100,72)).show()

Creates a 25*18 pixel image filled with red then draws a 23*16 pixel rectangle filled with blue with white outline of one pixel. It then offsets the image by (9,9) which wraps on the edges, resizes it to 100*72 then shows it in a window.

Flag before offsetting:

enter image description here (resized to 100*72)

Output:

enter image description here

Animated:

enter image description here

Edit1: Golfed 18 bytes by removing the cropping by initially creating a 25*18 image.

Edit2: Golfed 1 byte by using #fff instead of white.

Edit3: Golfed 2 bytes by aliasing imports.

Edit4: Golfed 2 bytes by removing the second argument of the offset method .

Edit5: Golfed 7 bytes by showing the image instead of saving. (needs imagemagick installed on Unix)

Edit6: Golfed 1 byte by rewriting imports.

Edit7: Golfed 12 bytes by rewriting imports again. (thanks by @Dennis)

Edit8: Added animation.

Edit9: Updated animation as it was missing the last frame.

Edit10: Golfed 4 bytes thanks to Albert Renshaw!

\$\endgroup\$
16
  • 44
    \$\begingroup\$ Really nice answer. \$\endgroup\$ Commented Jul 11, 2016 at 14:30
  • 19
    \$\begingroup\$ This is genius! (Viking)Hat off to you. \$\endgroup\$
    – Ioannes
    Commented Jul 11, 2016 at 15:59
  • 29
    \$\begingroup\$ Wow, it's rare that I vote on code-golf type questions on SO, but it's even rarer that I'll join a whole new community just to do so. This offset hack is reminiscent of what we used to have to do before you young whippersnappers got your oodlebytes of memory to work with. Excellent job. \$\endgroup\$
    – user56228
    Commented Jul 12, 2016 at 0:53
  • 5
    \$\begingroup\$ genius,really! 💡 \$\endgroup\$
    – InuYaksa
    Commented Jul 12, 2016 at 7:22
  • 4
    \$\begingroup\$ If you do from PIL.ImageDraw import*, I becomes Image and D.Draw becomes Draw, saving 11 bytes. \$\endgroup\$
    – Dennis
    Commented Jul 12, 2016 at 16:44
121
\$\begingroup\$

x86 real-mode machine code for DOS COM, 69 65 63 62 bytes

Iceland flag produced

The code is meant to be executed as a DOS COM executable.

Special thanks

  • meden, saved four bytes.
  • meden, saved two bytes and removed the flickering.

Machine code (in hex bytes)

68 00 A0 07 B8 13 00 CD      10 BE 23 01 AD 91 AD 91 
AC E3 FE 60 30 ED F3 AA      61 81 C7 40 01 FE CD 75 
F2 EB E9 FA B4 00 00 09      28 B4 46 00 0F FA 28 80 
57 0F 14 B4 0C 50 00 FA      14 0C 00 64 00 00

Assembly source

Source is for NASM.

ORG 100h

push 0a000h
pop es

mov ax, 13h
int 10h

mov si, data


_draw:
 lodsw
 xchg ax, cx

 lodsw
 xchg ax, di

 lodsb

_cycle:
 jcxz _cycle

 ;al = color
 ;cl = col
 ;ch = row

rect:
 pusha
 xor ch, ch
 rep stosb
 popa
 add di, 320
 dec ch
 jnz SHORT rect

jmp SHORT _draw


data: 

        db 250d
        db 180d
        dw 0000h
        db 09h


        db 40d
        db 180d
        dw 0070d
        db 0fh


        db 250d
        db 40d
        dw 22400d
        db 0fh

        db 20d
        db 180d
        dw 80d
        db 0ch


        db 250
        db 20
        dw 25600d 
        db 0ch


        dw 0000h
\$\endgroup\$
6
  • 15
    \$\begingroup\$ This is a really cool first answer! Welcome! \$\endgroup\$ Commented Jul 11, 2016 at 21:00
  • 6
    \$\begingroup\$ You can save 2 bytes by replacing 'mov' with 'xchg' at 10h & 13h and another 2 bytes by replacing 'test cx,cx/jz' with 'jcxz' at 16h \$\endgroup\$
    – meden
    Commented Jul 12, 2016 at 10:10
  • 3
    \$\begingroup\$ Some more thoughts. Since the program runs in the infinite loop, you can avoid flickering just by making the loop shorter: _loop: jcxz _loop. You can also cut 2 bytes from the end of the data chunk if you change the loading order of cx and di \$\endgroup\$
    – meden
    Commented Jul 12, 2016 at 13:47
  • \$\begingroup\$ Thanks again @meden. The flickering was completely unnecessary in effect :) I also removed the mov bx, 320 and moved the 320 into add di, 320 (previously add di, bx). \$\endgroup\$ Commented Jul 12, 2016 at 14:04
  • \$\begingroup\$ Great. Now you've got a firm edge over all machine code answers in this challenge. Just for the sake of correctness: it'd better to move jcxz _cycle right after xchg ax,cx so it wouldn't load bytes past the end of the data. And there's some misleading comments in the source: ;dx = row. dx is not used anywhere in code. \$\endgroup\$
    – meden
    Commented Jul 13, 2016 at 12:46
57
\$\begingroup\$

C, 194 191 183 Bytes

#define C "\x1b["
#define A "@@@@@@"
y;f(){for(;y++<14;)printf(y>5&&y<10?y>6&&y<9?C"31m"A A A A"@\n":C"0m"A"@@"C"31m@@"C"0m"A A"@@@\n":C"34m"A"@"C"0m@"C"31m@@"C"0m@"C"34m"A A"@@\n");}

-3 adding one @ on the #define A
-8 adding [ on #define C

Usage

main(){f();}

Output

image

valid basing on this comment from the OP

Double Size Output, 204 Bytes

#define C "\x1b["
#define B "████"
#define A B B B
y;f(){for(;y++<28;)printf(y>10&&y<19?y>12&&y<17?C"31m"A A A A"██\n":C"0m"A B C"31m"B C"0m"A A B"██\n":C"34m"A"██"C"0m██"C"31m"B C"0m██"C"34m"A A B"\n");}

image2

\$\endgroup\$
5
  • 23
    \$\begingroup\$ the 5th upvote triggered a +810 rep network wide... Thanks! (Yes it's the first site where i reach the 200 rep :D) \$\endgroup\$ Commented Jul 11, 2016 at 14:58
  • 1
    \$\begingroup\$ Doesn't the result have to be "at least 100 x 72 units, where a unit is a pixel or a character"? This doesn't meet this requirement, but I suspect the OP made a mistake when formulating that definition. \$\endgroup\$
    – Kritzefitz
    Commented Jul 12, 2016 at 14:07
  • 4
    \$\begingroup\$ @Kritzefitz Well, a character takes up many pixels, so it can be a pixel instead of a character. Found a hole. \$\endgroup\$ Commented Jul 13, 2016 at 9:17
  • \$\begingroup\$ @GiacomoGarabello Whats the first site in the at pic where you got +150? I don't recognise the icon. \$\endgroup\$
    – user8777
    Commented Jul 14, 2016 at 4:41
  • \$\begingroup\$ @LegoStormtroopr It's PPCG!! Take a look at this GitHub Project! \$\endgroup\$ Commented Jul 14, 2016 at 5:29
32
\$\begingroup\$

Excel VBA, 254 228 153 bytes

Couldn't really find a way to set column/row size to pixels(thereby making them square) because of the way Excel handles it so make them nice and square first.

Edit 1: Replaced RGB with returned values for colors, -26 bytes

Edit 2: Tried to add as many suggestions as I could, -75 bytes. I was not able to use &48e0 as a color and I am not sure why. Thanks everyone

Sub e()
c "A1:CV72", rgbBlue
c "AC1:AR72", -1
c "A29:CV44", -1
c "AG1:AN72", 255
c "A33:CV40", 255
End Sub

Sub c(d, f)
Range(d).Interior.Color = f
End Sub

Picture: Iceland Flag

\$\endgroup\$
15
  • 1
    \$\begingroup\$ Also the code to convert it to pixels looks like it requires you hard code either some part of the resolution or PPI (I don't really understand the formula) so it seems it wouldn't work across all devices either. \$\endgroup\$
    – tjb1
    Commented Jul 11, 2016 at 17:10
  • 2
    \$\begingroup\$ And, just for completeness (to do with setting up square cells rather than the solution itself), if you switch to page layout view, you can set cell height and width to specific values like 0.2cm. This will be maintained once you switch back, and no need to try and work out the bizarre Excel aspect ratios :-) By the way, if you want some more cool Excel tricks, look up Joel Spolsky's "You suck at Excel" video. \$\endgroup\$
    – user56228
    Commented Jul 12, 2016 at 12:10
  • 3
    \$\begingroup\$ I think extra whitespace can be removed, even though it is added automatically later. \$\endgroup\$ Commented Jul 12, 2016 at 16:00
  • 1
    \$\begingroup\$ Nice to see someone using VBA; to make cells square within the code use Columns.ColumnWidth = 2.14. This matches the default height of the rows, and so makes all the cells square. \$\endgroup\$
    – Carrosive
    Commented Jul 15, 2016 at 13:44
  • 1
    \$\begingroup\$ For future reference a Cells.ColumnWidth=2 call can be used to make all of the cells square; also you can condense c "AG1:AN72", 255 *\n* c "A33:CV40", 255 to c "AG1:AN72,A33:CV40", 255 and like wise for the c call that proceeds it \$\endgroup\$ Commented Jan 6, 2017 at 12:05
30
\$\begingroup\$

MATL, 57 56 52 49 48 bytes

7:g2IvtPvt!9Mh2$X>2YG[0E28]8*255/7B[43DD]51/v2ZG

This produces the following figure (tested with the compiler running on Matlab and on Octave).

enter image description here

EDIT: You can experimentally try at MATL Online! (you may need to reload the page if it doesn't work initially).

How it works

7:g         % Range from 1 to 7 converted to logical: push array [1 1 1 1 1 1 1]
2           % Push 2
I           % Push 3
v           % Concatenate vertically into a 9×1 array
tPv         % Duplicate, flip vertically, concatenate. Gives a 18×1 array
t!          % Duplicate, transpose: 1×18 array
9M          % Push [1 1 1 1 1 1 1] again
h           % Concatenate horizontally: gives 1×25 array
2$X>        % Maximum of the two arrays, with broadcast. Gives a 18×25 array
            % with 1 for blue, 2 for white, 3 for red
2YG         % Show image with default colormap
[0E28]8*    % Push array [0 72 224] (blue)
255/        % Divide each entry by 255. Colors are normalized between 0 and 1
7B          % 7 converted into binary: push array [1 1 1] (white, normalized)
[43DD]51/   % Push array [215/255 40/255 40/255] (red, normalized)
v           % Concatenate vertically. Gives a 3×3 array
2ZG         % Use as colormap
\$\endgroup\$
0
27
\$\begingroup\$

CSS, 285 284 264 bytes

*,:before,:after{background:#fff;width:100;height:72}body{background:#0048e0;margin:0}:before,:after{content:"";position:fixed}:after{background:#d72828}html:before{top:28;height:16}body:before{left:28;width:16}html:after{top:32;height:8}body:after{left:32;width:8

Saved 1 byte thanks to @insertusernamehere.

Saved 20 bytes thanks to @user2428118, by removing all the pxs. Note that this requires the page to be rendered in quirks mode, so it doesn't work in Stack Snippets.

I could copy the Python approach of wrapping an image around at an offset, but it wouldn't be interesting to.

Ungolfed:

*, *::before, *::after {
  background: #fff;
  width: 100px;
  height: 72px;
}

body {
  background: #0048e0;
  margin: 0;
}

*::before, *::after {
  content: "";
  position: fixed;
}

*::after { background: #d72828 }

html::before { top: 28px; height: 16px }
body::before { left: 28px; width: 16px }
html::after { top: 32px; height: 8px }
body::after { left: 32px; width: 8px }

This uses the pseudo-elements (elements that aren't written in HTML) ::before and ::after to create the lines on the flag. The reason it works with no HTML is that in HTML5 the <html> and <body> elements are optional, so browsers automatically create them if they're not present.

More fun:

*, *::before, *::after {
  background: white;
  width: 100px;
  height: 72px;
}

body {
  background: #0048e0;
  margin: 0;
}

*::before, *::after {
  content: "";
  position: fixed;
}

*::after { background: #d72828 }

html::before { top: 28px; height: 16px }
body::before { left: 28px; width: 16px }
html::after { top: 32px; height: 8px }
body::after { left: 32px; width: 8px }

@keyframes change-color {
  from { filter: none }
  50% { filter: hue-rotate(360deg) }
  to { filter: none }
}

@keyframes transformations {
  from { transform: translate(150%, 100%) rotateZ(0deg) scale(0.7) }
  15% { transform: translate(150%, 100%) rotateZ(54deg) scale(1.8) }
  to { transform: translate(150%, 100%) rotateZ(360deg) scale(0.7) }
}

html {
  animation:
    0.7s linear infinite change-color,
    1s linear infinite transformations;
}

\$\endgroup\$
8
  • 2
    \$\begingroup\$ You can still save 1 byte by replacing white with #fff. \$\endgroup\$ Commented Jul 11, 2016 at 21:11
  • \$\begingroup\$ @insertusernamehere Yep, thanks. \$\endgroup\$
    – gcampbell
    Commented Jul 12, 2016 at 5:40
  • 1
    \$\begingroup\$ If you apply the CSS in quirks mode (page without doctype) you can bring it down to 264 bytes by omitting px everywhere. \$\endgroup\$ Commented Jul 12, 2016 at 10:11
  • \$\begingroup\$ @user2428118 Even more useful considering that there's no HTML, therefore no <!doctype html>! \$\endgroup\$
    – wizzwizz4
    Commented Jul 12, 2016 at 17:32
  • \$\begingroup\$ @user2428118 For some reason it doesn't work for me in mobile Safari. I'll have a look when I'm next at a computer. \$\endgroup\$
    – gcampbell
    Commented Jul 12, 2016 at 19:05
27
\$\begingroup\$

Bash + Imagemagick 7, 94 90 86 85 bytes

magick -size 84x56 xc:#0048e0 ${s=-splice 8x8}+28+28 -background \#d72828 $s+32+32 x:

Saved 8 bytes, thanks to @manatwork, and 1 byte, thanks to @GlennRanders-Pehrson

\$\endgroup\$
6
  • 5
    \$\begingroup\$ If you specify x: instead of output file name, convert will display the result in a window, which is also acceptable. And is enough to just escape the sharp, no need to quote: \#d72828. \$\endgroup\$
    – manatwork
    Commented Jul 11, 2016 at 15:29
  • 2
    \$\begingroup\$ Usually we label such answers as Bash + Imagemagick. On bash side you can save another 4 characters: convert -size 84x56 xc:#0048e0 ${s=-splice 8x8}+28+28 -background \#d72828 $s+32+32 x:. \$\endgroup\$
    – manatwork
    Commented Jul 12, 2016 at 10:36
  • \$\begingroup\$ Just a stupid question: Can you do ${s=-splice 8x8}+56? \$\endgroup\$ Commented Jul 13, 2016 at 9:48
  • \$\begingroup\$ @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ +56 is treated as +56+0, not +28+28. \$\endgroup\$
    – bodqhrohro
    Commented Jul 13, 2016 at 10:16
  • 2
    \$\begingroup\$ You can save another byte by using a recent version of ImageMagick; then the command can be "magick" instead of "convert". \$\endgroup\$ Commented Jul 13, 2016 at 11:17
20
\$\begingroup\$

ZX Spectrum BASIC, 210 141 92 bytes

1 LET n=-VAL "8.5": FOR y=n TO -n: FOR x=n TO VAL "16": LET p=VAL "271"(PI-(ABS x<SQR PI OR ABS y>SQR PI)-NOT INT ABS x*INT ABS y): PRINT PAPER p; BRIGHT p>PI;" ";: NEXT x: PRINT : NEXT y

enter image description here

Size determined as the size of the BASIC program on tape via SAVE. A lot of the golfing credit to some members of the ZX Spectrum group on Facebook, in particular @impomatic and Johan Koelman.

\$\endgroup\$
7
  • \$\begingroup\$ Seeing those PAPER and BRIGHT brings so many good memories :-) \$\endgroup\$
    – Luis Mendo
    Commented Jul 12, 2016 at 0:01
  • \$\begingroup\$ Is there any info on how much memory a ZX Spectrum BASIC program takes? I thought it was a "tokenized" language, i.e. I expected FOR, NOT etc to take up only 1 or maybe 2 bytes each \$\endgroup\$
    – Luis Mendo
    Commented Jul 12, 2016 at 0:19
  • 1
    \$\begingroup\$ @LuisMendo Yes, it is tokenized - FOR is precisely one byte. However, numbers are "anti-tokenized" in that they are stored as both their text and binary forms and take up 5 more bytes than you'd expect, hence NOT PI instead of zero and the like. \$\endgroup\$ Commented Jul 12, 2016 at 5:13
  • \$\begingroup\$ 132 bytes by removing the AT and adjusting the boundary test twitter.com/john_metcalf/status/752760203007791105 \$\endgroup\$
    – impomatic
    Commented Jul 12, 2016 at 7:06
  • 1
    \$\begingroup\$ 122 bytes with some further optimizations twitter.com/john_metcalf/status/752783690179211264 \$\endgroup\$
    – impomatic
    Commented Jul 12, 2016 at 8:37
17
\$\begingroup\$

ZX Spectrum Z80 Assembly, 65 bytes

    ld hl,22528
    ld b,7
    ld de,120*256+8 ; white, blue
    ld a,16         ; red

; create the first row

blueleft:
    ld (hl),e
    inc hl
    djnz blueleft

    ld (hl),d
    inc hl
    ld (hl),a
    inc hl
    ld (hl),a
    inc hl
    ld (hl),d
    inc hl

    ld b,14
blueright:
    ld (hl),e
    inc hl
    djnz blueright

; copy the first row to the next 17 rows

    ld l,b
    ld de,22528+32
    ld bc,17*32
    ldir

; add the horizontal stripe

    ld hl,22528+7*32
    dec d
    ld e,b
    ld c,2
midrep:
    ld b,25
midstripe:
    cp (hl)
    jr z,red
    ld (hl),120
red:
    ld (de),a
    inc hl
    inc de
    djnz midstripe

    ld hl,22528+10*32
    ld e,9*32
    dec c
    jr nz,midrep
    ret

Icelandic Flag

\$\endgroup\$
16
\$\begingroup\$

Minecraft 1.10.2, 734 characters

It might be 734 characters, but it's the only submission so far made of actual wool!

summon FallingSand ~ ~1 ~ {Block:log,Time:1,Passengers:[{id:FallingSand,Block:redstone_block,Time:1,Passengers:[{id:FallingSand,Block:activator_rail,Time:1,Passengers:[{id:MinecartCommandBlock,Command:"fill 0 ~ 0 100 ~ 72 wool 11"},{id:MinecartCommandBlock,Command:"fill 28 ~ 0 44 ~ 72 wool"},{id:MinecartCommandBlock,Command:"fill 0 ~ 28 100 ~ 44 wool"},{id:MinecartCommandBlock,Command:"fill 32 ~ 0 40 ~ 72 wool 14"},{id:MinecartCommandBlock,Command:"fill 0 ~ 32 100 ~ 40 wool 14"},{id:MinecartCommandBlock,Command:setblock ~ ~ ~1 command_block 0 replace {Command:fill ~ ~-3 ~-1 ~ ~ ~ air}},{id:MinecartCommandBlock,Command:setblock ~ ~-1 ~1 redstone_block},{id:MinecartCommandBlock,Command:kill @e[type=MinecartCommandBlock]}]}]}]}

Go to about -5x -5z, paste into an Impulse command block, set it to "Always Active" and press Done.

Flag spans from 0, 0 to 100, 72; and is 3 blocks above the command block as placed. It casts a fairly large shadow, and monsters spawn under it. Whether this is accurate to the country of Iceland, however, is anyone's guess.

Fair warning - will /kill all MinecartCommandBlocks in the world in the interest of saving four characters. Don't run this in a world you're overly attached to.

Flag

Used MrGarretto's command combiner and tweaked the output a little bit (808 -> 734)

\$\endgroup\$
2
  • 3
    \$\begingroup\$ "Whether this is accurate to the country of Iceland..." 😂 \$\endgroup\$
    – Jordan
    Commented Aug 1, 2016 at 17:43
  • 3
    \$\begingroup\$ Can't you just use kill @e without the target selector argument? It'll kill the player but hey the flag will still be there \$\endgroup\$
    – kuilin
    Commented Dec 29, 2016 at 4:33
11
\$\begingroup\$

Java 8, 449 447 bytes:

import java.awt.*;import javax.swing.*;class A extends JPanel{public void paintComponent(Graphics G){super.paintComponent(G);G.setColor(new Color(0,72,224));G.fillRect(0,0,175,126);G.setColor(Color.WHITE);G.fillRect(49,0,28,126);G.fillRect(0,49,175,28);G.setColor(new Color(215,40,40));G.fillRect(56,0,14,126);G.fillRect(0,56,175,14);}public static void main(String[]a){JFrame J=new JFrame();J.add(new A());J.setSize(175,147);J.setVisible(true);}}

A very late answer, and also the longest one here, apparently. Uses the java.awt.Graphics class to create and open a window with the flag in it, which is created by 5 total rectangles consisting of 1 for the blue blocks, 2 for the white stripes, and 2 for the red stripes. Uses 7 pixels:1 unit ratio. In other words, for each unit, 7 pixels are used. Here is an image of the output on a Macintosh with OS X 10.11:

Example Output

Now to find a way to golf this down a bit more...

\$\endgroup\$
9
  • \$\begingroup\$ Try overriding paint instead of paintComponent. Consider using an anonymous class for the JPanel. Consider just using a BufferedImage and outputting to a file. \$\endgroup\$
    – Justin
    Commented Jul 12, 2016 at 14:12
  • \$\begingroup\$ @Justin Actually, I was already using Blue as 1 huge rectangle for the background. I just got mixed up between this and another version I made in Python. Regardless, thanks for the other tips! :) \$\endgroup\$
    – R. Kap
    Commented Jul 12, 2016 at 17:42
  • \$\begingroup\$ Some more suggestions: Don't use a JPanel, just override the JFrame. If you do this and just override paint, you don't need Swing, just AWT, so change the JFrame to Frame and remove the import. Don't call super.paint. Rearrange the main method; move the setSize into the paint method of our Frame, remove the variable J, and append .setVisible(true) to the end of the anonymous class. Finally, change .setVisible(true) to be show(), yes it's a deprecated method, but it's shorter. Use an interface to remove the public from the main method. \$\endgroup\$
    – Justin
    Commented Jul 12, 2016 at 18:05
  • \$\begingroup\$ Final result at 338 chars (had to change the height as well since it's a frame): import java.awt.*;interface A{static void main(String[]a){new Frame(){public void paint(Graphics G){setSize(175,119);G.setColor(new Color(0,72,224));G.fillRect(0,0,175,126);G.setColor(Color.WHITE);G.fillRect(49,0,28,126);G.fillRect(0,49,175,28);G.setColor(new Color(215,40,40));G.fillRect(56,0,14,126);G.fillRect(0,56,175,14);}}.show();}} \$\endgroup\$
    – Justin
    Commented Jul 12, 2016 at 18:05
  • 1
    \$\begingroup\$ Even better: don't paint the first rectangle, just call setBackground(color) (also the size was still wrong). Now at 317: import java.awt.*;interface A{static void main(String[]a){new Frame(){public void paint(Graphics G){setSize(175,126);setBackground(new Color(0,72,224));G.setColor(Color.WHITE);G.fillRect(49,0,28,126);G.fillRect(0,49,175,28);G.setColor(new Color(215,40,40));G.fillRect(56,0,14,126);G.fillRect(0,56,175,14);}}.show();}} \$\endgroup\$
    – Justin
    Commented Jul 12, 2016 at 18:11
11
\$\begingroup\$

Logo, 216 188 bytes

Using Calormen.com's implementation. For you purists, the implementation uses some antialiasing which feathers the edges a little. I did waste 3 bytes hiding the turtle, though, so that should make up for it.

This could be reduced greatly if your Logo implementation lets you set the size of the window. Then you could wrap and make the turtle plow on through to make the cross in four strokes, and skip having to trim it up with a border.

generated flag screenshot

TO X :C :S
setpc :C
setpensize :S
home
pd
setx 100
setx 36
bk 36
fd 72
pu
END
setpc "#48e0
fill
X 7 16
X "#d72828 8
fd 4
pe
pd
setx -4
bk 80
setx 104
fd 80
setx 0
ht
\$\endgroup\$
4
  • \$\begingroup\$ I didn't know there was an English speaking version of Logo! \$\endgroup\$
    – Vincent
    Commented Jul 13, 2016 at 14:47
  • 1
    \$\begingroup\$ Absolutely. I think I first saw it over 30 years ago on an Apple IIe. I also had it on my TRS-80 Color Computer. It was my first taste of using angles in geometry, years before I was to officially learn it in school. \$\endgroup\$ Commented Jul 13, 2016 at 14:49
  • \$\begingroup\$ Why the white border around it? \$\endgroup\$ Commented Jul 14, 2016 at 23:37
  • 1
    \$\begingroup\$ I drew the lines using a large pen, which leaves rounded edges on the tips of the cross, so I had to sweep around it with a large eraser to square them up. I was writing another version of this which used a completely different method in Logo and turned out to be smaller. I also was working on a third version that prints a big Unicode Latin cross and paints it, but the proportions weren't right and the size looked like it would exceed this one. \$\endgroup\$ Commented Jul 15, 2016 at 14:08
10
\$\begingroup\$

R, 197 195 187 bytes

w="white";r="#d72828";png(w=100,h=72);par(mar=rep(0,4),bg="#0048e0",xaxs="i",yaxs="i");frame();rect(c(0,7,0,8)/25,c(7,0,8,0)/18,c(1,.44,1,.4),c(11/18,1,5/9,1),c=c(w,w,r,r),b=NA);dev.off()

Indented, with new lines and explanations:

w="white"
r="#d72828"
png(w=100,h=72) #Creates in working directory a png called Rplot001.png 
                #with a width and a height of 120 and 72 pixels respectively.
par(mar=rep(0,4), #No margin around the plot
    bg="#0048e0", #Blue background
    xaxs="i",yaxs="i") #Axes fits range exactly
frame() #Creates an empty plot which range is xlim=c(0,1) & ylim=c(0,1)
rect(c(0,7,0,8)/25, #Because rect is vectorized
     c(7,0,8,0)/18,
     c(1,.44,1,.4), #i. e. c(25,11,25,10)/25
     c(11/18,1,5/9,1), #i. e. c(11,18,10,18)/18
     c=c(w,w,r,r), # c= is the same as col=, thanks to argument name completion
     b=NA)#No borders
dev.off()

Island flag

Edit: turns out frame(), contrary to plot() or plot.new() doesn't by default add a border to the plot, meaning bty="n" was unnecessary here.

\$\endgroup\$
10
\$\begingroup\$

FFmpeg, 339 184 bytes

ffplay -f lavfi color=d72828:100x36[r];color=white:64x32[w];color=0048e0:56x28[b];[w][b]overlay=4,split[x][y];[r][x]overlay=-32[d];[d][y]overlay=40,split[t][m];[m]vflip[n];[t][n]vstack

Will try to golf this down ..further.

100x72 image of Iceland flag

\$\endgroup\$
9
\$\begingroup\$

Atari 8-bit executable, 123 bytes

Another "just for fun" entry, this program is meant to be run on an Atari 8-bit computer or emulator. For example, to load the program on Atari800, just run:

atari800 iceland.xex

Machine code (in hex bytes)

ff ff 00 06 74 06 a9 1b 8d 30 02 a9 06 8d 31 02
a9 44 8d c4 02 a9 0f 8d c5 02 a9 84 8d c6 02 d0
fe 70 70 70 48 57 06 48 57 06 48 57 06 48 57 06
48 57 06 48 57 06 48 57 06 48 61 06 48 6b 06 48
6b 06 48 61 06 48 57 06 48 57 06 48 57 06 48 57
06 48 57 06 48 57 06 48 57 06 41 1b 06 ff fe 5b
ff ff ff c0 00 00 00 aa aa 5a aa aa aa 80 00 00
00 55 55 55 55 55 55 40 00 00 00

Assembler source code (can be compiled with MADS):

        org $0600
        lda <dlist
        sta $0230
        lda >dlist
        sta $0231
        lda #$44
        sta $02c4
        lda #$0f
        sta $02c5
        lda #$84
        sta $02c6
loop    bne loop
dlist   dta $70, $70, $70
        dta $48, a(line1), $48, a(line1), $48, a(line1), $48, a(line1), $48, a(line1), $48, a(line1), $48, a(line1)
        dta $48, a(line2)
        dta $48, a(line3), $48, a(line3)
        dta $48, a(line2)
        dta $48, a(line1), $48, a(line1), $48, a(line1), $48, a(line1), $48, a(line1), $48, a(line1), $48, a(line1)
        dta $41, a(dlist)
line1   dta $ff, $fe, $5b, $ff, $ff, $ff, $c0, $00, $00, $00
line2   dta $aa, $aa, $5a, $aa, $aa, $aa, $80, $00, $00, $00
line3   dta $55, $55, $55, $55, $55, $55, $40, $00, $00, $00

How it works:

The program uses a custom display list that's based on ANTIC Mode 8 (40 pixels per line, 2 bpp). Repeated lines are loaded from the same memory location. After setting up the display, the program enters an infinite loop.

Screenshot:

iceland.xex running on Atari800

\$\endgroup\$
9
\$\begingroup\$

Java, 335 bytes

The function is

void w()throws Exception{int w=100,h=72;BufferedImage i=new BufferedImage(w,h,1);Graphics g=i.getGraphics();g.setColor(new Color(18656));g.fillRect(0,0,w,h);g.setColor(WHITE);g.fillRect(0,28,w,16);g.fillRect(28,0,16,h);g.setColor(new Color(14100520));g.fillRect(0,32,w,8);g.fillRect(32,0,8,h);ImageIO.write(i,"png",new File("f.png"));}

And it writes the desired image as f.png, with a size of 100x72

(Note that this is not a direct competitor to the Answer by R. Kap, because it writes a file, and does not display the image on the screen)

Here is the ungolfed version that can be compiled and run:

import static java.awt.Color.WHITE;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

public class Iceland
{
    public static void main(String[] args) throws Exception
    {
        Iceland i = new Iceland();
        i.w();
    }

    void w() throws Exception
    {
        int B=0x0048e0,R=0xd72828,w=100,h=72;
        BufferedImage i=new BufferedImage(w,h,1);
        Graphics g=i.getGraphics();
        g.setColor(new Color(B));
        g.fillRect(0,0,w,h);
        g.setColor(WHITE);
        g.fillRect(0,28,w,16);
        g.fillRect(28,0,16,h);
        g.setColor(new Color(R));
        g.fillRect(0,32,w,8);
        g.fillRect(32,0,8,h);
        ImageIO.write(i,"png",new File("f.png"));
    }
}

A side note, regarding the related questions: Maybe one should create a challenge to paint the flags of

  • Indonesia
  • Poland
  • Finland
  • France
  • Netherlands
  • Thailand
  • Norway

at the same time:

enter image description here

\$\endgroup\$
9
\$\begingroup\$

Python, 119 118 114 112 bytes

Nothing special, straightforward:

b,w,r="\0H\xe0"*28,"\xff"*12,"\xd7(("*8
A,B=28*(b+w+r+w+2*b),4*(8*w+r+15*w)
print"P6 100 72 255 "+A+B+100*r+B+A

Output as binary PPM, usage

python golf_iceland.py > iceland.ppm
  • Edit1: shoved a byte between print and the quotation mark
  • Edit2: slighty shorter as binary PPM
  • Edit3: Figured that \0 can be used instead of \x00

If someone knows how to use the non-printable ASCII-character directly, please let know.

Converted to PNG

\$\endgroup\$
6
  • 2
    \$\begingroup\$ Congratulations! You beat me by a lot :D \$\endgroup\$ Commented Jul 12, 2016 at 13:52
  • 2
    \$\begingroup\$ @GáborFekete beat you in bytes, yes. But your answer is much more clever with that offset \$\endgroup\$
    – Karl Napf
    Commented Jul 12, 2016 at 14:17
  • \$\begingroup\$ Why not have the results of the escapes instead of the escapes themselves? \$\endgroup\$ Commented Jul 14, 2016 at 23:41
  • \$\begingroup\$ @SolomonUcko I tried b,w,r="\0Hà"*28,"ÿ"*12,"×(("*8 and using Python 3, but it does not work. \$\endgroup\$
    – Karl Napf
    Commented Jul 15, 2016 at 10:35
  • \$\begingroup\$ @KarlNapf, how did it fail? Did it draw incorrectly, or give an error message? It could also be an encoding issue. \$\endgroup\$ Commented Jul 16, 2016 at 14:41
8
\$\begingroup\$

Python IDLE, 191 172 156 bytes

IDLE is Python's standard IDE. Unless it has a custom theme, STDOUT is blue, STDERR is red, and the background is white. So, the following code:

from sys import*
x=[1]*7;y=[0]*7;z=[0,2,2,0]
f=[x+z+x*2]*4+[y+z+y*2,[2]*25]
for s in f+f[::-1]:[[stderr,stdout][-x].write(' █'[x>0]*2)for x in s];print()

Produces this output:

enter image description here

As printed characters as not square, this is slightly off, but if we take 1 unit to be 2 chars across and 1 char tall, then the proportions are exact.

This could be golfed, by halfing the width dimension, and using an ASCII character for the blocks such as '#', but it doesn't exactly have the same effect.


Explanation

The code itself seems quite sloppy at the moment, and can definitely be golfed, but the basic idea is:

  • Construct a matrix where 0 represents whitespace, 1 represents a blue block, and 2 represents a red block.
    • The first half is constructed (mainly through list slicing / multiplication), and added to the reverse of itself to generate the full flag.
  • Loop through the matrix, printing each value as either whitespace or a block to STDERR/STDOUT accordingly. Print a newline after each row.
\$\endgroup\$
8
\$\begingroup\$

JavaScript + HTML, 267 bytes

document.write("<div style='width:250px;height:180px;background:"+[[b="bottom",44.4,d="d72828",55.6],[r="right",32,d,40],[b,38.9,e="fff",61.1],[r,28,e,44]].map(([d,a,c,o])=>`linear-gradient(to ${d+(t=",transparent ")+a}%,#${c} ${a}%,#${c} ${o}%${t+o}%)`)+",#003897'")

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Sure the 7 - 14 ratio of left and right blue widths is correct? \$\endgroup\$
    – manatwork
    Commented Jul 11, 2016 at 10:20
  • 1
    \$\begingroup\$ @manatwork Oops, for some reason I thought 100 / 25 = 5, so everything ended up 25% too wide. \$\endgroup\$
    – Neil
    Commented Jul 11, 2016 at 10:30
7
\$\begingroup\$

SVG+Javascript, 190 165 164 bytes

No expert there, repeating one path just to change the color and line width looks silly javascript ftw!

document.write(`<svg><rect width=100 height=72 fill="#0048e0"/>${a='<path d="M0 36L100 36M36 0L36 72"style="stroke-width:'}16;stroke:#fff"/>${a}8;stroke:#d72828">`)

More readable:

document.write(`<svg><rect width=100 height=72 fill="#0048e0"/>
${a='<path d="M0 36L100 36M36 0L36 72"style="stroke-width:'}16;stroke:#fff"/>
${a}8;stroke:#d72828">`)
\$\endgroup\$
1
  • \$\begingroup\$ You can use path d="m0,0h100v72H0" instead of the rectangle to save two bytes. Likewise, use M0 36H100M36 0V72 for the other path's data, which saves another five bytes. And you can drop the style attribute in favour of declaring both stroke-width and stroke as attributes to save another five bytes. \$\endgroup\$
    – Joey
    Commented Jul 15, 2016 at 5:01
7
\$\begingroup\$

Processing, 136 bytes

size(100,72);noStroke();background(#0048e0);fill(255);rect(28,0,16,72);rect(0,28,100,16);fill(#d72828);rect(0,32,100,8);rect(32,0,8,72);

Ungolfed

//open the window
size(100,72);
//turn off borders that surround shapes by default
noStroke();
//draw blue as the background
background(#0048e0);
//set color to white
fill(255);
//draw 2 white bars
rect(28,0,16,72);
rect(0,28,100,16);
//set color to red
fill(#d72828);
//draw 2 red bars
rect(0,32,100,8);
rect(32,0,8,72);

Output:

enter image description here

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You can shave off two more bytes by using fill and rect instead of size and background. 134 bytes: noStroke();fill(#0048e0);rect(0,0,100,72);fill(255);rect(0,28,100,16);rect(28,0,16,72);fill(#d72828);rect(0,32,100,8);rect(32,0,8,72); \$\endgroup\$ Commented Jul 12, 2016 at 16:42
  • \$\begingroup\$ Adding on to what GuitarPicker said, fill(-1) is one byte shorter than fill(255) \$\endgroup\$
    – user41805
    Commented Apr 23, 2017 at 15:39
7
\$\begingroup\$

Mathematica 174 157 bytes

Without builtins:

157 bytes

r=Rectangle;c=RGBColor;Graphics@{c[{0,72,224}/255],r[{0,0},{25,18}],White,r[{7,0},{11,18}],r[{0,7},{25,11}],c[{43,8,8}/51],r[{8,0},{10,18}],r[{0,8},{25,10}]}

enter image description here

or alternatively

232 bytes

x=Join[Unitize/@Range@7,{0},{2,2},{0},Unitize/@Range@14]&/@Range@7;y=Join[ConstantArray[0,8],{2,2},ConstantArray[0,15]];z=ConstantArray[2,25];ArrayPlot[Join[x,{y},{z,z},{y},x]/.{2->RGBColor[{43,8,8}/51],1->RGBColor[{0,72,224}/255]}]

enter image description here

\$\endgroup\$
4
  • 1
    \$\begingroup\$ you're welcome. same can be applied to your second longer version. u=Unitize;c=ConstantArray etc ^_^ \$\endgroup\$
    – Dan Oak
    Commented Jul 12, 2016 at 11:36
  • 1
    \$\begingroup\$ Wait, there's something Mathematica doesn't have a builtin for? I'm surprised. \$\endgroup\$ Commented Jul 13, 2016 at 20:13
  • \$\begingroup\$ @MorganThrapp I'm sure there used to be another Mathematica answer using a builtin. \$\endgroup\$
    – gcampbell
    Commented Jul 14, 2016 at 9:12
  • 3
    \$\begingroup\$ There is CountryData["Iceland", "Flag"] \$\endgroup\$
    – dwa
    Commented Jul 18, 2016 at 4:51
7
\$\begingroup\$

JavaScript (ES6), 231 240

Code inside the snippet below. Run it to test.

d=(w,h,c)=>`<div style=float:left;width:${w}em;height:${h}em;background:#${['0048e0','fff','d72828'][~~c]}>`;document.write(d(25)+(a=[252,61,94,61,476]).concat(b=[261,70,485],810,b,a).map(v=>d(v>>5,v/4&7,v&3)).join(e='</div>')+e+e)

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

ZX Spectrum Z80 Assembly, 51 bytes

https://github.com/ralphbecket/Z80/blob/master/IcelandFlag/IcelandFlag.asm

                zeusemulate "48K", "ULA+"
ZeusEmulate_PC  equ Main
ZeusEmulate_SP  equ $FF40

                org $8000

MinWhite        equ 7
MinRed          equ MinWhite + 1
TopRed          equ MinRed + 2
TopWhite        equ TopRed + 1
Height          equ TopWhite + MinWhite - 2
Width           equ TopWhite + 2 * MinWhite - 1

White           equ %01111000
Red             equ %01010000
Blue            equ %01001000

Main            ld hl, $5800 + ((Height - 1) * 32) + (Width - 1)
                ld c, Height

YLoop           ld b, Width

XLoop           ld (hl), Red
                ld de, MinRed * $100 + TopRed
                call Test
                jr c, Next

                ld (hl), White
                ld de, MinWhite * $100 + TopWhite
                call Test
                jr c, Next

                ld (hl), Blue

Next            dec hl
                djnz XLoop
                ld de, -(32 - Width)
                add hl, de
                dec c
                jr nz, YLoop
                ret

Test            equ *
TestX           ld a, b
                cp d
                jr c, TestY
                cp e
                ret c
TestY           ld a, c
                cp d
                ccf
                ret nc
                cp e
                ret

enter image description here

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

Python Turtle, 176 bytes

Another Python Turtle implementation but this time based on stamping instead of drawing:

from turtle import*
shape("square")
c=color
c("navy")
z=shapesize
z(18,25)
s=stamp
s()
c("white")
z(4,25)
s()
bk(70)
seth(90)
s()
c("#d72828")
z(2,18)
s()
home()
z(2,25)
done()

Using stamping, and not making it easily scalable, saves about 60 bytes of code.

enter image description here

The fun part is you can replace the "square" polygon option with the "turtle" polygon option in the shape() call and get an ecogroovy logo:

enter image description here

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

J, 86 84 83 bytes

   load'viewmat'
   (255,0 72 224,:215,2#40)viewmat _9 _9|.2(b=.[,~[,.~[,[,.])0 b 14 21$1

The approach is the same as @Gábor Fekete's with Python.

Left argument colors for viewmat is an array of RGB values, in our case:

255 255 255
  0  72 224
215  40  40

And the right argument is a matrix of indices of colors.
(_9 _9 |. matrix) instructs to shift matrix 9 items in each dimension.
Scary construction (border ([,~[,.~[,[,.]) matrix) wraps matrix with number border.
And (14 21 $ 1) makes 14×21 matrix of ones.

The output is displayed in separate resizable window, pretty large by default. enter image description here

Thanks

miles - saved 2 bytes with reordering the colors, used the feature of , that duplicates the numbers (255) for the shape agreement.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ It looks like the height of the flag is 26 units instead of 25. \$\endgroup\$ Commented Jul 12, 2016 at 13:51
  • \$\begingroup\$ @GáborFekete hm, you meant height is 19 instead of 18? didn't mention that, just noticed after your comment \$\endgroup\$
    – Dan Oak
    Commented Jul 12, 2016 at 14:34
  • \$\begingroup\$ Oh right I wrote height but used the width values... \$\endgroup\$ Commented Jul 12, 2016 at 14:35
  • \$\begingroup\$ yeeeah, indeed. i made a mistake in values. the shape of initial matrix should be 14 21 (18 25 - 4 4). correcting... thank you! \$\endgroup\$
    – Dan Oak
    Commented Jul 12, 2016 at 14:37
  • 1
    \$\begingroup\$ You can save 2 bytes reordering the rgb values (255,0 72 224,:215 40 40)viewmat _9 _9|.2(b=.[,~[,.~[,[,.])0 b 14 21$1 \$\endgroup\$
    – miles
    Commented Jul 14, 2016 at 6:05
7
\$\begingroup\$

Perl 5 + -p0513, 100 bytes

$b="..."x28;$}=1x12;$@="..."x8;print"P6 100 72 31",$_="$b$}$@$}$b$b"x28,$\=($}x8 .$@.$}x15)x4,$@x100

Try it online!

Outputs a PBM image.


Perl 5 + -M5.10.0 -p0513, 107 bytes

($},$@,$;)=map".[48;5;${_}m ",18,15,1;$}x=7;say$\="$}$@$; $@$}$}
"x7,$_=$@x8 .$;.$;.$@x15 ."
",$;x=25,"
",$

Try it online!

Squished flag

Uses ANSI escape sequences and assumes a Linux terminal to display the flag. Looks a bit weird using the measurements provided.

Perl 5 + -M5.10.0 -p0513, 109 bytes

This version looks a bit closer to the expected dimensions...

($},$@,$;)=map".[48;5;${_}m  ",18,15,1;$}x=7;say$\="$}$@$;$;$@$}$}
"x7,$_=$@x8 .$;.$;.$@x15 ."
",$;x=25,"
",$

Try it online!

Less squished flag


Perl 5 + -M5.10.0 -p0513, 103 bytes

Using the standard ANSI colours (as specified in the question) saves another 4 bytes!

($},$@,$;)=map".[${_}m ",44,47,41;$}x=7;say$\="$}$@$; $@$}$}
"x7,$_=$@x8 .$;.$;.$@x15 ."
",$;x=25,"
",$

Try it online!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ The weirdness comes from the fact that characters are taller than their width. \$\endgroup\$ Commented Jul 13, 2016 at 9:22
  • \$\begingroup\$ @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ Indeed, I did wonder if there were square fixed-width fonts, but I don't imagine they'd look particularly good! I might update that second version to look even closer (it shouldn't take any more bytes than it currently is, but time...) \$\endgroup\$ Commented Jul 13, 2016 at 9:36
  • \$\begingroup\$ On a TTY, you cannot wonder such a thing, the font is THE FONT! You can't change it just because you don't like it. \$\endgroup\$ Commented Jul 13, 2016 at 9:42
6
\$\begingroup\$

C#, 384 346 317 292 291 289 Bytes

Simple solution with Windows Forms and GDI

Func<int,int,Point>p=(x,y)=>new Point(x*10,y*10);var b=new Bitmap(250,180);var g=Graphics.FromImage(b);g.Clear(Color.Blue);g.DrawLines(new Pen(Color.White,40),new[]{p(0,9),p(50,9),p(9,-20),p(9,18)});g.DrawLines(new Pen(Color.Red,20),new[]{p(0,9),p(50,9),p(9,-20),p(9,18)});b.Save("b.png");

Usage

Start a new console-project and put the code above in the main-method, add System.Drawing-Namespace.

How it works

The code creates a new image and draws some lines on it. It saves the image to disk. Some of the ending points of the lines are outside the visible area.

enter image description here

\$\endgroup\$
5
  • \$\begingroup\$ Welcome to PPCG ! Great first codegolf, but it looks like you could improve it. First, I think you can removes some spaces here and there (b = new=>b=new, using () => using(), don't use spaces after ;s. If you want, you can read our Tips for golfing in C# to find some advices. \$\endgroup\$
    – Katenkyo
    Commented Jul 13, 2016 at 14:37
  • \$\begingroup\$ Thanks, spaces are removed and I delete the using statement, too. I also use anonymous variables now. \$\endgroup\$
    – soema
    Commented Jul 13, 2016 at 14:42
  • \$\begingroup\$ Sure you need Process.Start(f);? As I understand, that is similar to cmd start. As you can choose to save or display the image and you already saved it, that step seems pointless. In which case maybe you can avoid declaring variable f too. \$\endgroup\$
    – manatwork
    Commented Jul 13, 2016 at 14:49
  • \$\begingroup\$ Yes! Just save now and no opening more ... \$\endgroup\$
    – soema
    Commented Jul 13, 2016 at 14:59
  • \$\begingroup\$ You should count the bytes for the namespace usings as well as for a method declaration or program boilerplate. This is all part of what's needed (the task gives you the choice of a function or a program, but not the choice of just a bunch of statements). \$\endgroup\$
    – Joey
    Commented Jul 15, 2016 at 10:06
6
\$\begingroup\$

PICO-8/Lua, 108 100 92 bytes (non-competing)

rectfill(0,0,24,17,12)
rect(0,7,24,10,7)
rect(7,0,10,17,7)
rect(0,8,24,9,8)
rect(8,0,9,17,8)

output

\$\endgroup\$
6
  • 3
    \$\begingroup\$ Why is this marked "Non-competing"? Usually, that is reserved for using a language that's newer than the challenge. \$\endgroup\$
    – DJMcMayhem
    Commented Jul 12, 2016 at 20:18
  • 1
    \$\begingroup\$ Because the blue is brighter than the flag's blue. \$\endgroup\$
    – acrolith
    Commented Jul 12, 2016 at 20:24
  • \$\begingroup\$ I don't know much about Pico8/lua, but is it possible to make the colors match? Otherwise, this answer is incorrect, which means it should be deleted. \$\endgroup\$
    – DJMcMayhem
    Commented Jul 12, 2016 at 20:25
  • 4
    \$\begingroup\$ @daHugLenny Since the contest allows for ANSI colors if necessary, I'm sure this would be fine. \$\endgroup\$
    – MCMastery
    Commented Jul 12, 2016 at 20:26
  • \$\begingroup\$ @DrGreenEggsandIronMan Nope, the PICO-8 has a fixed 16-color palette. :< The only two shades of blue in the palette are too dark and too bright, respectively. \$\endgroup\$
    – lynn
    Commented Jul 30, 2016 at 19:07
5
\$\begingroup\$

SpecaBAS - 150 bytes

1 a=15,b=250,c=180: FOR i=1 TO 5: READ k,x,y,w,h: RECTANGLE INK k;x,y,w,h FILL: NEXT i
2 DATA 1,0,0,b,c,a,71,0,40,c,a,0,71,b,40,2,81,0,20,c,2,0,81,b,20

Reads the ink colour, x,y, width and height and draws a rectangle with those coordinates/dimensions.

enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ Do you need spaces after each :? Oh, and it's 151 bytes. \$\endgroup\$ Commented Jul 13, 2016 at 13:16

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.