Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 units, where a unit is a pixel or a character.
  • 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.

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

share|improve this question
6  
Far more challenging would be the flag of my country, who also did a lot better than expected in the Euros this year - Wales. :-) – Gareth 2 days ago
9  
@Gareth I'm looking forward to a waterproof specification of the dragon. ;) – Martin Ender 2 days ago
3  
It looks like the blue in the above image is darker than the actual #0048e0 – Luis Mendo 2 days ago
2  
@MartinEnder Does carving it on a stone tablet count? That's waterproof. – immibis yesterday
1  
At this point, given the number of answers, wouldn't this post benefit from having a leaderboard? – plannapus 16 hours ago

44 Answers 44

Python 3, 190 172 171 169 167 160 159 147 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','#fff')
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.

share|improve this answer
18  
Really nice answer. – insertusernamehere 2 days ago
6  
This is genius! (Viking)Hat off to you. – Joannes 2 days ago
5  
Wow, it's rare that I vote on code-golf type questions on SO, but it's even rarer that I'll join a whole new community just to do so. This offset hack is reminiscent of what we used to have to do before you young whippersnappers got your oodlebytes of memory to work with. Excellent job. – paxdiablo yesterday
2  
genius,really! 💡 – InuYaksa yesterday
2  
If you do from PIL.ImageDraw import*, I becomes Image and D.Draw becomes Draw, saving 11 bytes. – Dennis yesterday

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
share|improve this answer
5  
This is a really cool first answer! Welcome! – TimmyD 2 days ago
2  
You can save 2 bytes by replacing 'mov' with 'xchg' at 10h & 13h and another 2 bytes by replacing 'test cx,cx/jz' with 'jcxz' at 16h – meden yesterday
    
Thank you @meden – Margaret Bloom yesterday
1  
Some more thoughts. Since the program runs in the infinite loop, you can avoid flickering just by making the loop shorter: _loop: jcxz _loop. You can also cut 2 bytes from the end of the data chunk if you change the loading order of cx and di – meden yesterday
    
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 yesterday

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

share|improve this answer
14  
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 2 days ago
1  
Doesn't the result have to be "at least 100 x 72 units, where a unit is a pixel or a character"? This doesn't meet this requirement, but I suspect the OP made a mistake when formulating that definition. – Kritzefitz yesterday
3  
@Kritzefitz Well, a character takes up many pixels, so it can be a pixel instead of a character. Found a hole. – Eʀɪᴋ ᴛʜᴇ Gᴏʟғᴇʀ 14 hours ago

CSS, 285 284 bytes

*,: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

Saved 1 byte thanks to @insertusernamehere.

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

share|improve this answer
1  
You can still save 1 byte by replacing white with #fff. – insertusernamehere 2 days ago
    
@insertusernamehere Yep, thanks. – gcampbell yesterday
1  
If you apply the CSS in quirks mode (page without doctype) you can bring it down to 264 bytes by omitting px everywhere. – user2428118 yesterday
    
@user2428118 Even more useful considering that there's no HTML, therefore no <!doctype html>! – wizzwizz4 yesterday
    
@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 yesterday

Excel VBA, 254 228 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

Sub a()
r = 255
w = 16777215
Range("A1:CV72").Interior.Color = 16711680
Range("AC1:AR72").Interior.Color = w
Range("A29:CV44").Interior.Color = w
Range("AG1:AN72").Interior.Color = r
Range("A33:CV40").Interior.Color = r
End Sub

Picture: Iceland Flag

share|improve this answer
    
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 2 days ago
    
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 2 days ago
    
Also the code to convert it to pixels looks like it requires you hard code either some part of the resolution or PPI (I don't really understand the formula) so it seems it wouldn't work across all devices either. – tjb1 2 days ago
1  
And, just for completeness (to do with setting up square cells rather than the solution itself), if you switch to page layout view, you can set cell height and width to specific values like 0.2cm. This will be maintained once you switch back, and no need to try and work out the bizarre Excel aspect ratios :-) By the way, if you want some more cool Excel tricks, look up Joel Spolsky's "You suck at Excel" video. – paxdiablo yesterday
1  
I think extra whitespace can be removed, even though it is added automatically later. – Eʀɪᴋ ᴛʜᴇ Gᴏʟғᴇʀ yesterday

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

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
share|improve this answer

