Draw the national flag of Iceland

107

13

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.

insertusernamehere

Posted 2016-07-11T09:32:23.150

Reputation: 4 551

1Related, Related, Related – insertusernamehere – 2016-07-11T09:32:37.180

20Far more challenging would be the flag of my country, who also did a lot better than expected in the Euros this year - Wales. :-) – Gareth – 2016-07-11T10:54:53.817

24@Gareth I'm looking forward to a waterproof specification of the dragon. ;) – Martin Ender – 2016-07-11T11:04:46.897

4It looks like the blue in the above image is darker than the actual #0048e0 – Luis Mendo – 2016-07-11T12:32:05.153

is this output valid? – Giacomo Garabello – 2016-07-11T12:41:09.913

@GiacomoGarabello Yes, it is. – insertusernamehere – 2016-07-11T14:22:25.953

@LuisMendo Both, the approximately color values and the image are from Wikipedia, so they may differ slightly. The image is mainly to show the proportions. Please use the colors from the question as copied from this link.

– insertusernamehere – 2016-07-11T14:28:57.033

10@MartinEnder Does carving it on a stone tablet count? That's waterproof. – user253751 – 2016-07-12T11:11:38.400

5@MartinEnder Mathematica will have one. – gcampbell – 2016-07-12T18:57:08.560

Are you sure you want one character to be one unit? 100x72 characters seems very big and there are answers below which actually have smaller flags. Could you please clarify? – Kritzefitz – 2016-07-13T17:04:57.750

@insertusernamehere This is still inconsistent with Giacomo Garabello's answer, which you declared as valid. – Kritzefitz – 2016-07-14T09:26:58.310

@Kritzefitz Ob boy, I see it now. I miscounted the lines - actually his answer misses 4 lines. Good catch. Will get in touch with him. Looking at so many similar answers and checking proportions can be confusing. – insertusernamehere – 2016-07-14T09:33:23.187

Actually, outdated version of Leaderboard installed. But I see I'm the only annoyed by the lack of stylesheet. – manatwork – 2016-07-14T09:39:26.480

There is no official up to date version. You either edit the CSS path manually, or use the suggested version I posted in an answer, but which contains other changes too.

– manatwork – 2016-07-14T09:46:58.240

Congratulations on your gold badge! – Luis Mendo – 2016-07-15T08:07:35.513

@LuisMendo Thanks a lot. I'm still overwhelmed by the sheer amount of responses and people participating in this challenge, whether with own submissions or by helping others to improve their answers. – insertusernamehere – 2016-07-15T08:14:31.367

Looks like victories for assembly languages, von Neumann would be proud – Mark K Cowan – 2016-07-18T10:26:46.103

3Why are assembly program sizes listed below measured by the output of the assembler, not by the assembler source (10x larger)? Is this part of some FAQ? I.e. if my Java *.class file is smaller than my *.java source file, can I just hexdump the *.class file and claim the smaller byte count? I mean, if they painstakenly wrote their solutions in hex and then disassembled them for our convenience, that's one thing. But it looks like they wrote them in assembler so shouldn't that be what's measured? – cdlane – 2016-08-07T05:53:52.920

Answers

259

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!

Gábor Fekete

Posted 2016-07-11T09:32:23.150

Reputation: 2 809

Which PIL version? With 3.1.2 I get “Exception: offset() has been removed. Please call ImageChops.offset() instead.” – manatwork – 2016-07-11T12:58:58.163

I'm using Pillow version 2.3.0 which has PIL version 1.1.7. The offset method has been moved to the ImageChops module in PIL 1.2. – Gábor Fekete – 2016-07-11T13:04:29.047

Oh. Sorry, not familiar with Python graphics in general. Pillow 3.1.2's PIL 1.1.7 is the one that give the error: http://pastebin.com/nBXaw8Xe Well, probably depends on the build options used by the package maintainers (I'm on Ubuntu Xenial).

– manatwork – 2016-07-11T13:09:42.313

42Really nice answer. – insertusernamehere – 2016-07-11T14:30:23.233

1Excellent solution. I was trying to think of a block-matrix type approach in Mathematica, but this is much better. The similar solution in MMA amounts to 110 bytes: Image[RotateRight[a[Table[2,56,84],4,1]~(a=ArrayPad)~4/.{2->8{0,9,28}, 1->255{1,1,1},0->5{43,8,8}},4{9,9}]/255] – LLlAMnYP – 2016-07-11T15:29:29.040

17This is genius! (Viking)Hat off to you. – Ioannes – 2016-07-11T15:59:18.637

25Wow, 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. – None – 2016-07-12T00:53:34.990

5genius,really! – InuYaksa – 2016-07-12T07:22:46.920

I think it may be possible to save a byte by omitting the o in o.png. – user2428118 – 2016-07-12T10:28:18.820

I changed it to show instead of saving but your idea won't work because a valid filename is required for saving and .png isn't one. – Gábor Fekete – 2016-07-12T11:34:39.607

Can't you do from PIL import* and then use Image instead of I and ImageDraw instead of D? – Erik the Outgolfer – 2016-07-12T16:08:32.337

Already tried that but it seems that PIL doesn't include submodules in the __all__ variable. This means no starred import :( – Gábor Fekete – 2016-07-12T16:17:13.570

3If you do from PIL.ImageDraw import*, I becomes Image and D.Draw becomes Draw, saving 11 bytes. – Dennis – 2016-07-12T16:44:04.020

Thank you, it worked! But I counted 12 bytes instead of 11. – Gábor Fekete – 2016-07-12T21:21:42.973

1Replace '#fff' with ~0 to save 4 more bytes ;) (*Note, I removed the apostrophes as well, just ~0 not '~0') – Albert Renshaw – 2016-10-15T23:45:55.110

1Thanks! It also works with -1 which equals to your solution. – Gábor Fekete – 2016-10-17T08:33:35.813

117

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

Margaret Bloom

Posted 2016-07-11T09:32:23.150

Reputation: 1 946

13This is a really cool first answer! Welcome! – AdmBorkBork – 2016-07-11T21:00:58.377

5You 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 – meden – 2016-07-12T10:10:30.540

3Some 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 – meden – 2016-07-12T13:47:15.743

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). – Margaret Bloom – 2016-07-12T14:04:47.860

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. – meden – 2016-07-13T12:46:08.177

@meden I actually prefer the jcxz where it is, It makes the code a little bit more "uniform" (de gustibus). Reading past the end of the defined data is not a matter in RM, even at the end of the segment. I updated the comment though. Thanks again. – Margaret Bloom – 2016-07-13T12:59:33.113

55

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

Giacomo Garabello

Posted 2016-07-11T09:32:23.150

Reputation: 1 419

22

the 5th upvote triggered a +810 rep network wide... Thanks! (Yes it's the first site where i reach the 200 rep :D)

– Giacomo Garabello – 2016-07-11T14:58:37.403

1Doesn'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. – Kritzefitz – 2016-07-12T14:07:53.213

4@Kritzefitz Well, a character takes up many pixels, so it can be a pixel instead of a character. Found a hole. – Erik the Outgolfer – 2016-07-13T09:17:35.550

@GiacomoGarabello Whats the first site in the at pic where you got +150? I don't recognise the icon. – None – 2016-07-14T04:41:33.543

@LegoStormtroopr It's PPCG!! Take a look at this GitHub Project!

– Giacomo Garabello – 2016-07-14T05:29:03.110

31

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

tjb1

Posted 2016-07-11T09:32:23.150

Reputation: 561

How did you make the cells square? Did you do it manually, or with some other script not included? I'd like to see it, even if it's not part of your scored program. – mbomb007 – 2016-07-11T16:49:13.683

I did it manually, the code to change the cell width is easy enough where I could have added it but the sizes aren't consistent between Row/Column or monitor resolutions unless you set the size based on pixels which can't be done from what I could find. From what I read you have to find the resolution and do some math to convert the pixels to the size the function accepts. – tjb1 – 2016-07-11T17:03:49.210

1Also 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. – tjb1 – 2016-07-11T17:10:12.883

You can save more space with r = &hd72828, w = -1 and using &48e0 for blue. You can also use sub x(r, c), Range(r).Interior.Color = c, end sub and replace those five lengthy lines with something like x "a1:cv72", &48e0 and x "a33:cv40", r. – None – 2016-07-12T07:12:10.703

I think you can also refer to multi-part ranges which should make it a little smaller, e.g. x "ac1:ar72,a29:cv44", w for both the horizontal and vertical white strips. – None – 2016-07-12T12:08:20.987

2And, 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. – None – 2016-07-12T12:10:39.747

3I think extra whitespace can be removed, even though it is added automatically later. – Erik the Outgolfer – 2016-07-12T16:00:02.710

I was not able to get it to work that way paxdiablo, maybe I don't understand how it's suppose to work? Also, I was not able to get a multi part range to work. I actually tried that before I posted the answer but it just selects the entire rectangle instead of the two small areas. – tjb1 – 2016-07-13T11:23:44.060

I Count 202. setting w and r is more bytes then its just to use the numbers twice. Sub b() Range("A1:CV72").Interior.Color=rgbBlue Range("AC1:AR72").Interior.Color=-1:Range("A29:CV44").Interior.Color=-1 Range("AG1:AN72").Interior.Color=255:Range("A33:CV40").Interior.Color=255 End Sub – JimmyJazzx – 2016-07-13T13:04:56.867

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. – Carrosive – 2016-07-15T13:44:37.840

You could probably make the range command set a separate sub and lose quite a few bytes. – enderland – 2016-07-15T23:15:05.267

Drawing the flag into the top 18x25 cells gives a perfectly respectably sized flag, and loses some extra bytes. Sub e():c "A1:Y18",rgbBlue:c "H1:K18",-1:c "A8:Y11",-1:c "I1:J18",255:c "A9:Y10",255:End Sub and Sub c(d,f):Range(d).Interior.Color=f:End Sub comes in at 138 including 2 line feeds. – Joffan – 2016-07-19T23:07:31.740

I think cells would be considered pixels and fall into the 100 x 72 category. – tjb1 – 2016-07-20T02:56:07.440

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 – Taylor Scott – 2017-01-06T12:05:14.603

Also, you were not able to use &48e0 because the hex value that you want it to represent corresponds to t &HE04800 in VBA. – Taylor Scott – 2017-01-06T12:07:36.503

29

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

Luis Mendo

Posted 2016-07-11T09:32:23.150

Reputation: 87 464

26

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

bodqhrohro

Posted 2016-07-11T09:32:23.150

Reputation: 583

5If 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. – manatwork – 2016-07-11T15:29:10.197

2Usually 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:. – manatwork – 2016-07-12T10:36:22.750

Just a stupid question: Can you do ${s=-splice 8x8}+56? – Erik the Outgolfer – 2016-07-13T09:48:31.323

@EʀɪᴋᴛʜᴇGᴏʟғᴇʀ +56 is treated as +56+0, not +28+28. – bodqhrohro – 2016-07-13T10:16:39.427

2You can save another byte by using a recent version of ImageMagick; then the command can be "magick" instead of "convert". – Glenn Randers-Pehrson – 2016-07-13T11:17:17.187

@EʀɪᴋᴛʜᴇGᴏʟғᴇʀ, -splice's argument is geometry, superset of X's geometry.

– manatwork – 2016-07-13T13:12:35.947

26

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;
}

