112
\$\begingroup\$

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

Input

Well, obviously this challenge has no input.

Output

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

Boilerplate

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

Leaderboard

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

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


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

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

87 Answers 87

1 2
3
2
\$\begingroup\$

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

\$\endgroup\$
2
\$\begingroup\$

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

\$\endgroup\$
2
\$\begingroup\$

Batch, 226 bytes

@echo off&set a=.......
set l=␛[107m.%a%␛[41m..␛[107m.%a%%a%
:s
for /l %%i in (1,1,7)do echo ␛[44m%a%␛[107m.␛[41m..␛[107m.␛[44m%a%%a%
if not defined t echo %l%&echo ␛[41m%a%....%a%%a%&echo:%a%....%a%%a%&echo %l%&set t=0&goto:s

is used to represent the nonprintable character.

\$\endgroup\$
2
\$\begingroup\$

BASH - 157 bytes

r=\\e[41m;b=\\e[44m;w=\\e[47m;d=\\e[0m;for i in {1..18};{ n=$b;j=$w;((i==8||i==11))&&n=$w;((i==9||i==10))&&n=$r j=$r;printf "$n%14s$j  $r%4s$j  $n%28s$d\n";}

Ungolfed version for better readability:

r=\\e[41m
b=\\e[44m
w=\\e[47m
d=\\e[0m

for i in {1..18};{
    n=$b;j=$w
    ((i==8||i==11))&&n=$w
    ((i==9||i==10))&&n=$r j=$r
    printf "$n%14s$j  $r%4s$j  $n%28s$d\n"
}

The result

flag

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

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!

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

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

\$\endgroup\$
3
  • 2
    \$\begingroup\$ I'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. ;) \$\endgroup\$ Jul 13, 2016 at 9:53
  • 1
    \$\begingroup\$ confirmed on Windows, Ubuntu and iOS; fails on Android 4. \$\endgroup\$
    – Titus
    Jul 13, 2016 at 10:16
  • 1
    \$\begingroup\$ You 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. \$\endgroup\$
    – manatwork
    Jul 13, 2016 at 10:54
1
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Nice touch using <font color=""> - brings back some old memories. :) \$\endgroup\$ Jul 13, 2016 at 14:16
1
\$\begingroup\$

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

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

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

\$\endgroup\$
2
  • \$\begingroup\$ instead of using xlab="",ylab="", why not ann=F? \$\endgroup\$
    – plannapus
    Jul 12, 2016 at 11:21
  • \$\begingroup\$ 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) \$\endgroup\$
    – Titus
    Jul 13, 2016 at 1:44
1
\$\begingroup\$

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*/
        )();
    }
}
\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
6
  • \$\begingroup\$ 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.) \$\endgroup\$ Jul 12, 2016 at 18:16
  • \$\begingroup\$ @insertusernamehere your script has an error when executing for me. \$\endgroup\$
    – Sainan
    Jul 13, 2016 at 10:34
  • \$\begingroup\$ 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. \$\endgroup\$ Jul 13, 2016 at 10:40
  • \$\begingroup\$ @insertusernamehere variable $i was not defined. \$\endgroup\$
    – Sainan
    Jul 13, 2016 at 10:52
  • \$\begingroup\$ This will be a notice then, right? Notices can be ignored when golfing. ;) \$\endgroup\$ Jul 13, 2016 at 11:35
1
\$\begingroup\$

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!

\$\endgroup\$
1
  • \$\begingroup\$ stroke(-1) is one byte shorter than stroke(255) \$\endgroup\$
    – user41805
    Apr 23, 2017 at 15:21
1
\$\begingroup\$

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

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

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

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

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

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

\$\endgroup\$
2
  • \$\begingroup\$ Does kv also allow console output, or just GUI widgets? \$\endgroup\$
    – Pavel
    Dec 29, 2016 at 5:31
  • 1
    \$\begingroup\$ @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). \$\endgroup\$
    – KeyWeeUsr
    Dec 29, 2016 at 10:30
1
\$\begingroup\$

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

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

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

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

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

pdfTeX, 108 bytes

\def~{ w 9 0 m 9 18 l s 0 9 m 25 9 l s }\pdfliteral{0 .28 .88 rg 0 0 25 18 re f 1 G 4~.84 .16 .16 RG 2~}\bye
\$\endgroup\$
1
\$\begingroup\$

Desmos, 150 bytes

b=rgb(0,72,224)
r=rgb(215,40,40)
w=hsv(0,0,1)
0<=x<=25\{0<=y<=18\}
7<=x<=11\{0<=y<=18\}
0<=x<=25\{7<=y<=11\}
0<=x<=25\{8<=y<=10\}
8<=x<=10\{0<=y<=18\}

Try it on Desmos!

This should work, but it doesn't due to a bug where it shows white lines:

Desmos, 124 bytes

r=rgb(215,40,40)
w=hsv(0,0,1)
c=[rgb(0,72,224),w,w,r,r]
[0,7,0,0,8]<=x<=[25,11,25,25,10]\{[0,0,7,8,0]<=y<=[18,18,11,10,18]\}

Try it on Desmos!

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

Go + github.com/fogleman/gg, 343 334 bytes

import(."image/color";."github.com/fogleman/gg";."os")
func f(){C,W,R:=NewContext(100,72),White,RGBA{255,0,0,255}
for _,i:=range[]struct{c Color;x,y,w,h float64}{{RGBA{0,72,224,255},0,0,100,72},{W,0,28,100,16},{W,28,0,16,72},{R,0,32,100,8},{R,32,0,8,72}}{C.SetColor(i.c)
C.DrawRectangle(i.x,i.y,i.w,i.h)
C.Fill()}
C.EncodePNG(Stdout)}

Try it on the Go Playground!

A whopping -11 -20 bytes from using an external package. Does the same thing as the one below without an external package.

Changelog

  • -9 bytes from using an anonymous struct.

Go, 376 354 bytes (no external packages)

import(."image";c"image/color";d"image/draw";p"image/png";."os")
func f(){N,S,R,D,P:=NewUniform,d.Src,Rect,d.Draw,Point{0,0}
F,x,y:=NewRGBA(R(0,0,100,72)),N(c.RGBA{255,0,0,255}),N(c.White)
D(F,F.Bounds(),N(c.RGBA{0,72,224,255}),P,S)
D(F,R(0,28,100,44),y,P,S)
D(F,R(28,0,44,72),y,P,S)
D(F,R(0,32,100,40),x,P,S)
D(F,R(32,0,40,72),x,P,S)
p.Encode(Stdout,F)}

Attempt This Online!

Writes a PNG to STDOUT.

Changelog

  • -22 bytes by @The Thonnu

Ungolfed Explanation

func iceland() {
    N, S, R, D, P := NewUniform, d.Src, Rect, d.Draw, Point{0, 0}
    F := NewRGBA(R(0, 0, 100, 72))                           // create the image
    D(F, F.Bounds(), N(c.RGBA{0, 72, 224, 255}), P, S)       // background
    D(F, R(0, 28, 100, 44), N(c.White), P, S)                // horizontal white stripe
    D(F, R(28, 0, 44, 72), N(c.White), P, S)                 // vertical white stripe
    D(F, R(0, 32, 100, 40), N(c.RGBA{255, 0, 0, 255}), P, S) // horizontal red stripe
    D(F, R(32, 0, 40, 72), N(c.RGBA{255, 0, 0, 255}), P, S)  // vertical red stripe
    p.Encode(Stdout, F)                                      // output a PNG to STDOUT
}
\$\endgroup\$
1
1
\$\begingroup\$

Chipmunk BASIC, 238 235 bytes

Chipmunk Basic v368b2.02 on MacOS. The RGB range is [0,100].

graphics 0
graphics color 0,28,88
graphics fillrect 0,0,150,108
graphics color 100,100,100
graphics fillrect 42,0,66,108
graphics fillrect 0,42,150,66
graphics color 84,16,16
graphics fillrect 0,48,150,60
graphics fillrect 48,0,60,108

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

C (GCC), 167 140 bytes

- ~25 bytes thanks to @ceilingcat

i=-36;main(j,g){for(write(1,"P6 100 72 255 ",14);i<37;i-=~!i)for(j=-36;j<65;j-=~!j)g=abs(i*i<j*j?i:j),write(1,g>4?g>8?"\0Hà":"ÿÿÿ":"×((",3);}

Set encoding to ANSI, so each character corresponds to a single byte, and replace \0 with a NUL byte. Outputs to stdout a PPM image.

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

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

\$\endgroup\$
2
  • \$\begingroup\$ 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. \$\endgroup\$
    – algmyr
    Jul 29, 2016 at 23:27
  • \$\begingroup\$ Additionally, you should edit any answers that you already have to an answer rather than post a revised version as a new answer. \$\endgroup\$ Jan 6, 2017 at 11:58
0
\$\begingroup\$

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.

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

Pikchr, 130 bytes

color=-1
boxwid=50
boxht=36
define@{
box at-$1,0fill}
box fill 18656@(7)white wid 8@(0)white ht 8@(7)0xd72828wid 4@(0)0xd72828ht 4

Output

<svg xmlns="http://www.w3.org/2000/svg" class="xd-pikchr" viewBox="0 0 7204.32 5188.32">
<path d="M2,5186L7202,5186L7202,2L2,2Z" style="fill:rgb(0,72,224);"></path>
<path d="M2018,5186L3170,5186L3170,2L2018,2Z" style="fill:rgb(255,255,255);"></path>
<path d="M2,3170L7202,3170L7202,2018L2,2018Z" style="fill:rgb(255,255,255);"></path>
<path d="M2306,5186L2882,5186L2882,2L2306,2Z" style="fill:rgb(215,40,40);"></path>
<path d="M2,2882L7202,2882L7202,2306L2,2306Z" style="fill:rgb(215,40,40);"></path>
</svg>

Explanation

  • color = -1: disable outlines
  • boxwid = 50: set the default box width to 50
  • boxht = 36: set the default box height to 36
  • define @ {…}: define a macro named @ which expands to the content of the curly braces, replacing $1 with its argument
  • box fill 18656: draw a rectangle with the center at (0,0) filled with color #0048e0
  • box at -7,0 fill white wid 8: draw a rectangle with the center at (-7,0) with width 8 filled white
  • box at -0,0 fill white ht 8: draw a rectangle with the center at (0,0) with height 8 filled white
  • box at -7,0 fill 0xd72828 wid 4: draw a rectangle with the center at (-7,0) with width 4 filled with color #d72828
  • box at -0,0 fill 0xd72828 ht 4: draw a rectangle with the center at (0,0) with height 4 filled with color #d72828
\$\endgroup\$
1 2
3

Your Answer

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

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