ZX Spectrum BASIC, 210 141 bytes

1 FOR x=NOT PI TO VAL "24": FOR y=NOT PI TO VAL "17": LET p=SGN PI: IF x>=VAL "7" AND x<=VAL "10" OR y>=VAL "7" AND y<=VAL "10" THEN LET p=VAL "7": IF x=VAL "8" OR x=VAL "9" OR y=VAL "8" OR y=VAL "9" THEN LET p=VAL "2"
2 PRINT AT y,x: PAPER p; BRIGHT p=VAL "7";" ": NEXT y: NEXT x

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.

share|improve this answer
    
Seeing those PAPER and BRIGHT brings so many good memories :-) – Luis Mendo 2 days ago
    
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 yesterday
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 yesterday
    
132 bytes by removing the AT and adjusting the boundary test twitter.com/john_metcalf/status/752760203007791105 – impomatic yesterday
1  
122 bytes with some further optimizations twitter.com/john_metcalf/status/752783690179211264 – impomatic yesterday

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

share|improve this answer
5  
If you specify x: instead of output file name, convert will display the result in a window, which is also acceptable. And is enough to just escape the sharp, no need to quote: \#d72828. – manatwork 2 days ago
2  
Usually we label such answers as Bash + Imagemagick. On bash side you can save another 4 characters: convert -size 84x56 xc:#0048e0 ${s=-splice 8x8}+28+28 -background \#d72828 $s+32+32 x:. – manatwork yesterday
    
Just a stupid question: Can you do ${s=-splice 8x8}+56? – Eʀɪᴋ ᴛʜᴇ Gᴏʟғᴇʀ 14 hours ago
    
@EʀɪᴋᴛʜᴇGᴏʟғᴇʀ +56 is treated as +56+0, not +28+28. – bodqhrohro 13 hours ago
1  
You can save another byte by using a recent version of ImageMagick; then the command can be "magick" instead of "convert". – Glenn Randers-Pehrson 12 hours ago

Python, 119 118 114 bytes

Nothing special, straightforward:

b,w,r="\x00H\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

Converted to PNG

share|improve this answer
1  
Congratulations! You beat me by a lot :D – Gábor Fekete yesterday
    
You've got to include a picture in your answer! :) – Lembik yesterday
1  
@GáborFekete beat you in bytes, yes. But your answer is much more clever with that offset – Karl Napf yesterday
    
@Lembik If you insist :) – Karl Napf yesterday

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

share|improve this answer
    
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 yesterday
    
@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 yesterday
    
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 yesterday
    
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 yesterday
    
Even better: don't paint the first rectangle, just call setBackground(color) (also the size was still wrong). Now at 317: import java.awt.*;interface A{static void main(String[]a){new Frame(){public void paint(Graphics G){setSize(175,126);setBackground(new Color(0,72,224));G.setColor(Color.WHITE);G.fillRect(49,0,28,126);G.fillRect(0,49‌​,175,28);G.setColor(new Color(215,40,40));G.fillRect(56,0,14,126);G.fillRect(0,56,175,14);}}.show();}} – Justin yesterday

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.

share|improve this answer

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

share|improve this answer
1  
Sure the 7 - 14 ratio of left and right blue widths is correct? – manatwork 2 days ago
1  
@manatwork Oops, for some reason I thought 100 / 25 = 5, so everything ended up 25% too wide. – Neil 2 days ago

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">`)
share|improve this answer

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

share|improve this answer
    
You can shave off two more bytes by using fill and rect instead of size and background. 134 bytes: noStroke();fill(#0048e0);rect(0,0,100,72);fill(255);rect(0,28,100,16);rect(28,0‌​,16,72);fill(#d72828);rect(0,32,100,8);rect(32,0,8,72); – GuitarPicker yesterday

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

share|improve this answer

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

share|improve this answer
1  
@dahnoak thanks :) – martin yesterday
1  
you're welcome. same can be applied to your second longer version. u=Unitize;c=ConstantArray etc ^_^ – dahn oak yesterday
1  
Wait, there's something Mathematica doesn't have a builtin for? I'm surprised. – Morgan Thrapp 3 hours ago

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)

share|improve this answer

Logo, 216 190 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 "#0048e0
fill
X 7 16
X "#d72828 8
fd 4
pe
pd
setx -4
bk 80
setx 104
fd 80
setx 0
ht
share|improve this answer
    