gcampbell

Posted 2016-07-11T09:32:23.150

Reputation: 551

2You can still save 1 byte by replacing white with #fff. – insertusernamehere – 2016-07-11T21:11:33.990

@insertusernamehere Yep, thanks. – gcampbell – 2016-07-12T05:40:06.980

1If you apply the CSS in quirks mode (page without doctype) you can bring it down to 264 bytes by omitting px everywhere. – user2428118 – 2016-07-12T10:11:18.437

@user2428118 Even more useful considering that there's no HTML, therefore no <!doctype html>! – wizzwizz4 – 2016-07-12T17:32:53.943

@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. – gcampbell – 2016-07-12T19:05:42.840

@gcampbell Stack snippets automatically insert a doctype. – user2428118 – 2016-07-13T19:04:12.207

You can replace "::" with just ":" to save 9 bytes – Solomon Ucko – 2016-07-14T23:31:59.633

@SolomonUcko I've only used :: in the ungolfed version. – gcampbell – 2016-07-15T05:41:15.683

20

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.

Philip Kendall

Posted 2016-07-11T09:32:23.150

Reputation: 475

Seeing those PAPER and BRIGHT brings so many good memories :-) – Luis Mendo – 2016-07-12T00:01:10.940

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 – Luis Mendo – 2016-07-12T00:19:40.020

1@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. – Philip Kendall – 2016-07-12T05:13:16.047

132 bytes by removing the AT and adjusting the boundary test https://twitter.com/john_metcalf/status/752760203007791105

– impomatic – 2016-07-12T07:06:47.863

1

122 bytes with some further optimizations https://twitter.com/john_metcalf/status/752783690179211264

– impomatic – 2016-07-12T08:37:40.183

Sorry for the basic question :-P How do I save and load this program into the Fuse emulator? – Luis Mendo – 2016-07-12T19:55:52.887

I love this answer :-) – Paul Drewett – 2016-07-30T02:35:24.247

15

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

impomatic

Posted 2016-07-11T09:32:23.150

Reputation: 341

14

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)

quat

Posted 2016-07-11T09:32:23.150

Reputation: 1 211

1"Whether this is accurate to the country of Iceland..." – Jordan – 2016-08-01T17:43:35.937

2Can't you just use kill @e without the target selector argument? It'll kill the player but hey the flag will still be there – Kuilin Li – 2016-12-29T04:33:34.483

11

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

GuitarPicker

Posted 2016-07-11T09:32:23.150

Reputation: 1 101

I didn't know there was an English speaking version of Logo! – Vincent – 2016-07-13T14:47:01.353

1Absolutely. 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. – GuitarPicker – 2016-07-13T14:49:18.113

Why the white border around it? – Solomon Ucko – 2016-07-14T23:37:26.800

1I 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. – GuitarPicker – 2016-07-15T14:08:06.010

10

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.

plannapus

Posted 2016-07-11T09:32:23.150

Reputation: 8 610

10

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...

R. Kap

Posted 2016-07-11T09:32:23.150

Reputation: 4 730

Try overriding paint instead of paintComponent. Consider using an anonymous class for the JPanel. Consider just using a BufferedImage and outputting to a file. – Justin – 2016-07-12T14:12:12.017

@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! :) – R. Kap – 2016-07-12T17:42:47.687

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. – Justin – 2016-07-12T18:05:17.163

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();}} – Justin – 2016-07-12T18:05:49.230

1Even 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();}} – Justin – 2016-07-12T18:11:07.490

I'm a C# guy, not Java, but they're prettying similar. Does Java require access modifiers, or could you declare things as void instead of public void? – ArtOfCode – 2016-07-12T23:25:15.940

Much better than my attempt with JavaFX. – David Conrad – 2016-07-13T02:46:50.803

@ArtOfCode In this case, it has to be public void since it overrides a public method. But otherwise, Java would be fine with it. – Justin – 2016-07-13T05:04:03.770

As it turns out, you don't need a complete program; the question says a function suffices. In that case, we can shorten it even more by removing the class (down to 285), posted on ideone to avoid the zero-width-space problem: http://ideone.com/2SpE18

– Justin – 2016-07-13T05:29:40.333

9

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

Karl Napf

Posted 2016-07-11T09:32:23.150

Reputation: 4 131

2Congratulations! You beat me by a lot :D – Gábor Fekete – 2016-07-12T13:52:31.237

2@GáborFekete beat you in bytes, yes. But your answer is much more clever with that offset – Karl Napf – 2016-07-12T14:17:00.143

Why not have the results of the escapes instead of the escapes themselves? – Solomon Ucko – 2016-07-14T23:41:04.607

@SolomonUcko I tried b,w,r="\0Hà"*28,"ÿ"*12,"×(("*8 and using Python 3, but it does not work. – Karl Napf – 2016-07-15T10:35:08.103

@KarlNapf, how did it fail? Did it draw incorrectly, or give an error message? It could also be an encoding issue. – Solomon Ucko – 2016-07-16T14:41:48.297

@SolomonUcko Output failed, was colored gibberish, so yes it is somehow an encoding issue. – Karl Napf – 2016-07-16T15:16:47.423

9

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

Locoluis

Posted 2016-07-11T09:32:23.150

Reputation: 741

8

JavaScript, 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'")

Neil

Posted 2016-07-11T09:32:23.150

Reputation: 95 035

1Sure the 7 - 14 ratio of left and right blue widths is correct? – manatwork – 2016-07-11T10:20:47.470

1@manatwork Oops, for some reason I thought 100 / 25 = 5, so everything ended up 25% too wide. – Neil – 2016-07-11T10:30:29.427

8

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

Gyan

Posted 2016-07-11T09:32:23.150

Reputation: 521

8

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

Marco13

Posted 2016-07-11T09:32:23.150

Reputation: 1 131

7

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)

edc65

Posted 2016-07-11T09:32:23.150

Reputation: 31 086

7

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">`)

nicael

Posted 2016-07-11T09:32:23.150

Reputation: 4 585

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. – Joey – 2016-07-15T05:01:41.687

7

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

Cody

Posted 2016-07-11T09:32:23.150

Reputation: 71

1You 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); – GuitarPicker – 2016-07-12T16:42:00.003

Adding on to what GuitarPicker said, fill(-1) is one byte shorter than fill(255) – user41805 – 2017-04-23T15:39:15.650

7

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

martin

Posted 2016-07-11T09:32:23.150

Reputation: 1 335

1you're welcome. same can be applied to your second longer version. u=Unitize;c=ConstantArray etc ^_^ – Dan Oak – 2016-07-12T11:36:17.943

1Wait, there's something Mathematica doesn't have a builtin for? I'm surprised. – Morgan Thrapp – 2016-07-13T20:13:11.227

@MorganThrapp I'm sure there used to be another Mathematica answer using a builtin. – gcampbell – 2016-07-14T09:12:30.403

3There is CountryData["Iceland", "Flag"] – dwa – 2016-07-18T04:51:25.490

7

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.

Dan Oak

Posted 2016-07-11T09:32:23.150

Reputation: 263

1It looks like the height of the flag is 26 units instead of 25. – Gábor Fekete – 2016-07-12T13:51:17.383

@GáborFekete hm, you meant height is 19 instead of 18? didn't mention that, just noticed after your comment – Dan Oak – 2016-07-12T14:34:25.660

Oh right I wrote height but used the width values... – Gábor Fekete – 2016-07-12T14:35:29.180

yeeeah, indeed. i made a mistake in values. the shape of initial matrix should be 14 21 (18 25 - 4 4). correcting... thank you! – Dan Oak – 2016-07-12T14:37:43.160

1You 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 – miles – 2016-07-14T06:05:24.107

7

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

Ralph Becket

Posted 2016-07-11T09:32:23.150

Reputation: 71

6

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.

FlipTack

Posted 2016-07-11T09:32:23.150

Reputation: 13 242

6

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

cdlane

Posted 2016-07-11T09:32:23.150

Reputation: 351

6

TI-BASIC (non-competing), 323 bytes

Code is written for the TI-84, 83, and variants. I sure hope it isn't an issue that dimensions vary by device, and that the code isn't colored.

Setup:

:18→Xmax:¯18→Xmin
:10→Ymin:¯10→Ymin
:AxesOff

Drawing:

:Line(¯15,9,¯8,9)
:Line(¯8,9,¯8,2)
:Line(¯8,2,¯15,2)
:Line(¯15,2,¯15,9)

:Line(¯15,¯9,¯8,¯9)
:Line(¯8,¯9,¯8,¯2)
:Line(¯8,¯2,¯15,¯2)
:Line(¯15,¯2,¯15,¯9)

:Line(¯4,9,10,9)
:Line(¯4,2,10,2)
:Line(¯4,9,¯4,2)
:Line(10,9,19,2)

:Line(¯4,¯9,10,¯9)
:Line(¯4,¯2,10,¯2)
:Line(¯4,¯9,¯4,¯2)
:Line(10,¯9,19,¯2)

:Line(¯15,1,¯7,1)
:Line(¯15,¯1,¯7,¯1)
:Line(¯5,1,20,1)
:Line(¯5,¯1,¯20,¯1)
:Line(¯7,¯1,¯7,¯9)
:Line(¯5,¯1,¯5,¯9)
:Line(¯7,1,¯7,9)
:Line(¯5,1,¯5,9)

Golfed:

:18→Xmax:¯18→Xmin:10→Ymin:¯10→Ymin:AxesOff:Line(¯15,9,¯8,9:Line(¯8,9,¯8,2:Line(¯8,2,¯15,2:Line(¯15,2,¯15,9:Line(¯15,¯9,¯8,¯9:Line(¯8,¯9,¯8,¯2:Line(¯8,¯2,¯15,¯2:Line(¯15,¯2,¯15,¯9:Line(¯4,9,10,9:Line(¯4,2,10,2:Line(¯4,9,¯4,2:Line(10,9,19,2:Line(¯4,¯9,10,¯9:Line(¯4,¯2,10,¯2:Line(¯4,¯9,¯4,¯2:Line(10,¯9,19,¯2:Line(¯15,1,¯7,1:Line(¯15,¯1,¯7,¯1:Line(¯5,1,20,1:Line(¯5,¯1,¯20,¯1:Line(¯7,¯1,¯7,¯9:Line(¯5,¯1,¯5,¯9:Line(¯7,1,¯7,9:Line(¯5,1,¯5,9

Yes, the lack of ) is intentional.

Size:

Line( and all commands like that take up 1 byte, each number takes a byte. That's 323 bytes.

That was absolutely tedious. I'll get this on an emulator hopefully (I have to manually enter everything) but it's literally just lines in the shape of the flag.

charredgrass

Posted 2016-07-11T09:32:23.150

Reputation: 935

Do commands like this really only take one byte? What is the value of the byte? – Random832 – 2016-07-11T13:19:18.393

1

@Random832 Oddly enough, yes! Check the token size here: http://tibasicdev.wikidot.com/line I'm not sure what the byte is exactly. However I do know that on the calculator, it is treated essentially as a char.

– charredgrass – 2016-07-11T13:38:11.797

1

@Random832 The byte for Line( is 0x9C. You can see a table of one-byte tokens here: http://tibasicdev.wikidot.com/one-byte-tokens

– f'' – 2016-07-11T14:12:14.703

1Couldn't you graph using regions (using < and >) instead of lines to get greyscale shading? – mbomb007 – 2016-07-11T16:51:29.303

7Why is this non-competing? – Mego – 2016-07-11T22:55:21.203

1Note that there is now a color TI-84, so you could probably run it on there with only minor modifications. – Moshe Katz – 2016-07-13T07:10:01.210

@Mego Doesn't fit the requirements for colors exactly. – charredgrass – 2016-07-13T07:21:29.427

@MosheKatz I am aware (and quite jealous of anyone with a TI-84C). However I have no idea how exactly to do that as I've never gotten my hands on one. Might try an emulator later if I can get it to run at an acceptable speed on my computer. – charredgrass – 2016-07-13T07:22:32.573

@charredgrass If it doesn't use the exact colors, non-competing has nothing to do with it. Relevant meta post. You should ask the OP for clarification, though, since the only current allowance is using the ANSI values for red, white, and blue, rather than the exact values.

– Mego – 2016-07-13T07:24:47.583

I would try to make it competing if you can. I mean, it's not like you're trying to subvert the rules to save on bytes, you're using what is available to you. – corsiKa – 2016-07-13T20:15:18.227

6

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

soema

Posted 2016-07-11T09:32:23.150

Reputation: 61

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.

– Katenkyo – 2016-07-13T14:37:20.043

Thanks, spaces are removed and I delete the using statement, too. I also use anonymous variables now. – soema – 2016-07-13T14:42:18.517

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.

– manatwork – 2016-07-13T14:49:26.617

Yes! Just save now and no opening more ... – soema – 2016-07-13T14:59:28.843

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). – Joey – 2016-07-15T10:06:27.243

5

Excel VBA, 126 112 111 Bytes

This is an immediates window function that outputs to the Application.ThisWorkbook.Activesheet object

Golfed:

Cells.RowHeight=48:[A1:G7,A12:G18,L1:Y7,L12:Y18].Interior.Color=-2078720:[A9:Y10,I1:J18].Interior.Color=2631895

Ungolfed:

Sub MakeIcelandicFlag()
    Let Cells.RowHeight = 48
    Let Range("A1:G7,A12:G18,L1:Y7,L12:Y18").Interior.Color = -2078720
    Let Range("A9:Y10,I1:J18").Interior.Color = 2631895
End Sub

-14 Bytes by converting Range(/*Address*/) calls to [/*Address*/]calls

-1 Byte for converting Cells.ColumnWidth=2to Cells.RowHeight=48

Output:

I'm the Flag!

Taylor Scott

Posted 2016-07-11T09:32:23.150

Reputation: 6 709

I think the red strips have to be 2 cells wide - see 5th bullet in question – MildlyMilquetoast – 2017-01-05T03:58:05.027

@Mistah Figgins it has been corrected, Thanks for the catch! – Taylor Scott – 2017-01-05T04:06:28.407

5

Perl, 134 bytes

Note: \x1b is actually the ASCII escape character and counts as 1 byte

($b,$w,$r)=map"\x1b[48;5;${_}m",18,15,1;print@l=("$b "x7,"$w $r  $w $b",$"x14,$/)x7,@m=("$w "x8,"$r  ","$w "x15,$/),("$r "x25,$/)x2,@m,@l

Usage

Save as iceland-flag.pl and run via:

perl iceland-flag.pl

Squished flag

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

Perl, 141 bytes

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

($b,$w,$r)=map"\x1b[48;5;${_}m",18,15,1;print@l=("$b "x14,"$w  $r    $w  $b",$"x28,$/)x7,@m=("$w "x16,"$r "x4,"$w "x30,$/),("$r "x50,$/)x2,@m,@l

Less squished flag

Dom Hastings

Posted 2016-07-11T09:32:23.150

Reputation: 16 415

1The weirdness comes from the fact that characters are taller than their width. – Erik the Outgolfer – 2016-07-13T09:22:28.583

@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...) – Dom Hastings – 2016-07-13T09:36:49.400

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. – Erik the Outgolfer – 2016-07-13T09:42:58.887

5

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

Brian

Posted 2016-07-11T09:32:23.150

Reputation: 1 209

Do you need spaces after each :? Oh, and it's 151 bytes. – Erik the Outgolfer – 2016-07-13T13:16:16.070

5

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

acrolith

Posted 2016-07-11T09:32:23.150

Reputation: 3 728

3Why is this marked "Non-competing"? Usually, that is reserved for using a language that's newer than the challenge. – James – 2016-07-12T20:18:54.420

Because the blue is brighter than the flag's blue. – acrolith – 2016-07-12T20:24:00.427

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. – James – 2016-07-12T20:25:51.627

4@daHugLenny Since the contest allows for ANSI colors if necessary, I'm sure this would be fine. – MCMastery – 2016-07-12T20:26:55.320

@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. – Lynn – 2016-07-30T19:07:04.497

@MCMastery In that case it isn't "non-competing". This is either a valid competing answer, or its not and is subject to deletion -- there's no middle state. – pppery – 2019-10-10T02:59:34.287

4

PowerShell v2+, 379 340 289 286 bytes

nal n New-Object
Add-Type -A *.Dr*g,S*ms
$x='$g.FillRectangle((n Drawing.SolidBrush '
($f=n Windows.Forms.Form).Add_paint({$g=$args[1].Graphics;"$x'#0048e0'),0,0,100,72);$x white),28,0,16,72);$x white),0,28,100,16);$x'#d72828'),32,0,8,72);$x'#d72828'),0,32,100,8)"|iex})
$f.ShowDialog()

Linebreaks and semicolons count the same, so linebreaks left in for clarity. ;-)

So, drawing in PowerShell is not its strong suit -- it needs to use lengthy .NET assembly imports and GDI+ function calls.

Saved 39 bytes saved thanks to TessellatingHeckler's answer, and another 51 bytes thanks to Joey's impressive golfing commentary. Thanks to them both!

We start with creating a New-Alias n and assign it New-Object. We can thus reference just n instead of New-Object elsewhere in the program. Next is the import calls, with wildcards -- we're importing System.Drawing and System.Windows.Forms. We then create a variable $x that we use for several repeated calls in the future, so we're not needing to type it out every time.

The next line is the meat-and-potatoes of the program. We start with setting $f as a new Windows.Forms.Form and immediately call the Add_paint() routine on it.

Inside the paint routine, the first line is to create our graphics component, $g, that we'll use as our canvas. The next line is actually a constructed string that we pass to iex (similar to eval) so that we can leverage the $x variable from above. We're simply drawing the blue background, then two white rectangles, followed by two red rectangles. We adjust the values appropriately each time and pipe it to the Invoke-Expression.

The final line simply shows the dialog form as we've drawn it above.

Iceland Flag

Note that since we're creating a form object, and PowerShell is all about the pipeline, closing the pop-up form will pass along a System.Enum.DialogResult object of Cancel, since that's technically what the user did. Since we're not capturing or otherwise doing anything with that result, the word Cancel will be displayed to STDOUT when the program concludes, as it was left on the pipeline. That can be suppressed by adding >$a to the end of the last line, if so required, so the output redirects into a throwaway variable.

AdmBorkBork

Posted 2016-07-11T09:32:23.150

Reputation: 41 581

If you pinch the start of my script here: http://codegolf.stackexchange.com/a/59110/571 - you can drop to a single Add-Type call, and reuse the same string for adding the System.Windows.Forms type and creating the object.

– TessellatingHeckler – 2016-07-12T00:27:50.123

@TessellatingHeckler Oh, that's excellent. I tweaked it around a little bit more and squeezed a few additional bytes out. Additionally, dropped the height/width setting of the form - the default (at least v4 on Win8.1) seems fine. – AdmBorkBork – 2016-07-12T12:39:24.673

@Joey Wow, thanks for the massive golf. I left the nal in so it's for v2+, so it's at 289 now. – AdmBorkBork – 2016-07-15T12:54:00.630

@Joey True, but if I surround it in quotes or prepend two grave accents, it's still two bytes each. Saved the quotes for white, though. – AdmBorkBork – 2016-07-15T13:51:46.527

@AdmBorkBork the Add-Type can be shortened to Add-Type -A S*ms – root – 2017-07-09T01:34:56.487

@root Are you sure? I get an error that Drawing isn't recognized when I try that on my machine. – AdmBorkBork – 2017-07-18T13:02:49.293

@AdmBorkBork Working for me, version 5.1.15063.483 – root – 2017-07-24T17:47:23.123

4

GLSL, 266 265 bytes (non-competing)

Just for fun!

Only input it takes is the uniform which is the resolution of the texture it draws to. Needs an existing OpenGL context. The function r masks a rectangular area. The colors and the proportions are a bit off but looks believable.

#define r(p,w,h)step(abs(p.x),w)*step(abs(p.y),h)
uniform vec2 R;void main(){vec2 p=-1.+2.*gl_FragCoord.xy/R;p.y*=R.y/R.x*1.39;vec2 q=p;p.x+=.3;p=mod(p,2.)-1.;gl_FragColor.rgb=mix(mix(vec3(.83,.15,.15),vec3(1.),r(p,.9,.85)),vec3(0.,.28,.95),r(p,.8,.7))*r(q,1.,1.);}

Gábor Fekete

Posted 2016-07-11T09:32:23.150

Reputation: 2 809

1Can you do #define r(p,w,h)step(abs(p.x),w)*step(abs(p.y),h)? – Erik the Outgolfer – 2016-07-13T09:49:42.667

Yes that works! Thank you! – Gábor Fekete – 2016-07-13T10:14:24.020

https://codegolf.stackexchange.com/a/85518/6485 — you might want to look at this answer (it's also in GLSL but even smaller) – Display Name – 2016-07-16T15:11:50.270

Thanks, I could help to save some bytes on that code. My solution works in a general GLSL context, his on shadertoy which has uniforms defined and has a change in the main function to work with arguments. – Gábor Fekete – 2016-07-16T16:30:33.890

4

Vim, 49 keystrokes

25i<Ctrl+k>:S<Esc>yy17pqal<Ctrl+v>G$khhqr<Space>j@akhr<Ctrl+k>?SGV8kdggP<Ctrl+v>G15ld$p

I'm certain it could be golfed more, but there you have it. I spent some extra keystrokes on the :S (MEDIUM SHADE) and ?S (DARK SHADE) digraphs for a result I'm pretty happy with:

Icelandic flag in Vim

Explanation:

25i<Ctrl+k>:S<Esc>yy17p  " Draw 18 lines of "blue" blocks
qa                       " Start recording macro "a"
  l<Ctrl+v>G$khh           " Visual-block select the inner rectangle
q                        " Stop recording
r<Space>                 " Replace rectangle with spaces
j@akh                    " Select next inner rectangle
r<Ctrl+k>?S              " Replace rectangle with "red" blocks
GV8kdggP                 " Cut the last 9 lines and paste them before the first line
<Ctrl+v>G15ld$p          " Cut the first 16 columns and paste them after the last column

If I have some time later I'll try to record a GIF of it in action.

Jordan

Posted 2016-07-11T09:32:23.150

Reputation: 5 001

1I love seeing vim answers since there is a good chance you'll discover something new in the huge feature set of vim. This time for me: digraphs. Not as big a revelation as discovering o in visual mode, but still a useful thing to know. – algmyr – 2016-07-30T18:59:59.767

3

Befunge, 126 124 bytes

99>+1-:00p0 >:01-\100g>:::9`\55+`+\8\v
@_^#!:,+55$_^#`*46:+1<|!`\0:\*+`\7\+`<
"[",5g,4g,3g," m",:,,^>$1+2/::39*,
174
404
010

2 bytes golfed thanks to Zacharý

This is a text solution using ANSI escape sequences to set the colours. It outputs 50x18 characters rather than 25x18 (doubling the horizontal resolution), since that more closely matches the required dimensions when the characters aren't square. If you prefer the 25x18 resolution, though, you can simply replace the :, on line 3 with two spaces.

Sample Output

Rendering of the Iceland flag

(exact colours may vary depending on the operating system)

James Holderness

Posted 2016-07-11T09:32:23.150

Reputation: 8 298

I know that this is over a year old, but 9*,"[",5g,4g,3g," m",,^>$1+2/::3 would save 2 bytes on the third line if you use the 25x18 resolution. – Zacharý – 2018-07-16T17:25:16.393

It seems that this works for -4 bytes!

– Zacharý – 2018-07-16T17:37:39.027

@Zacharý I don't think the 25x18 version really counts, because it's not the right shape, but that trick you used to compress the top loop is rather brilliant. Thanks. – James Holderness – 2018-11-28T18:51:25.743

Thanks, golfing syntax is what I do best on other people's code – Zacharý – 2018-11-28T20:44:14.720

3

HTML+CSS, 276 258 254 234 bytes

Ridiculously quite long compared to the SVG+JS solution.

*{position:fixed;background:#fff}e,f{background:#d72828}a{background:#0048e0}c{top:36px;height:16px}d{left:36px;width:16px}e{top:40px;height:8px}f{left:40px;width:8px;}d,f,a{height:72px;top:8px}a,c,e{left:8px;width:100px
<a><c><d><e><f

nicael

Posted 2016-07-11T09:32:23.150

Reputation: 4 585

1*{position:fixed} should do it. And it's 18 bytes shorter than a,a *{display:block;position:fixed}. – insertusernamehere – 2016-07-11T21:02:47.337

1@insert Indeed, thanks for that. The other way I was working with failed though. – nicael – 2016-07-11T21:09:39.210

This should save you another 12 bytes: *{position:fixed;background:#fff}e,f{background:#d72828}a{background:#0048e0}c{top:36px;height:16px}d{left:36px;width:16px}e{top:40px;height:8px}f{left:40px;width:8px}d,f{top:8px}c,e{left:8px}a,c,e{width:100px}d,f,a{height:72px, fiddle.

– insertusernamehere – 2016-07-11T21:20:31.720

1@insert Thanks again, saved 20 with your hints :) – nicael – 2016-07-11T21:59:10.793

@insertusernamehere: looks fine here, but when copied to a regular document (in every Browser I have installed on all my machines: Windows 10, Ubuntu, Android, iPhone), fis not displayed. – Titus – 2016-07-12T10:49:24.187

@insertusernamehere You need the > in most cases! The real test (opening it with a browser) won't work there. Also, sometimes you even need <a/><c/><d/><e/><f/> or, even worse, <a></a><c></c><d></d><e></e><f></f>! – Erik the Outgolfer – 2016-07-13T09:26:54.273

@EʀɪᴋᴛʜᴇGᴏʟғᴇʀ @Titus - You're both correct. I somehow thought, that the browser will wrap it in a <body>-element implicitly. But this is not the case. Removed the suggestion. – insertusernamehere – 2016-07-13T09:35:42.137

@insertusernamehere <html> and <body> elements are in fact implicit, but <a_half_of_a_tag_without_a_greater_than_symbol_at_the_end is considered pure text. – Erik the Outgolfer – 2016-07-13T09:38:41.450

@EʀɪᴋᴛʜᴇGᴏʟғᴇʀ Ah OK, got it. The browser corrects the "mistake" if any other tag follows explicitly. If not, it wraps everything in <body>and drops the incorrect tag – at least the inspector in Safari and Chrome won't show <f anymore. – insertusernamehere – 2016-07-13T09:45:17.370

3

bash, 239 161 bytes

took the closest colors I could find in ANSI
golfed by a third (an amazing 78 bytes) with manatwork´s tips

a="${u=${e=\e[48;5};20m}${s=       }${w=$e;231m} ${r=$e;124m}  $w $u$s$s${n=\e[0m
}"
printf "${t=$a$a$a$a$a$a$a}${b=$w$s $r  $w $s$s$n}${c=$r$s    $s$s$n}$c$b$t"

ungolfed (184 bytes + comments)

u='\e[48;5;20m'             # color blUe
r='\e[48;5;124m'            # color Red
w='\e[48;5;231m'            # color White
#presets:
n="\e[0m\n"                 # No color + New line
s='       '                 # 7*chr(32)

# lines:
a="$u$s$w $r  $w $u$s$s$n"  # blue-white-red-white-blue
b="$w$s $r  $w $s$s$n"      # white-red-white
c="$r$s    $s$s$n"          # all red

# output:
t="$a$a$a$a$a$a$a"          # 7* line $a
printf "$t$b$c$c$b$t"

output pretty distorted due to character aspect ratio:

Titus

Posted 2016-07-11T09:32:23.150

Reputation: 13 814

1

You could pack it to 159 characters without changing the base principle: http://pastebin.com/8YKAR7Mn (^[ is a literal escape character counted as 1). Regarding those function declarations, see Dennis's related tip in Tips for golfing in Bash.

– manatwork – 2016-07-13T07:56:11.007

@manatwork: A) Wow didn´t know about the variable definition in strings. B) ^[ doesn´t seem to work - what bash version is that? C) Same for the function definitions: a(){for i ...} => unexpected "{for" (a()(...) works) – Titus – 2016-07-13T09:53:14.730

A) See ${parameter:=word} in man bash. B) ^[ is the graphic image of the escape character. In command line and Vim you enter it with Ctrl+v, Esc, in MCEdit and Emacs with Ctrl+Q, Esc. (In MCEdit you may need a second Esc too, depending on configuration.) C) You have to add delimiters where required by syntax – a space after { and a ; before the }: a(){ for i ...;}.

– manatwork – 2016-07-13T10:27:58.707

so basically you used magic. That's pretty amazing tbh. – Bjorn – 2017-04-09T22:19:10.273

3

Python 3.5 + Tkinter, 235 bytes:

from tkinter import*;C=Canvas(Tk(),height=126,width=175,bg='#d72828');C.pack();X=lambda*a:C.create_rectangle(a,fill='#0048E0',outline='#fff',width=7);X(0,0,8,8);X(0,11,8,19);X(11,0,26,8);X(11,11,26,19);C.scale('all',0,0,7,7);mainloop()

Really long, but happy with it regardless. Basically creates a canvas with a red background and then draws 4 blue rectangles with white borders over the background in the 4 corners. After the drawing is all done, the canvas is enlarged by a scale factor of 7. Displays the completed flag in a new window on a canvas with the dimensions 175 x 126.

Image of Output:

Output

R. Kap

Posted 2016-07-11T09:32:23.150

Reputation: 4 730

3

Lua + LÖVE, 212 characters

f="fill"l=love
g=l.graphics
c=g.setColor
r=g.rectangle
l.window.setMode(100,72)function
l.draw()g.setBackgroundColor(0,72,224)c(-1,-1,-1)r(f,28,0,16,72)r(f,0,28,100,16)c(215,40,40)r(f,32,0,8,72)r(f,0,32,100,8)end

Sample output:

flag on Iceland

manatwork

Posted 2016-07-11T09:32:23.150

Reputation: 17 865

2

TI-Basic (TI-84 Plus CE), 76 74 bytes

9→Ymax
-9→Ymin
16→Xmax
-9→Xmin
AxesOff
For(A,-9,9,.2
DrawF A/(X2>4 and A2>4),10
DrawF A/not(X2>1 and A2>1),11
End

This was created independently of charredgrass's answer.

-2 bytes from lirtostat

TI-Basic is a tokenized language. Ymax, Ymin, Xmax, Xmin, and AxesOff are two-byte tokens; all other tokens used are one-byte tokens.

Possibly non-competing due to color values (blue 0x0000FF, white 0xFFFFFF, red 0xFF0000).

It takes quite a while to run, but it works.

9→Ymax                           # 5 bytes, adjust window
-9→Ymin                          # 6 bytes
16→Xmax                          # 6 bytes
-9→Xmin                          # 6 bytes
AxesOff                          # 3 bytes, remove axes
For(A,-9,9,.2                    # 11 bytes, for each Y-value, -9 to 9, by 0.2
DrawF A/(X2>4 and A2>4),10       # 20 18 bytes, draw a blue point if Y^2>4 and X^2>4
DrawF A/not(X2>1 and A2>1),11    # 18 bytes, draw a red point if Y^2 or X^2 is less than 1
End                              # 1 byte

pizzapants184

Posted 2016-07-11T09:32:23.150

Reputation: 3 174

1(X^2>4)/(A^2>4) -> X^2>4 and A^2>4? – lirtosiast – 2018-12-01T04:54:09.563

2

C - Win32 GDI 180 bytes

#include <Windows.h>
main(i,x,y,h,v){for(i=0;i<180000;i++)h=(x=i%500)/20,v=(y=i/500)/20,SetPixelV(GetDC(0),x,y,h>7&&h<10||v>7&&v<10?2631895:h>6&&h<11||v>6&&v<11?16777215:9910272);}

Very slowly draws the flag onto the desktop:

enter image description here

Johan du Toit

Posted 2016-07-11T09:32:23.150

Reputation: 1 524

Why SetPixelV ? Can't it be SetPixel ? – sergiol – 2017-07-08T11:22:00.290

2

Tcl/Tk, 180 162 158

pack [canvas .c -w 100 -he 72 -bg #0048e0]
proc D {L f\ d72828} {.c cr r $L -w 0 -f #$f}
D "28 2 44 74" fff
D "2 28 102 44" fff
D "32 2 40 74"
D "2 32 102 40"

enter image description here

Stupid margin at the end forced me to use 102 instead of 99; I could save two bytes.

sergiol

Posted 2016-07-11T09:32:23.150

Reputation: 3 055

1

Visible at the right on http://i.imgur.com/m0bCgwT.png — you will see a vertical blue line where it shouldn't be.

– sergiol – 2017-07-09T15:40:26.983

1

@insertusernamehere On an unrelated thing, I finally discovered the origin of the "stupid margin"; the highlightthickness attribute of canvas is by default 2 (instead of 0) — https://stackoverflow.com/a/4311134/383779

– sergiol – 2017-09-03T09:57:19.527

2

PaperScript, 149 bytes

R=Path.Rectangle
for(y=0;y<88;y+=44)R(0,y,28,28).fillColor=R(44,y,56,28).fillColor="#0048e0"
R(0,32,100,8).fillColor=R(32,0,8,72).fillColor="#d72828"

PaperScript is an extension of JavaScript based on the Paper.js vector graphics library. You can run PaperScript code directly, without having to mess with the HTML and CSS, at sketch.paperjs.org.

The code uses a loop to draw the top two blue rectangles, then the bottom two. It then adds two red rectangles to complete the flag. Try it at Paper.js Sketch!

Ungolfed

for (var y = 0; y < 88; y += 44) {
    new Path.Rectangle({
        point: [0, y],
        size: [28, 28],
        fillColor: "#0048e0"
    });
    new Path.Rectangle({
        point: [44, y],
        size: [56, 28],
        fillColor: "#0048e0"
    });
}
new Path.Rectangle({
   point: [0, 32],
   size: [100, 8],
   fillColor: "#d72828"
});
new Path.Rectangle({
   point: [32, 0],
   size: [8, 72],
   fillColor: "#d72828"
});

Output

Iceland flag

DLosc

Posted 2016-07-11T09:32:23.150

Reputation: 21 213

2

PostScript, 152 150 149 bytes

Golfed version:

9 9 scale 0 .282 .878 setrgbcolor 0 0 25 18 rectfill 1 setgray[0 7 25 4 7 0 4 18]rectfill .843 .157 dup setrgbcolor[0 8 25 2 8 0 2 18]rectfill showpage

Ungolfed version:

9 9 scale                     % over-all scaling
0 .282 .878 setrgbcolor       % set blue color
0 0 25 18 rectfill            % blue rectangle
1 setgray                     % set white color
[0 7 25 4 7 0 4 18] rectfill  % white cross
.843 .157 dup setrgbcolor     % set red color
[0 8 25 2 8 0 2 18] rectfill  % red cross
showpage

Result:

result

Thomas Fritsch

Posted 2016-07-11T09:32:23.150

Reputation: 361

2

Javascript console, 242 bytes

c='background:#';r=c+'d72828;';b=c+'0048e0;';w=c+'fff;';console.log(('%c  '[E='repeat'](25)+'\n')[E](18),...((t=(v='b'[E](7))+'wrrw'+v+v)[E](7)+(o=(j='w'[E](7))+'wrrw'+j+j)+'r'[E](50)+o+t[E](7)).replace(/(.)/g,a=>eval(a)).slice(0,-1).split`;`)

enter image description here

Charlie Wynn

Posted 2016-07-11T09:32:23.150

Reputation: 696

2

Java with ANSI escape codes, 278 bytes

interface R{static void main(String[]a){String x=o(0,0)+"\n",l=o(4,7)+o(7,1)+o(1,2)+o(7,1)+o(4,14)+x,t=l+l+l+l+l+l+l,r=o(1,12)+o(1,13)+x,q=o(7,8)+o(1,2)+o(7,15)+x;System.out.print(t+q+r+r+q+t);}static String o(int c,int l){return"\33[4"+c+"m"+"               ".substring(0,l);}}

slady

Posted 2016-07-11T09:32:23.150

Reputation: 21

Remove the space after the class name, shorten the name of the args parameter to a single character, reduce the octal escape to \33 and don't count the unnecessary trailing newline character. That brings your count down to 282. – Joey – 2016-07-15T09:49:25.977

Change the class to an interface and remove the public from the method declaration. You can also remove the space after the return. This brings it down to 278. – Joey – 2016-07-15T10:01:45.820

Thanks you Joey, I added your ideas, now I am at 278 bytes, great job! =) – slady – 2016-07-19T10:27:22.017

2

JavaFX, 527 bytes

import javafx.scene.*;import javafx.scene.paint.*;import javafx.scene.shape.Rectangle;public class I extends javafx.application.Application{public void start(javafx.stage.Stage s){Color w=Color.WHITE;Paint z=Paint.valueOf("#d72828");Group g=new Group();Scene n=new Scene(g,250,180,Color.valueOf("#0048e0"));g.getChildren().addAll(r(70,0,40,180,w),r(0,70,250,40,w),r(0,80,250,20,z),r(80,0,20,180,z));s.setScene(n);s.show();}Rectangle r(int x,int y,int w,int h,Paint p){Rectangle r=new Rectangle(x,y,w,h);r.setFill(p);return r;}}

Two red rectangles on two white rectangles on a blue background.

Ungolfed:

import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.shape.Rectangle;

public class I extends javafx.application.Application {
    public void start(javafx.stage.Stage s) {
        Color w = Color.WHITE;
        Paint z = Paint.valueOf("#d72828");
        Group g = new Group();
        Scene n = new Scene(g, 250, 180, Color.valueOf("#0048e0"));
        g.getChildren().addAll(
            r(70, 0, 40, 180, w),
            r(0, 70, 250, 40, w),
            r(0, 80, 250, 20, z),
            r(80, 0, 20, 180, z));
        s.setScene(n);
        s.show();
    }

    Rectangle r(int x, int y, int w, int h, Paint p) {
        Rectangle r = new Rectangle(x, y, w, h);
        r.setFill(p);
        return r;
    }
}

(Weirdly, if I change it to import javafx.scene.shape.*; it won't compile with Java 1.8.0_92. I'm not sure if that's a bug.)

David Conrad

Posted 2016-07-11T09:32:23.150

Reputation: 1 037

2

Ruby with Shoes, 150 149 characters

Shoes.app(width:100,height:72){background'0048e0'
stroke fill'fff'
rect 28,0,15,72
rect 0,28,99,15
stroke fill'd72828'
rect 32,0,7,72
rect 0,32,99,7}

Thanks to:

Sample output:

flag on Iceland

manatwork

Posted 2016-07-11T09:32:23.150

Reputation: 17 865

Can't do fill'fff' instead of fill white for -1? – Erik the Outgolfer – 2016-07-13T12:10:35.643

Doh. You are right, @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ. I remembered having some issues with shortening hex color codes earlier and not tried it this time. – manatwork – 2016-07-13T12:28:17.083

2

R/ggplot2, 273 bytes 270 bytes

Since we have a couple base R answers we obviously need a ggplot answer. One of the few areas where base might be better ;)

library(ggplot2);ggplot(data.frame(a=c(0,7,0,8,0),b=c(25,11,25,10,25),c=c(0,0,7,0,8),d=c(18,18,11,18,10),e=paste(c(1,2,2,3,3))),aes(xmin=a,xmax=b,ymin=c,ymax=d,fill=e))+geom_rect()+scale_fill_manual(values=c('#0048e0','white','#d72828'),g=F)+theme_void();ggsave('o.png')

Output

Iceland

Ungolfed

library(ggplot2)

ggplot(
  data.frame(xmin = c(0,  7,  0,  8,  0),
             xmax = c(25, 11, 25, 10, 25),
             ymin = c(0,  0,  7,  0,  8),
             ymax = c(18, 18, 11, 18, 10),
             fill = paste(c(1, 2, 2, 3, 3)))
) +
aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax, fill = fill)+
geom_rect() +
scale_fill_manual(values = c('#0048e0', 'white', '#d72828'), g = FALSE) +
theme_void()

ggsave('o.png')

Edit: Thanks to plannapus for suggesting a way to shorten the fill specification.

Mhairi McNeill

Posted 2016-07-11T09:32:23.150

Reputation: 121

I don't actually use ggplot2 often but isn't it possible to fill argument fill with integers rather than character strings? As in c(1,2,2,3,3)? If not, you can still coerce them into characters with paste, and it'd still be shorter: paste(c(1,2,2,3,3)) is 19 bytes instead of the 22 of c('a','b','b','c','c'). – plannapus – 2016-07-15T08:19:08.733

Can't be numeric or it will try fill with a gradient. Paste is a very good idea though! – Mhairi McNeill – 2016-07-15T09:30:38.247

2

FLIF, 48 bytes

I'm surprised that no (bitmap) image formats have been used as answers here. A well compressed PNG comes in at a respectable 132 bytes (thanks to tools like pngout, pngcrush and optipng). However, I encountered another intriguing format that does even better! Using FLIF (Free Lossless Image Format) and some manual trimming I got down to 48 bytes:

4c46 4649 3133 6400 4800 4023 eb51 1272
9034 113b 7727 a2b6 fdac dc4e c1ae 6cf8
4a00 fc03 2064 7772 dc38 97a7 63f2 0a03

Viewing the image with viewflif gives the expected output:

Iceland flag, screenshot of rendered FLIF file

EDIT: Added link to FLIF web site.

algmyr

Posted 2016-07-11T09:32:23.150

Reputation: 858

2

SVG+HTML, 134

<svg><path d="m0,2h100v72H0"fill="#0048e0"/><path d="M0 32H30V0h12V32h60v12H42V76H30V44H0"fill='#d72828'stroke="#fff"stroke-width='4'>

Cheated a bit in that the rectangle is slightly offset so that I can use a second path with a red fill and white outline to draw the cross. This emerged as an idea while making suggestions to golf nicael's SVG+JS answer further and ended up as a complete rewrite of the SVG in question. In fact, this is pure SVG anyway, it just needs the HTML parser, so has to be put into an HTML file.

Joey

Posted 2016-07-11T09:32:23.150

Reputation: 12 260

2

HTML+CSS, 225 bytes

I liked Nicael's answer, but I found a way to draw the bars in less bytes.

   *{position:fixed;width:100px;margin:0}a{background:#0048E0;height:72px}b,c{box-shadow:0 0 0 4px #FFF;}b,c,d{background:#D72828}b,d{width:8px;left:32px}b{height:72px}c{height:8px;top:32px}d{height:16px;top:28px
<a><b></b><c><d>

scoota269

Posted 2016-07-11T09:32:23.150

Reputation: 121

box-shadow is a nice idea. – Joey – 2016-07-15T07:49:12.437

2

HTML+CSS, single element, 321

<p style="width:100;height:72;background:linear-gradient(0deg,transparent 44.4%,#D72828 44.5%,#D72828 55.6%,transparent 55.7%),linear-gradient(90deg,transparent 28%,#fff 28.1%,#fff 32%,#D72828 32.1%,#D72828 40%,#fff 40.1%,#fff 44%,transparent 44.1%),linear-gradient(0deg,#0047E0 38.9%,#fff 39%,#fff 61.1%,#0047E0 61.2%)">

Needs quirks mode to run, so the snippet below has the errors fixed:

<p style="width:100px;height:72px;background:linear-gradient(0deg,transparent 44.4%,#D72828 44.5%,#D72828 55.6%,transparent 55.7%),linear-gradient(90deg,transparent 28%,#fff 28.1%,#fff 32%,#D72828 32.1%,#D72828 40%,#fff 40.1%,#fff 44%,transparent 44.1%),linear-gradient(0deg,#0047E0 38.9%,#fff 39%,#fff 61.1%,#0047E0 61.2%)">

Joey

Posted 2016-07-11T09:32:23.150

Reputation: 12 260

2

SVG pattern, 250

<svg><pattern id="a"width=9 height=9 patternUnits="userSpaceOnUse"patternTransform="translate(55,55),scale(10)"><path d="M0,0H7V7H0" fill="#0048e0"/><path d="M8,0V9M9,8H0"stroke="#d72828"fill="none"/></pattern><path d="M0,0H125V90H0" fill="url(#a)"/>

A square blue path, a red stroke (of default stroke-width) and all that scaled and offset into another path. Needs to be placed into HTML to work.

Klaus Hilgenfelder

Posted 2016-07-11T09:32:23.150

Reputation: 21

Welcome to PPCG! – Erik the Outgolfer – 2016-07-15T13:08:57.563

2

TRS-80 Color Computer BASIC, 133 bytes

This one is a little off on the widths, but some of that is due to characteristics of the semi-graphics mode. In the emulator, the screen is 512x384 even though the actual programming is lower resolution. This color mode only supports 8 colors plus black, and the algorithm is a sort of threshold heat map which is using math to determine the color value to use if it gets within a certain range of the cross axes. The number 3 is blue, 5 is white, and 4 is red. Logical TRUE is -1, and FALSE is 0, so I leveraged that to add two to blue to make white, and subtract one to made red. I could have golfed further and removed some decimals sacrificing accuracy to gain 16 bytes.

1FORY=0TO31:FORX=0TO63:C=3-2*((ABS(21.5-X)<5.5)OR(ABS(15.5-Y)<4.5))+((ABS(21.5-X)<3.5)OR(ABS(15.5-Y)<2.5)):SET(X,Y,C):NEXT:NEXT:GOTO1

enter image description here Ungolfed, and more conventional styling:

10 FOR Y=0 TO 31
20 FOR X=0 TO 63
30 C=3-2*((ABS(21.5-X)<5.5) OR (ABS(15.5-Y)<4.5)) + ((ABS(21.5-X)<3.5) OR (ABS(15.5-Y)<2.5))
40 SET(X,Y,C)
50 NEXT X
60 NEXT Y
70 GOTO 10

I used the JS Mocha online interpreter, which made me feel all warm and fuzzy and want to take my CoCos out of the attic.

Technically, I didn't need to have the last GOTO statement (6 bytes), but I left it in to keep the final result from scrolling off the screen a couple of lines as soon as it finished drawing.

GuitarPicker

Posted 2016-07-11T09:32:23.150

Reputation: 1 101

2

GLSL + shadertoy, 193 190 187 179 bytes

void mainImage(out vec4 f,vec2 p){vec2 a=abs(p/iResolution.xy*vec2(25,18)-9.);int c=int(min(a.x,min(a.y,2.)));f=vec4(c==0?vec3(215,40,40):c==1?vec3(255):vec3(0,72,224),255)/255.;}

The aspect ratio will be correct as long as the window/screen size is 25:18.
Can be tested at https://www.shadertoy.com/new
I wanted to use an array lookup in the last statement, but it seems I can't really make an array of vectors :/
Additional thanks going to @GáborFekete for tips for further golfing. Screenshot: Screenshot

Display Name

Posted 2016-07-11T09:32:23.150

Reputation: 654

1You can save 3 bytes by removing the in keyword in the mainImage argument. – Gábor Fekete – 2016-07-16T16:08:22.233

Oh yeah, forgot about it. Thank you! – Display Name – 2016-07-16T16:09:21.790

Also remove trailing zeros in floating values. And I'm not sure if it works on all browsers and OSes but try to assign only the .rgb values of the variable f. – Gábor Fekete – 2016-07-16T16:23:01.040

trailing zeroes are necessary, without them there are "incompatible types" errors. (maybe it also works slightly differently depending on implementation) also I guess the second suggestion would be UB, but maybe I'll try later – Display Name – 2016-07-16T16:53:35.123

1I meant write 2. instead of 2.0. – Gábor Fekete – 2016-07-16T17:30:02.460

Wow. Didn't know about this – Display Name – 2016-07-16T17:31:13.607

vec3(255,255,255) can be shorted to vec3(255) – Gábor Fekete – 2016-07-16T20:39:16.647

2

Maple 231 bytes

macro(t=thickness,w=white,c=color):
plots:-display(
plot([],background=blue),
plot(9,0..25.2,t=48,c=w),
plot([9,y,y=0..18.2],t=48,c=w),
plot(9,0..25.2,t=24,c=red),
plot([9,y,y=0..18.2],t=24,c=red),
scaling=constrained,view=[0..25,0..18]);

Added newlines for readability. This code uses a couple of aliases for repeated terms. Iceland->Maple

Another method, which is slightly cleaner and produces a slightly more crisp image but longer (285 without aliases) is:

plots:-display(
plottools:-rectangle([0,8],[25,10],color=red),
plottools:-rectangle([8,0],[10,18],color=red),
plottools:-rectangle([0,7],[25,11],color=white),
plottools:-rectangle([7,0],[11,18],color=white),
plottools:-rectangle([0,0],[25,18],color=blue),
style=polygon,scaling=constrained);

DSkoog

Posted 2016-07-11T09:32:23.150

Reputation: 560

2

Python Turtle, 233 bytes

from turtle import*
import tkinter as _
_.ROUND=_.BUTT
S=8
c=color
w=width
h=18*S
c("navy")
w(h)
fd(25*S)
c("white")
w(4*S)
home()
pu()
goto(9*S,-9*S)
lt(90)
pd()
fd(h)
c("#d72828")
w(S+S)
bk(h)
pu()
home()
pd()
fd(25*S)
ht()
done()

enter image description here

One feature of this implementation is that I sacrificed 15 bytes to make it scalable so you can set S to anything from 1:

enter image description here

to however large you wish. If you want to run it under Python 2, simply change tkinter to Tkinter.

cdlane

Posted 2016-07-11T09:32:23.150

Reputation: 351

2

Postscript 148 characters (84 bytes when using binary shortcuts)

First of all, there are two versions: One optimized for characters, and one optimized for binary shortcuts.

Golfed character version:

/s{setrgbcolor}def/R{rectfill}def 0.843 0.157 0.157 s 0 8 25 2 8 0 2 18 R R 0 0.282 0.878 s 0 0 7 7 0 11 7 7 8 copy R R 11 0 translate 2 1 scale R R

Less golfed version (character optimised):

/s {setrgbcolor} def 
/R {rectfill} def
0.843 0.157 0.157 s
0 8 25 2
8 0 2 18
R
R
0 0.282 0.878 s
0 0 7 7
0 11 7 7
8 copy
R
R
11 0 translate
2 1 scale
R
R

Less golfed version (binary optimised):

0.843 0.157 0.157 setrgbcolor
0 8 25 2
8 0 2 18
rectfill
rectfill
0 0.282 0.878 setrgbcolor
0 0 7 7
0 11 7 7
8 copy
rectfill
rectfill
11 0 translate
2 1 scale
rectfill
rectfill

Hex of the binary representation version:

30 2E 38 34 33 20 30 2E 31 35 37 20 30 2E 31 35 37 92 9D 30 20 38 88 19 32 88 08 30 20 32 88 12 92 80 92 80 30 20 30 2E 32 38 32 20 30 2E 38 37 38 92 9D 30 88 00 37 88 07 30 88 0B 37 88 07 38 92 19 92 80 92 80 88 0B 30 92 AD 32 20 31 92 8B 92 80 92 80

goose121

Posted 2016-07-11T09:32:23.150

Reputation: 151

rectfill can take an array of numbers and draw multiple rectangles with one call. This can get it down to 139 bytes (by also changing the 8 copy to a dup). Also leading zeroes are not needed on the floats which brings it down to 134 – Geoff Reedy – 2016-11-01T14:27:38.017

1

Small Basic, 215 bytes

A Script that takes no input and outputs to the GraphicsWindow Object

a=0
b=0
c=25
d=9
x="#0048E0
p()
b=7
d=2
x="White
p()
a=7
b=0
c=4
d=9
p()
a=0
b=8
c=25
d=1
x="#D72828
p()
a=8
b=0
c=2
d=9
p()
Sub p
GraphicsWindow.BrushColor=x
GraphicsWindow.FillRectangle(a*25,b*25,c*25,d*50)
EndSub

Try it at SmallBasic.com! Requires IE/Silverlight

Output

Pic

Taylor Scott

Posted 2016-07-11T09:32:23.150

Reputation: 6 709

1

OCL, 232 177 bytes

Function a b c d e DrawRectangle b c d e End ShowCanvas SetFillColor 0 72 224 a 0 0 28 28 a 44 0 56 28 a 0 44 28 28 a 44 44 56 28 SetFillColor 215 40 40 a 32 0 8 72 a 0 32 100 8

I made the DrawRectangle function shorter, and removed the canvas resize. Produces this image:

enter image description here

Tux1

Posted 2016-07-11T09:32:23.150

Reputation: 41

1

JavaScript + HTML, 159 bytes

c=C.getContext`2d`;r=(o,w,s)=>{c.fillStyle=s;c.fillRect(o,0,w,72);if(o)c.fillRect(0,o,100,w)};r(0,100,'#0048e0');r(28,16,'#fff');r(32,8,'#d72828')
<canvas id=C>

I noticed that this question mentioned "HTML canvas" in the description mentioned, but there were no answers that used one (yet). As a bonus, you can run this in your browser. Here is a less-golfed version:

// get canvas's 2D drawing context
c=C.getContext`2d`;

// function to draw a rectangle
r=(o,w,s)=> {
    c.fillStyle=s;
    c.fillRect(o,0,w,72);
    if(o)c.fillRect(0,o,100,w)
};

// the blue background
r(0,100,'#0048e0');

// the white stripes
r(28,16,'#fff');

// the red stripes
r(32,8,'#d72828')

dana

Posted 2016-07-11T09:32:23.150

Reputation: 2 541

1

R, 258 bytes

plot(c(0,250),c(0,180),type="n",ann=F)
rect(0,110,70,180,col="blue")
rect(0,0,70,70,col="blue")
rect(110,0,250,70,col="blue")
rect(110,110,250,180,col="blue")
rect(0,80,250,100,col="red",border="transparent")
rect(80,0,100,180,col="red",border="transparent")

enter image description here

Michal

Posted 2016-07-11T09:32:23.150

Reputation: 209

instead of using xlab="",ylab="", why not ann=F? – plannapus – 2016-07-12T11:21:04.803

Can You omit the trailing line break? (-1) Can R draw one blue rectangle, overwrite that with two white rects and those with two red ones? (-71) – Titus – 2016-07-13T01:44:17.653

1

Perl, 128 bytes

$b=" 0 9 27"x28;$w=" 31"x12;$r=" 26 5 5"x8;
$t="$b$w$r$w$b$b"x28;
$m=($w x8 .$r.$w x15)x4;
print"P3 100 72 31",$t,$m,$r x100,$m,$t;

(newlines added for readability, and not counted)

This is a straightforward compression of a PPM image. A PPM is supposed to have a line length of 70 or less, but in practice all readers will accept this image that's all on a single line. If you want to be properly portable, replace the first space in each of $b, $w and $r with a newline.

I've assumed that the RGB values supplied are in sRGB coordinates, so no need to apply any gamma correction for PPM.

Toby Speight

Posted 2016-07-11T09:32:23.150

Reputation: 5 058

2Picture! :) (Please include one.) – None – 2016-07-12T13:58:58.323

It's a bit too long for a data: URL. – Toby Speight – 2016-07-12T14:03:41.247

1@TobySpeight Upload to imgur first, then post it here, no need for data: URLs. – Erik the Outgolfer – 2016-07-13T09:41:22.777

1

PHP (CLI-Only), 277 chars

<?f();r(7,25);r(1,25);r(1,25);r(7,25);f();function f(){for($c=0;$c<7;$c++){r(4);b(7);b(1);b(1);b(7);r(4,14);echo"\n";}}function r($c,$w=7){for($i=0;$i<$w;$i++)if($c==7&&$w==25)if($i==8||$i==9)b(1);else b($c);else b($c);if($w==25)echo"\n";}function b($c){echo"\033[01;3{$c}m█";}

I'm using console colors and these blocky things to make it look like this:

enter image description here

It looks odd because the height is like 2.5x the width.

timmyRS

Posted 2016-07-11T09:32:23.150

Reputation: 329

Finally an answer using PHP. You can save a few bytes – here's a 265 bytes version: f();r(7,25);r(1,25);r(1,25);r(7,25);f();function f(){for(;$c++<7;){r(4);b(7);b(1);b(1);b(7);r(4,14);echo"⏎";}}function r($c,$w=7){for(;$i<$w;$i++)if($c==7&&$w==25)if($i==8||$i==9)b(1);else b($c);else b($c);if($w==25)echo"⏎";}function b($c){echo"\033[01;3{$c}m█";} (Replace ⏎ with an actual newline.) – insertusernamehere – 2016-07-12T18:16:59.517

@insertusernamehere your script has an error when executing for me. – timmyRS – 2016-07-13T10:34:19.973

Which error do you get? Did you replace with a real newline? Tested it in 5.5 - I don't have a PHP 7 console right now to verify. – insertusernamehere – 2016-07-13T10:40:15.670

@insertusernamehere variable $i was not defined. – timmyRS – 2016-07-13T10:52:18.623

This will be a notice then, right? Notices can be ignored when golfing. ;) – insertusernamehere – 2016-07-13T11:35:28.953

@insertusernamehere no, your script doesn't output the flag – timmyRS – 2016-07-13T15:20:39.930

1

ImageScript, 145 bytes

hex("0048e0");rect(0,0,156,156);rect(0,244,156,156);rect(244,0,366,156);rect(244,244,366,156);hex("d72828");rect(0,178,600,44);rect(178,0,44,400)

Fairly straightforward. Just changes colors and draws rectangles

NOTE: When this is loaded into the website, the website automatically adds new lines after semicolons. The program still works fine without them

(By default, image size is 600x400)

Try it online!

MCMastery

Posted 2016-07-11T09:32:23.150

Reputation: 783

1

PHP with GD, 256 253 244 238 bytes

saved 9 bytes thanks to insertusernamehere, manatwork reminded me of another 6.

<?$a=imageColorAllocate;$f=imageFilledRectangle;$a($g=imagecreate(100,72),0,72,224);$f($g,28,0,43,71,$w=$a($g,-1,-1,-1));$f($g,0,28,99,43,$w);$f($g,32,0,39,71,$r=$a($g,215,40,40));$f($g,0,32,99,39,$r);header('Content-Type:');imagegif($g);
  • call in web browser
  • for Android: insert image/gif behind Content-Type: (+9)

enter image description here

Titus

Posted 2016-07-11T09:32:23.150

Reputation: 13 814

2I've tested it on OS X in Safari, Chrome and Firefox and every browser showed the image correctly using only: header('Content-Type:') - could save 9 bytes. Please verify it yourself first. ;) – insertusernamehere – 2016-07-13T09:53:04.853

1confirmed on Windows, Ubuntu and iOS; fails on Android 4. – Titus – 2016-07-13T10:16:40.157

1You could move the assignment to color variables to their first use: $f($g,28,0,43,71,$w=$a($g,-1,-1,-1));. Same for $r. – manatwork – 2016-07-13T10:54:47.170

1

KV(lang), 730 B :D

Not a competing answer, rather showing a language Kivy uses to make designing its widgets easier. The language requires indentation and newlines, therefore I'm forced to leave it in this shape. Kivy also takes rgb(a) as a color input, so I need to convert it and although there's a built-in, it's surely not suitable for golfing. :D

I'm traveling and with Kivy I'm able to code even on android. + its code is already crossplatform in I think 9/10 cases. ^^

#:import h kivy.utils.rgba
<F>:
    canvas:
        Color:
            rgb: h('#d72828')
        Rectangle:
            size: [100,72]
        Color:
            rgb: h('#ffffff')
        Rectangle:
            pos: [40,0]
            size: [60,32]
        Rectangle:
            pos: [40,40]
            size: [60,32]
        Rectangle:
            pos: [0,40]
            size: [32,32]
        Rectangle:
            size: [32,32]
        Color:
            rgb: h('#0048e0')
        Rectangle:
            pos: [44,0]
            size: [56,28]
        Rectangle:
            pos: [44,44]
            size: [56,28]
        Rectangle:
            pos: [0,44]
            size: [28,28]
        Rectangle:
            size: [28,28]

To run it you need to install Kivy and either save it as a .kv file, or have something like this in Python to parse it as a string:

from kivy.lang import Builder
from kivy.base import runTouchApp
from kivy.uix.boxlayout import BoxLayout
Builder.load_string('''KVstring''')
class F(BoxLayout):pass
runTouchApp(F())

enter image description here

KeyWeeUsr

Posted 2016-07-11T09:32:23.150

Reputation: 181

Does kv also allow console output, or just GUI widgets? – Pavel – 2016-12-29T05:31:56.947

1@Pavel well, you still need kivy installed to be able to run it, but otherwise everything after : is python, so it can have console output or just return widgets(gui). – KeyWeeUsr – 2016-12-29T10:30:22.960

1

Javascript ES6, 200 bytes

Yes, it is huge. I decided to do text outputting instead of table fiddling and stuff.

N='<br>',B=(_,t=1)=>`<font color=#${['fff','0048e0','d72828'][_|0]}>@`.repeat(t);C=B(1,7)+B()+B(2,2)+B()+B(1,14)+N;document.body.innerHTML=C+C+C+(L=B(0,8)+B(2,2)+B(0,15)+N)+B(2,25)+N+B(2,25)+N+L+C+C+C

This does not work well on Firefox, but works fully on Google Chrome.

Ismael Miguel

Posted 2016-07-11T09:32:23.150

Reputation: 6 797

1Nice touch using <font color=""> - brings back some old memories. :) – insertusernamehere – 2016-07-13T14:16:03.457

1

Scala, 219 bytes

Inspired by Titus' bash solution, not very Scala-like. Also, the colors are off and the "pixels" are not square.

object O{def main(a:Array[String])={val e="\u001B[";val(b,r,w,n,s)=(e+"44m",e+"41m",e+"47m",e+"0m\n"," "*7);val(x,y,z)=(s"$b$s$w $r  $w $b$s$s$n",s"$w$s $r  $w $s$s$n",s"$r${s*3}    $n");print(s"${x*7}$y$z$z$y${x*7}")}}`

ungolfed:

object O{
  def main(a:Array[String])={
    val e="\u001B["; // escape sequence for color codes
    val(b,r,w,n,s)=(
      e+"44m", // blue background
      e+"41m", // red background
      e+"47m", // white background
      e+"0m\n",// color off + newline
      " "*7);  // seven spaces
    val(x,y,z)=(
      s"$b$s$w $r  $w $b$s$s$n", // 7*blue,white,red,red,white,14*blue
      s"$w$s $r  $w $s$s$n",     // 8*white,2*red,15*white
      s"$r${s*3}    $n");        // 3*7+4=25*red
    print(s"${x*7}$y$z$z$y${x*7}") // print the individual lines
  }
}

Idea: The program uses (bash) color escape sequences to set the background color on the console. It then draws a number of space characters in the respective background color. The image consists of 18 lines of 25 spaces; the first seven and the last seven lines represented by variable x, the two (completely red) middle lines by z, and y represents the two white-and-red lines above/below. To save bytes, variable s represents seven consecutive spaces; for smaller cases, the spaces are used literally (i.e. the four consecutive spaces in variable z are necessary).

Icelandic flag as output by terminal

Heinrich supports Monica

Posted 2016-07-11T09:32:23.150

Reputation: 111

1

C#, 356 272 bytes

enter image description here

Golfed

()=>{Action f=Console.WriteLine;Action<int,int>o=(c,l)=>{Console.BackgroundColor=(ConsoleColor)c+8;Console.Write(new char[l]);};for(int d=1,i=0;i>-1;i+=d){if(i<7){o(1,7);o(7,1);o(4,2);o(7,1);o(1,14);}if(i==7){o(7,8);o(4,2);o(7,15);}if(i>7){o(4,25);f();o(4,25);d=-1;}f();}}

Ungolfed

() =>
{
    Action f = Console.WriteLine;
    Action<int, int> o = (c, l) =>
    {
        Console.BackgroundColor = (ConsoleColor)c + 8;
        Console.Write(new char[l]);
    };
    for (int d = 1, i = 0; i > -1; i += d)
    {
        if (i < 7)
        {
            o(1, 7);
            o(7, 1);
            o(4, 2);
            o(7, 1);
            o(1, 14);
        }
        if (i == 7)
        {
            o(7, 8);
            o(4, 2);
            o(7, 15);
        }
        if (i > 7)
        {
            o(4, 25);
            f();
            o(4, 25);
            d = -1;
        }
        f();
    }
}

By the rules anonymous delegates are allowed as long as the answer includes an example of how to run it...

using System;
class P
{
    static void Main()
    {
        new Action(
/*replace this with delegate*/
        )();
    }
}

Matthew Whited

Posted 2016-07-11T09:32:23.150

Reputation: 141

1

KA Processing, 79 bytes

stroke(255);background(0,72,224);fill(215,40,40);rect(0,8,25,2);rect(8,0,2,18);

Try it here!

bleh

Posted 2016-07-11T09:32:23.150

Reputation: 161

stroke(-1) is one byte shorter than stroke(255) – user41805 – 2017-04-23T15:21:38.493

1

Common Lisp (Lispworks), 465 bytes

(capi:contain(make-instance'capi:output-pane :display-callback #'(lambda(#4=pane x y #5=width #6=height)(let((a(/ #5# 25))(b(/ #6# 18)))(progn(#1=gp:draw-rectangle #4# x y #5# #6# #2=:filled t #3=:foreground :blue)(#1# #4# x(+ y(* b 7))#5#(+ y(* b 4))#2# t #3# :white)(#1# #4#(+ x(* a 7))y(+ x(* a 4)) #6# #2# t #3# :white)(#1# #4# x(+ y(* b 8))#5#(+ y(* b 2))#2# t #3# :red)(#1# #4#(+ x(* a 8))y(+ x(* a 2))(+ y(* b 18))#2# t #3# :red)))):width 200 :height 144))

ungolfed:

    (defun draw-a-flag (pane x y width height)
      (let ((a (/ width 25)) (b (/ height 18)))
        (progn
          (gp:draw-rectangle pane x y width height :filled t :foreground :blue)
          (gp:draw-rectangle pane x (+ y (* b 7)) width (+ y (* b 4)) :filled t :foreground :white)
          (gp:draw-rectangle pane (+ x (* a 7)) y (+ x (* a 4)) height :filled t :foreground :white)
          (gp:draw-rectangle pane x (+ y (* b 8)) width (+ y (* b 2)) :filled t :foreground :red)
          (gp:draw-rectangle pane (+ x (* a 8)) y (+ x (* a 2)) (+ y (* b 18)) :filled t :foreground :red))))


    (capi:contain
     (make-instance
      'capi:output-pane
      :display-callback 'draw-a-flag)
     :best-width 200
     :best-height 144)

Usage:

enter image description here

sadfaf

Posted 2016-07-11T09:32:23.150

Reputation: 101

1

ZX Spectrum Z80 assembly, 55 Bytes

1st attempt.

     org 8000H

start:

     ld hl,5800h  
     ld c,18  
main:


     ld de,120*256+8  
     ld a,c  
     sub e  
     jr c, line  
     jr z,white_line  
     sub 3  
     jr c,red_line  
     jr nz,line  

white_line:  

     ld e,d  
     jr line  

red_line:  

     ld de,16*256+16  

line:  

     ld a,16  
     ld b,7  

first_bit:  

     ld (hl),e  
     inc hl  
     djnz first_bit  
     ld (hl),d  
     inc hl  
     ld (hl),a  
     inc hl  
     ld (hl),a  
     inc hl  
     ld (hl),d  
     ld b,15  

next_bit:  

     inc hl  
     ld (hl),e  
     djnz next_bit  
     ld de,7  
     add hl,de  
     dec c  
     jr nz,main  
     ret  


     end  

Z80 coder

Posted 2016-07-11T09:32:23.150

Reputation: 51

1

Lua + LÖVE, 195 bytes

Very close to the other Lua + LÖVE answer but a bit different and shorter.

l=love
g=l.graphics
c=g.setColor
r=g.rectangle
m=255
e=100
p=72
f='fill'function
l.draw()c(0,p,224,m)r(f,0,0,e,p)c(m,m,m,m)r(f,0,28,e,16)r(f,28,0,16,p)c(215,40,40,m)r(f,0,32,e,8)r(f,32,0,8,p)end

Output:

enter image description here

Master_ex

Posted 2016-07-11T09:32:23.150

Reputation: 526

0

AHK, 194 Bytes

s=w100 h72 x0 y0 Q0048E0|wp h16 x0 y28 QWhite|w16 h72 x28 y0 QWhite|w100 h8 x0 y32 QD72828|w8 h72 x32 y0 QD72828
s:=StrReplace(s,"Q","Background")
Loop,Parse,s,"|"
GUI,Add,Progress,%A_LoopField%
GUI,Show

Is the initial string for all the parameters that eats up all the bytes.

Engineer Toast

Posted 2016-07-11T09:32:23.150

Reputation: 5 769

0

Golfscript (probably non-competing), 47 bytes

Let's try an equivalent in a language without real support for colored output. I hope it's allowed.

I have chosen # to represent blue, * to represent red, and to represent white.

{'#'7*' ** ':&1$.n}7*][' '7*&1$.n].'*'25*n+.@4$

At a cost of 6 bytes, I can make the flag "wider":

{'##'7*' ** '{.}%:&1$.n}7*][' '14*&1$.n].'*'50*n+.@4$

Josiah Winslow

Posted 2016-07-11T09:32:23.150

Reputation: 725

0

ZX Spectrum Z80 assembly, 49, 47 46, 47 bytes

Program when running uses 47 bytes + 4 for stack usage
stack usage is 2 bytes to store return address and 2 for internal use

It uses no other programs and uses no other external Ram/Rom The output is the modification of the video Ram.

Brief idea of how program draws flag.
The background is coloured blue.
Then if vertically or horizontally in the red area draw red. (offset 9 and 10)
Then if vertically or horizontally in the white area draw white, only if the background is not already coloured in red. (offset 8 and 11)

          org   8000H  
red:      equ   16  
white:    equ   120   
blue:     equ   8  
;  
start:

          ld    hl,5800h  
          ld    c,18
main:
          ld    b,25     
loop:
          ld   de,red*256+blue  
          ld   (hl),e  
          ld   a,c  
          call check  
          ld   a,l  
          and  31  
          call check  
          inc  hl  
          djnz loop
          ld   d,b
          add  hl,de
          dec  hl 
          dec  c  
          jr   nz,main  
          ret  

check:  
          sub   e  
          ret   c  
          jr    z,white_line  
          sub   3 
          jr    z,white_line
          ret   nc
          ld    (hl),d  
white_line:  
          ld    a,d 
          cp    (hl)  
          ret   z  
          ld    (hl),white    
          ret  

          end  


;         47 bytes

Original code 49 bytes
edit 1 47 bytes changed logic flow
edit 2 46 bytes removed a ret
edit 3 47 bytes. fixed output to exact dimensions

Spectrum screen output

Z80 coder

Posted 2016-07-11T09:32:23.150

Reputation: 51

Indent all code by 4 spaces to make it into a code block. If you have the output as an image or screenshot you can upload it and include it in your answer. The toolbar in the answer textarea can give you a lot of tips about formatting, clicking the question mark gives you some info about the markdown syntax used here. Also, consider adding a header (add === under a line of text) with <languge>, <# of bytes> bytes. – algmyr – 2016-07-29T23:27:57.570

Additionally, you should edit any answers that you already have to an answer rather than post a revised version as a new answer. – Taylor Scott – 2017-01-06T11:58:31.070