I didn't know there was an English speaking version of Logo! – Vincent 9 hours ago
1  
Absolutely. I think I first saw it over 30 years ago on an Apple IIe. I also had it on my TRS-80 Color Computer. It was my first taste of using angles in geometry, years before I was to officially learn it in school. – GuitarPicker 9 hours ago

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

share|improve this answer
    
Do you need spaces after each :? Oh, and it's 151 bytes. – Eʀɪᴋ ᴛʜᴇ Gᴏʟғᴇʀ 10 hours ago

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

share|improve this answer
    
The weirdness comes from the fact that characters are taller than their width. – Eʀɪᴋ ᴛʜᴇ Gᴏʟғᴇʀ 14 hours ago
    
@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 14 hours ago
    
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. – Eʀɪᴋ ᴛʜᴇ Gᴏʟғᴇʀ 14 hours ago

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

share|improve this answer

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.

share|improve this answer
    
Do commands like this really only take one byte? What is the value of the byte? – Random832 2 days ago
1  
@Random832 Oddly enough, yes! Check the token size here: 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 2 days ago
1  
@Random832 The byte for Line( is 0x9C. You can see a table of one-byte tokens here: tibasicdev.wikidot.com/one-byte-tokens – f'' 2 days ago
1  
Couldn't you graph using regions (using < and >) instead of lines to get greyscale shading? – mbomb007 2 days ago
6  
Why is this non-competing? – Mego 2 days ago

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

share|improve this answer

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.);}
share|improve this answer
1  
Can you do #define r(p,w,h)step(abs(p.x),w)*step(abs(p.y),h)? – Eʀɪᴋ ᴛʜᴇ Gᴏʟғᴇʀ 14 hours ago
    
Yes that works! Thank you! – Gábor Fekete 13 hours ago

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

share|improve this answer
    
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 9 hours ago
    
Thanks, spaces are removed and I delete the using statement, too. I also use anonymous variables now. – soema 9 hours ago
    
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 9 hours ago
    
Yes! Just save now and no opening more ... – soema 9 hours ago

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

share|improve this answer
1  
*{position:fixed} should do it. And it's 18 bytes shorter than a,a *{display:block;position:fixed}. – insertusernamehere 2 days ago
1  
@insert Indeed, thanks for that. The other way I was working with failed though. – nicael 2 days ago
    
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;wid‌​th:8px}d,f{top:8px}c,e{left:8px}a,c,e{width:100px}d,f,a{height:72px, fiddle. – insertusernamehere 2 days ago
1  
@insert Thanks again, saved 20 with your hints :) – nicael 2 days ago
    
@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 yesterday

PowerShell v2+, 379 340 bytes

nal n New-Object
Add-Type -A System.Drawing,($m='System.Windows.Forms')
$g=($f=n "$m.Form").CreateGraphics()
$x='$g.FillRectangle($b'
$f.Add_paint({$g.FillRectangle(($b=n Drawing.SolidBrush '0x0048e0'),0,0,100,72)
$b.Color="white"
"$x,28,0,16,72);$x,0,28,100,16)"|iex
$b.color='0xd72828'
"$x,32,0,8,72);$x,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. Most of the boilerplate is similar to my chessboard answer, with an additional 39 bytes saved thanks to TessellatingHeckler's answer, so check those out for further details.

Otherwise, we're simply drawing the blue background, then two white rectangles, followed by two red rectangles. One quirk here is the variable $x which is just a placeholder for the lengthy $g.FillRectangle($b,...) call. We adjust the values appropriately each time and pipe it to iex (similar to eval) so that we don't need to type out the call each time -- saves about 30 bytes.

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.

share|improve this answer
    
If you pinch the start of my script here: 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 yesterday
    
@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. – TimmyD yesterday

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

share|improve this answer
    
Why is this marked "Non-competing"? Usually, that is reserved for using a language that's newer than the challenge. – Dr Green Eggs and Iron Man yesterday
    
Because the blue is brighter than the flag's blue. – daHugLenny yesterday
    
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. – Dr Green Eggs and Iron Man yesterday
4  
@daHugLenny Since the contest allows for ANSI colors if necessary, I'm sure this would be fine. – MCMastery yesterday

Javascript console, 244 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

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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