画出韩国国旗


58

当我偶然发现这个问题时,我想起曾经曾经看到过建造朝鲜国旗的确切规则。这是完全不同的构造。

在此处输入图片说明

资料来源:维基百科

所以,现在您要绘制此结构的确切结构!

规格

您可以使用矢量或光栅图形将标志呈现到文件或屏幕。如果对输出进行光栅化,则图像的尺寸必须为450x300像素或更大。

所有的长度比率和位置都必须完全如下图所示:

在此处输入图片说明

资料来源:维基百科

请注意,两个小圆圈的中心与对角线对齐。

对于颜色,必须使用以下调色板:

  • 白色:#FFFFFF
  • 黑色:#000000
  • 红色:#C60C30
  • 蓝色:#003478

除非您的绘图系统出于技术原因不允许您指定3:2画布,否则不得绘制黑色边界(否则,您应使用3:2画布,并且标记应填满所有画布)。如果确实需要添加边界,则边界可以任意厚-该标志应严格考虑黑色边界内。不得绘制任何其他帮助线或长度指示器。即,该标志应与第一个图像完全相同。

计分

这是代码高尔夫球,因此最短的答案(以字节为单位)获胜。

值得一提的是,使用现有压缩(例如嵌入压缩的GIF)会陷入几个标准漏洞


2
有趣的是,韩国国旗包含二进制数字系统的早期形式(britton.disted.camosun.bc.ca/jbbinflag.htm
britishtea

当我们使用大于标记的HTML页面时,是否必须绘制边框吗?是白色的,即使画布/元素的大小与标记相似,也看不到任何分隔
Optimizer

@Optimizer,不,如果画布以某种方式可见(例如,通过突出显示浏览器的“检查元素”)来界定边界,则不需要边界。仅在极少情况下无法在技术上定义画布范围的情况下才应绘制黑色边框。
Martin Ender 2014年

3
我假设CountryData["ROK","Flag"]不算数?
wchargin 2014年

Answers:


13

PHP / HTML / SVG,324

(添加了换行符以便于阅读)

<?=gzinflate(base64_decode('tVHBioMwFPyVwF5WSOzLi/tswQjdu9cevIk1KqtriaFd9utrgpSWFva0PPImMwzDkGTz
uWXnvrl8Tj8aOPAUebLNs5Y5W33PZrKjtpOrXPOuVEy7KMiD54mKMY3yrO5tPTTMaonM9MOg32qCWgHb5Nmpch076kIih/2y
PC4jRRCIU6BhbkwGV7lmAagk3d5nCfwQdKByVBwOFLagQu6exZLNzk5fjU+B9S4u/dF1Gh/apRw6Cb83uzHm0S69/cWbSIkx
YfSf5QT6dkk5UoACIeAfXTftepb/za8='));

压缩后的数据将扩展为与下面显示的我先前的答案相同的SVG数据,但进行了两项更改以帮助压缩:

  1. 这两个<use>部分将扩展为该<defs>部分的原始内容。这使源文本更长,但减小了熵,因此压缩效果更好。

  2. 在第一个<g>元素中,我更改transform=translate(36,24)rotate(33.69)transform=rotate(33.69)translate(43.27)。这在几何上具有相同的效果,但压缩效果更好,因为该序列><g transform=rotate(现在出现两次。

默认情况下,PHP将用作Content-Type: text/html,因此无效的XML语法应该不会成为问题。

SVG / HTML,463

HTML语法分析器对正确的语法不太在意,因此我们可以取消参数中的引号,只要它们不包含空格即可。应该可以使用一些Javascript将其进一步压缩。

<svg viewBox=0,0,72,48><defs><path d=M-25-6V6Zm3,0V6m3,0V-6M19-6V6Zm3,0V6m3,0V-6Z stroke=#000
stroke-width=2 id=p /></defs><g transform=translate(36,24)rotate(33.69)><circle r=12 fill=#c60c30
/><path d=M12,0A12,12,0,0,1-12,0A6,6,0,0,0,0,0A6,6,0,0,1,12,0Z fill=#003478 /><use xlink:href=#p
/><path d=M17,0h10z stroke=#fff stroke-width=1 /><g transform=rotate(112.62)><use xlink:href=#p
/><path d=M-27,0h4Zm6,0h4ZM20,0h4Z stroke=#fff stroke-width=1 /></g></g></svg>


44

Python + Pycairo, 371370 366字节

旗

from cairo import*
p=3.141593
c=Context(SVGSurface("F",12,8))
C=c.set_source_rgb;R=c.rectangle;T=c.rotate;F=c.fill
C(1,1,1);R(0,0,12,8);F()
c.translate(6,4);T(.588);b=3188
for o in[(0,.2,.47),(.77,.05,.19)]*2:C(*o);i=b/2%2;b+=1;c.arc(i,0,2-i,0,p+i*p);F();T(p)
C(0,0,0)
for x in(p,1.966)*2:
 for y in.5,0,1:
    for z in-1,1:R(3+y,-z,1./3,z*(2.75+b%2)/3);F()
    b/=2
 T(x)

输出一个名为的微型SVG文件F


C(*[.77,0,.05,.2,.19,.47][i::2])短于C(*[(.77,.05,.19),(0,.2,.47)][i%2])
isaacg,2014年

你为什么写s=SVGSurface("F",12,8);c=Context(s)而不是仅仅写c=Context(SVGSurface("F",12,8))
莉莉·钟

@IstvanChung好点。
2014年

32

HTML + CSS,966 906 843 792 762字节

任何时候都不是赢家,但是用CSS进行绘画很有趣。这可以打很多球。

CSS,HTML

*{position:fixed}a{background:linear-gradient(0deg,#003478 50%,#C60C30 50%);width:2in;height:2in;transform:rotate(.6rad);top:1in;left:2in}d,e{width:50%;height:50%;background:#C60C30;left:0;top:25%}a,d,e{border-radius:50%}d{background:#003478;left:50%}b,i{width:1in;height:26em;top:-1em;left:15em;transform:rotate(.98rad)}g,f,k,j{width:1in;height:17%;background:repeating-linear-gradient(0deg,#000,#000 1em,#fff 1em,#fff 1.5em);bottom:0;left:0}g,j,p{top:-.5em}b{transform:rotate(-.98rad)}c,p,v,x{height:2em;width:.5em;background:#fff;transform:rotate(.98rad)}p{top:2.8in;left:28em;transform:rotate(-.98rad) scale(1,4)}x{top:3.9em;left:28.4em}c,v{top:23.8em;transform:none}c{top:3.5em}body{height:4in;width:6in;border:1px solid
<a><d><e></a><b><f><g></b><i><j><k></i><p></p><x><v><c

;border:1px solid仅用于显示,因为<body>标签具有清晰的边界,可以由Inspector或类似工具观察到,如OP所述

注意由于使用了非特定于供应商的转换和渐变,因此仅在Firefox(或Chrome Canary / dev)中工作。

实际观看


我认为您应该在字符数中包含<link>或<style>标签。您可以保存一些字符:在CSS- 0deg>中0(两次)并left:0从中删除a:before。在HTML中,您可以使用<p><ul></ul>。(<p>将在此之前隐式关闭<ul>
gronostaj 2014年

1
在Firefox 32中运行。在Safari 7.1中失败。
200_success 2014年

1
对CSS使用LESS或SASS可以为您提供很多选择,可以大大缩短它。此外:before{content:''}:after{content:''}而且比添加其他元素还要长(尽管看起来确实更好)。
David Mulder 2014年

@DavidMulder我想要这个有趣的因素,而不是较短的代码。与LESS或SASS相比,人们可以更轻松地与纯CSS相关联:)
Optimizer

在最新版本的Chrome中也可以使用。@ 200_success您应该可以通过-webkit-在所有transform:s 之前添加使其在Safari中工作,但是不用说这会使它更长一些!
门把手

20

BBC Basic,349 343 ASCII字符,标记化文件大小330

http://www.bbcbasic.co.uk/bbcwin/bbcwin.html下载仿真器

  p=1049q=25r=100VDU4118;275;-1,49,3076;19,7,-1;-1;531;255;7693;q;40;0;q,97,1200;800;29,640;400;
  FORa=38TO56STEP0.01x=r*COS(a)y=r*SIN(a)b=a*7DIV44/2IFb=3.5z=y<0ELSEz=x>0
  VDU18;1,p;-x;-y;q,153,r;0;18;2,p;x;y;q,153,r;0;18;0
  IFABS(y)DIV1=56VDUp;x*b+y;y*b-x;q;x/3;y/3;q,113,-2*y;2*x;18;7:b-=0.1VDUp;x*b+y/12;y*b-x/12;q;x/2;y/2;q,112-z,-y/6;x/6;
  NEXT

使用正确的颜色增加了很多,但是将所有图形命令简化为原始VDU代码,与我的原始帖子相比,总共节省了6个字符。BBC micro上的所有图形都是通过机器专用的ASCII控制代码完成的,因此,可以使用直接将字节送至VDU控制器的方式来代替使用高级图形命令(通常较短,但以可读性为代价)。以分号(而不是逗号)结尾的值是2字节的16位little-endian表示形式。

非高尔夫版本

  MODE16
  VDU19,1,-1,49,4,12                :REM adjust shade of red 
  VDU19,7,-1,-1,-1,-1               :REM adjust shade of white to full brightness (63 is 2's complement representation of -1
  VDU19,4,-1,0,13,30                :REM adjust shade of blue
  RECTANGLEFILL40,0,1200,800        :REM plot background rectangle
  ORIGIN640,400
  FORa=38TO56STEP0.01
    x=COS(a)*100
    y=SIN(a)*100
    GCOL1:CIRCLEFILL-x,-y,100       :REM red
    GCOL4:CIRCLEFILLx,y,100         :REM blue
    GCOL0                           :REM black
    b=a*7DIV44/2                    :REM divide a by 2*(22/7) to get integer representation, then divide by 2 again.
    IFb=3.5THENz=y<0ELSEz=x>0       :REM decide whether to cut bar
    REM If the angle is correct (100*sin(a) = 56) draw bar. If required, cut out the middle of the bar.
    IFABS(INT(y))=56 MOVEx*b+y,y*b-x:MOVEBY x/3,y/3:PLOT113,-2*y,2*x:GCOL7:b-=0.1:MOVEx*b+y/12,y*b-x/12:MOVEBY x/2,y/2:IFz PLOT113,-y/6,x/6
  NEXT

在程序的开始,我将原点移动到屏幕的中心。

我没有画任何彩色的大半圈。相反,我运行了一个绘制红色和蓝色小圆圈的循环,并沿逆时针方向旋转。我进行了将近3次完整的旋转(从右边的蓝色开始),这显然足以装满光盘。我停在第三转,正好在右下角的蓝色位于正确的位置以与条形图对齐(必须绘制)。

当角度正确时,我将绘制其中一个条。用于绘制当前小蓝色圆圈的向量x,y用来告诉条形应该在哪个方向。对于3圈中的每一圈,a*7DIV44都会计算一个不同的整数值,该整数指示应绘制第一条,第二条还是第三条,其内边缘距中心6 / 8、7 / 8或8/8单位(因为程序单位是规范中单位的1/4,所以仍然是半个单位,因此在保存到变量“ b”之前,我们再除以2,以避免重复减半后来。

条形图绘制为实线,然后在必要时删除中间条。这样可以防止扭结连接半条。变量z指示是否应切割钢筋。也就是说,中间条的y为y,其他条的x为正。

MOVE是绝对的举动。MOVEBY是相对的举动。PLOT133将最后两个图形光标位置加上指定的新光标位置(在相对坐标中)视为平行四边形的三个角,并绘制该平行四边形。

输出(和语言限制的讨论)

我选择了1280x800逻辑像素= 640x400物理像素的屏幕模式,默认情况下具有黑色背景。为此,我绘制了一个从-600,-400到600,400的白色矩形,作为我的“画布”。

BBC Basic可通过可重新编程的托盘一次处理16种颜色。但是它仅支持18位颜色,而问题指定颜色为24位。颜色越接近越好。

在此处输入图片说明


2
我对边界做了一些修改。您处理它的方式几乎符合我的预期。
Martin Ender 2014年

16

Python 3中龟(552 549个字节)

旗

全尺寸图片

编辑:现在我们有了堆栈片段,这是使用Skulpt进行的堆栈片段测试,借助ArtOfCode的答案在这里。不幸的是,Skulpt还没有完全实现Python,因此我不得不削减一半的代码才能使它正常工作。换句话说,这个片段只是为了说明如何我的程序运行(无需拉起的Python)。

(此外,我发现这可能在某些浏览器上实际上不起作用...)

function out(a){var b=document.getElementById("output");b.innerHTML+=a}function builtinRead(a){if(void 0===Sk.builtinFiles||void 0===Sk.builtinFiles.files[a])throw"File not found: '"+a+"'";return Sk.builtinFiles.files[a]}
$(document).ready(function run(){Sk.canvas="canvas";Sk.configure({output:out,read:builtinRead});try{Sk.importMainWithBody("<stdin>",!1,'import turtle\nimport math\nt=turtle.Turtle()\nt.speed(9)\nR="#c60c30"\nr=56.3\nk=0.6\ns=60*k\noffsetx,offsety=-215,-145\nt.up()\nt.goto(offsetx,offsety)\nt.down()\ndef q():t.rt(90)\ndef Q():t.lt(90)\ndef K():t.color("black");t.begin_fill();q()\ndef A(g,G):t.fd(g);Q();t.fd(G);Q();t.fd(g);Q();t.fd(G);Q()\ndef E():t.up();t.fd(s);t.down();Q();t.end_fill();t.up();t.fd(30*k);t.down();\ndef i():K();t.up();t.bk(s);t.down();A(120*k,20*k);E()\ndef I():K();t.up();t.fd(5*k);t.down();A(55*k,20*k);t.up();t.bk(65*k);t.down();A(55*k,20*k);E()\ndef C():t.circle(120*k,180)\nA(720*k,480*k)\nt.seth(r)\nt.up()\nt.goto(459.8*k+offsetx,173.4*k+offsety)\nt.down()\nt.color(R)\nt.begin_fill()\nC()\nt.end_fill()\nt.begin_fill()\nt.color("#003478")\nC()\nt.circle(s)\nt.end_fill()\nt.color(R)\nC()\nt.begin_fill()\nt.circle(s)\nt.end_fill()\nq()\nt.up()\nt.fd(s)\nt.down()\ni()\ni()\ni()\nt.up()\nt.bk(530*k)\nt.down()\nI()\nI()\nI()\nt.up()\nt.fd(170*k)\nt.rt(2*r)\nt.fd(180*k)\nt.down()\nI()\ni()\nI()\nt.up()\nt.bk(530*k)\nt.down()\ni()\nI()\ni()\n')}catch(a){throw Error(a.toString());}})
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script><script src="http://www.skulpt.org/static/skulpt.min.js" type="text/javascript"></script><script src="http://www.skulpt.org/static/skulpt-stdlib.js" type="text/javascript"></script>
<canvas height="320" width="480" id="canvas" style="border:1px solid gray">Your browser does not support HTML5 Canvas!</canvas>


实际代码:

import turtle as t
b=t.begin_fill
c=t.circle
e=t.end_fill
f=t.fillcolor
R="#c60c30"
r=56.3
F=t.fd
B=t.bk
s=60
def q():t.rt(90)
def Q():t.lt(90)
def K():f(0,0,0);b();q()
def A(g,G):exec("F(g);Q();F(G);Q();"*2)
def E():F(s);Q();e();F(30)
def i():K();B(s);A(120,20);E()
def I():K();F(5);A(55,20);B(65);A(55,20);E()
def C():c(120,180)
A(720,480)
t.seth(r)
t.up()
t.goto(459.8,173.4)
f(R)
b()
C()
e()
b()
f("#003478")
C()
c(s)
e()
C()
f(R)
b()
c(s)
e()
q()
F(s)
i()
i()
i()
B(530)
I()
I()
I()
F(170)
t.rt(2*r)
F(180)
I()
i()
I()
B(530)
i()
I()
i()
t.ht()

由于乌龟是如此的慢速动作,因此,如果您想获得即时结果,可以t.tracer(0)在运行脚本之前在第一行之后添加。

注意:由于某种原因,即使我已经叫up(),turtle仍会继续绘制看起来像黑色像素的东西,我也不知道为什么...


我相信有人在Stack Snippets帖子上实现了Python(用乌龟!);如果您想弄清楚如何做,可以成为最早使用此新功能的人之一!;)
门把手

@Doorknob我必须销毁一半的代码才能使它模糊地执行我想要的操作,但至少在视觉上它与现在的Python一样。(但是由于某些原因,它无法在我的Chrome上运行...)
Sp3000 2014年

2
在Chrome iOS上正常工作。很高兴看到有人发现了我的项目的用处:)
ArtOfCode 2014年

14

HTML + ES6、388

<canvas id=D width=576 height=384><script>c=D.getContext('2d')
T=x=>c.translate(x*72,x*48)
R=(x,y)=>T(4)+c.rotate(x*.59)+T(-4)+eval('for(i=j=0;i*j<6;i+=(j^=1))c.fillRect(72+24*i+(i>2)*288,144+j*52,16,44+52*(y>>i&1-j))')
A=(w,x,y,z)=>(c.fillStyle=c.fill()+c.beginPath()||w)*c.arc(x*4,192-y,48*y,0,3.1,z)||A
R(-1,21)
R(2,7)
A(r='#C60C30',72,2,1)('#003478',72,2)(0,84,1,1)(r,60,1)()</script>

如果您的浏览器支持ES6,则可以在JSFiddle上查看它或运行代码段。

它根据一些基本形状构造标记,首先旋转画布以说明角度。


只是注意,这并不在Chrome 39工作,在FF罚款> 29
JBCP

<canvas width=576 height=384 id=D><script>c=D.getContext('2d')少9个字节。另外,由于整个页面都是白色的,因此我认为您需要绘制边框。
Optimizer

@Optimizer谢谢。据我了解,仅当您拥有无限画布时才需要边框。
grc

5
您可以尝试使用Stack Snippets!
Beta Decay

@BetaDecay它实际上起作用了:o
grc

6

数学404 450

b=1&~Array~13;a=ReplacePart[b,7-> 0];d=Disk;r=RGBColor;
z@{q_,p_,s_}:=ArrayPlot[{q,q,{},p,p,{},s,s},Frame-> False,ImageSize-> 155];
m=r@@{0,.2,.5};
o=r@@{.8,0,.2};
t=-19.1;u=-12.75;v=-5;q=-3.33;
Graphics[{Line[{{-36,-24},{36,-24},{36,24},{-36,24},{-36,-24}}],
Inset[Rotate[z@#,#2 125 Degree],#3]&@@@{{{b,a,b},1,{t,u}},{{a,b,a},1,{-t,-u}},
{{a,a,a},-1,{-t,u}},{{b,b,b},-1,{t,-u}}},
{o,d[{0,0},12,{-.2 Pi,.8Pi}],m, d[{0,0},12,{.8Pi,1.8Pi}],o,d[{v,-q},6],m,d[{-v,q},6]}}]

旗


3

C ++太大

使用我自己制作的PPM绘图库尝试了此操作。从技术上讲,它是可伸缩的,但是由于它不可靠并且喜欢进行段错误,因此我受到了递归填充功能的限制,我认为它占用了过多的内存,因此我实际上不会让用户设置比例。该图像不规则,因为我为条形图的每个角输入的坐标略有偏离。 在此处输入图片说明

我将其设置为从黑色背景开始,然后在中间放置一个白色圆圈,然后在其中放置红色和蓝色圆圈。使用递归填充来添加其余的红色和蓝色。然后绘制带有白线的矩形以标记黑条。用黑线将黑色背景分成4个部分,并使用4个递归填充使每个部分变为白色。一次性执行此操作将导致段错误。渲染仍然很慢。

取消主代码(库的其余部分太大,打高尔夫球没关系)

#include "PPMDraw.h"
#include <iostream>

int main(){
    std::cout << "Drawing Korean Flag" << std::endl;

    int scale = 150;
    int width = 3 * scale;
    int height = 2 * scale;

    int xc = width/2;
    int yc = height/2;

    // coords for the bar corners
    float nwax = -0.773; float nway = -0.813;
    float nwbx = -0.707; float nwby = -0.773;
    float nwcx = -1.000; float nwcy = -0.360;
    float nwdx = -1.050; float nwdy = -0.400;
    float nwex = -0.667; float nwey = -0.747;
    float nwfx = -0.613; float nwfy = -0.693;
    float nwgx = -0.880; float nwgy = -0.293;
    float nwhx = -0.947; float nwhy = -0.333;
    float nwix = -0.560; float nwiy = -0.667;
    float nwjx = -0.507; float nwjy = -0.627;
    float nwkx = -0.773; float nwky = -0.227;
    float nwlx = -0.840; float nwly = -0.267;

    float neax = 0.747; float neay = -0.813;
    float nebx = 0.867; float neby = -0.627;
    float necx = 0.813; float necy = -0.587;
    float nedx = 0.680; float nedy = -0.773;
    float neex = 0.893; float neey = -0.587;
    float nefx = 1.030; float nefy = -0.400;
    float negx = 0.960; float negy = -0.360;
    float nehx = 0.840; float nehy = -0.547;
    float neix = 0.640; float neiy = -0.747;
    float nejx = 0.920; float nejy = -0.333;
    float nekx = 0.853; float neky = -0.293;
    float nelx = 0.587; float nely = -0.693;
    float nemx = 0.533; float nemy = -0.667;
    float nenx = 0.667; float neny = -0.493;
    float neox = 0.600; float neoy = -0.440;
    float nepx = 0.480; float nepy = -0.627;
    float neqx = 0.693; float neqy = -0.440;
    float nerx = 0.813; float nery = -0.267;
    float nesx = 0.747; float nesy = -0.227;
    float netx = 0.627; float nety = -0.400;

    float swax = -0.773; float sway = 0.200;
    float swbx = -0.507; float swby = 0.613;
    float swcx = -0.560; float swcy = 0.653;
    float swdx = -0.840; float swdy = 0.253;
    float swex = -0.880; float swey = 0.280;
    float swfx = -0.760; float swfy = 0.453;
    float swgx = -0.813; float swgy = 0.493;
    float swhx = -0.947; float swhy = 0.320;
    float swix = -0.733; float swiy = 0.507;
    float swjx = -0.613; float swjy = 0.680;
    float swkx = -0.667; float swky = 0.720;
    float swlx = -0.787; float swly = 0.547;
    float swmx = -0.987; float swmy = 0.347;
    float swnx = -0.707; float swny = 0.760;
    float swox = -0.773; float swoy = 0.800;
    float swpx = -1.053; float swpy = 0.387;

    float seax = 0.747; float seay = 0.200;
    float sebx = 0.813; float seby = 0.253;
    float secx = 0.693; float secy = 0.427;
    float sedx = 0.627; float sedy = 0.387;
    float seex = 0.853; float seey = 0.280;
    float sefx = 0.920; float sefy = 0.320;
    float segx = 0.800; float segy = 0.507;
    float sehx = 0.733; float sehy = 0.453;
    float seix = 0.960; float seiy = 0.347;
    float sejx = 1.036; float sejy = 0.387;
    float sekx = 0.893; float seky = 0.573;
    float selx = 0.840; float sely = 0.520;
    float semx = 0.600; float semy = 0.427;
    float senx = 0.667; float seny = 0.467;
    float seox = 0.547; float seoy = 0.653;
    float sepx = 0.480; float sepy = 0.613;
    float seqx = 0.707; float seqy = 0.493;
    float serx = 0.773; float sery = 0.547;
    float sesx = 0.640; float sesy = 0.733;
    float setx = 0.547; float sety = 0.680;
    float seux = 0.813; float seuy = 0.573;
    float sevx = 0.880; float sevy = 0.613;
    float sewx = 0.747; float sewy = 0.800;
    float sexx = 0.693; float sexy = 0.747;

    PPMDraw flag = PPMDraw(width, height);
    flag.fill(0, 0, 0);

    // draw white circle in middle
    flag.set_color(255, 255, 255);
    flag.draw_fill_circle(xc, yc, scale/2);

    // draw red and blue portions of circle
    flag.set_color(255, 0, 0);
    flag.draw_fill_circle(xc - .21*scale, yc - .14*scale, scale/3.9);
    flag.set_color(0, 0, 255);
    flag.draw_fill_circle(xc + .21*scale, yc + .14*scale, scale/3.9);
    flag.set_color(255, 0, 0);
    flag.recursive_fill(xc + .21*scale, yc - .21*scale);
    flag.set_color(0, 0, 255);
    flag.recursive_fill(xc - .21*scale, yc + .21*scale);

    // draw the northwest bars
    flag.set_color(255, 255, 255);

    flag.draw_line(xc + nwax*scale, yc + nway*scale, xc + nwbx*scale, yc + nwby*scale);
    flag.draw_line(xc + nwax*scale, yc + nway*scale, xc + nwdx*scale, yc + nwdy*scale);
    flag.draw_line(xc + nwbx*scale, yc + nwby*scale, xc + nwcx*scale, yc + nwcy*scale);
    flag.draw_line(xc + nwcx*scale, yc + nwcy*scale, xc + nwdx*scale, yc + nwdy*scale);

    flag.draw_line(xc + nwex*scale, yc + nwey*scale, xc + nwfx*scale, yc + nwfy*scale);
    flag.draw_line(xc + nwex*scale, yc + nwey*scale, xc + nwhx*scale, yc + nwhy*scale);
    flag.draw_line(xc + nwfx*scale, yc + nwfy*scale, xc + nwgx*scale, yc + nwgy*scale);
    flag.draw_line(xc + nwhx*scale, yc + nwhy*scale, xc + nwgx*scale, yc + nwgy*scale);

    flag.draw_line(xc + nwix*scale, yc + nwiy*scale, xc + nwjx*scale, yc + nwjy*scale);
    flag.draw_line(xc + nwix*scale, yc + nwiy*scale, xc + nwlx*scale, yc + nwly*scale);
    flag.draw_line(xc + nwjx*scale, yc + nwjy*scale, xc + nwkx*scale, yc + nwky*scale);
    flag.draw_line(xc + nwlx*scale, yc + nwly*scale, xc + nwkx*scale, yc + nwky*scale);
    //NE
    flag.draw_line(xc + neax*scale, yc + neay*scale, xc + nebx*scale, yc + neby*scale);
    flag.draw_line(xc + neax*scale, yc + neay*scale, xc + nedx*scale, yc + nedy*scale);
    flag.draw_line(xc + nebx*scale, yc + neby*scale, xc + necx*scale, yc + necy*scale);
    flag.draw_line(xc + necx*scale, yc + necy*scale, xc + nedx*scale, yc + nedy*scale);

    flag.draw_line(xc + neex*scale, yc + neey*scale, xc + nefx*scale, yc + nefy*scale);
    flag.draw_line(xc + neex*scale, yc + neey*scale, xc + nehx*scale, yc + nehy*scale);
    flag.draw_line(xc + nefx*scale, yc + nefy*scale, xc + negx*scale, yc + negy*scale);
    flag.draw_line(xc + nehx*scale, yc + nehy*scale, xc + negx*scale, yc + negy*scale);

    flag.draw_line(xc + neix*scale, yc + neiy*scale, xc + nejx*scale, yc + nejy*scale);
    flag.draw_line(xc + neix*scale, yc + neiy*scale, xc + nelx*scale, yc + nely*scale);
    flag.draw_line(xc + nejx*scale, yc + nejy*scale, xc + nekx*scale, yc + neky*scale);
    flag.draw_line(xc + nelx*scale, yc + nely*scale, xc + nekx*scale, yc + neky*scale);

    flag.draw_line(xc + nemx*scale, yc + nemy*scale, xc + nenx*scale, yc + neny*scale);
    flag.draw_line(xc + nemx*scale, yc + nemy*scale, xc + nepx*scale, yc + nepy*scale);
    flag.draw_line(xc + nepx*scale, yc + nepy*scale, xc + neox*scale, yc + neoy*scale);
    flag.draw_line(xc + nenx*scale, yc + neny*scale, xc + neox*scale, yc + neoy*scale);

    flag.draw_line(xc + neqx*scale, yc + neqy*scale, xc + nerx*scale, yc + nery*scale);
    flag.draw_line(xc + neqx*scale, yc + neqy*scale, xc + netx*scale, yc + nety*scale);
    flag.draw_line(xc + nerx*scale, yc + nery*scale, xc + nesx*scale, yc + nesy*scale);
    flag.draw_line(xc + netx*scale, yc + nety*scale, xc + nesx*scale, yc + nesy*scale);

    //sw
    flag.draw_line(xc + swax*scale, yc + sway*scale, xc + swbx*scale, yc + swby*scale);
    flag.draw_line(xc + swax*scale, yc + sway*scale, xc + swdx*scale, yc + swdy*scale);
    flag.draw_line(xc + swbx*scale, yc + swby*scale, xc + swcx*scale, yc + swcy*scale);
    flag.draw_line(xc + swcx*scale, yc + swcy*scale, xc + swdx*scale, yc + swdy*scale);

    flag.draw_line(xc + swex*scale, yc + swey*scale, xc + swfx*scale, yc + swfy*scale);
    flag.draw_line(xc + swex*scale, yc + swey*scale, xc + swhx*scale, yc + swhy*scale);
    flag.draw_line(xc + swfx*scale, yc + swfy*scale, xc + swgx*scale, yc + swgy*scale);
    flag.draw_line(xc + swhx*scale, yc + swhy*scale, xc + swgx*scale, yc + swgy*scale);

    flag.draw_line(xc + swix*scale, yc + swiy*scale, xc + swjx*scale, yc + swjy*scale);
    flag.draw_line(xc + swix*scale, yc + swiy*scale, xc + swlx*scale, yc + swly*scale);
    flag.draw_line(xc + swjx*scale, yc + swjy*scale, xc + swkx*scale, yc + swky*scale);
    flag.draw_line(xc + swlx*scale, yc + swly*scale, xc + swkx*scale, yc + swky*scale);

    flag.draw_line(xc + swmx*scale, yc + swmy*scale, xc + swnx*scale, yc + swny*scale);
    flag.draw_line(xc + swmx*scale, yc + swmy*scale, xc + swpx*scale, yc + swpy*scale);
    flag.draw_line(xc + swpx*scale, yc + swpy*scale, xc + swox*scale, yc + swoy*scale);
    flag.draw_line(xc + swnx*scale, yc + swny*scale, xc + swox*scale, yc + swoy*scale);

    //se
    flag.draw_line(xc + seax*scale, yc + seay*scale, xc + sebx*scale, yc + seby*scale);
    flag.draw_line(xc + seax*scale, yc + seay*scale, xc + sedx*scale, yc + sedy*scale);
    flag.draw_line(xc + sebx*scale, yc + seby*scale, xc + secx*scale, yc + secy*scale);
    flag.draw_line(xc + secx*scale, yc + secy*scale, xc + sedx*scale, yc + sedy*scale);

    flag.draw_line(xc + seex*scale, yc + seey*scale, xc + sefx*scale, yc + sefy*scale);
    flag.draw_line(xc + seex*scale, yc + seey*scale, xc + sehx*scale, yc + sehy*scale);
    flag.draw_line(xc + sefx*scale, yc + sefy*scale, xc + segx*scale, yc + segy*scale);
    flag.draw_line(xc + sehx*scale, yc + sehy*scale, xc + segx*scale, yc + segy*scale);

    flag.draw_line(xc + seix*scale, yc + seiy*scale, xc + sejx*scale, yc + sejy*scale);
    flag.draw_line(xc + seix*scale, yc + seiy*scale, xc + selx*scale, yc + sely*scale);
    flag.draw_line(xc + sejx*scale, yc + sejy*scale, xc + sekx*scale, yc + seky*scale);
    flag.draw_line(xc + selx*scale, yc + sely*scale, xc + sekx*scale, yc + seky*scale);

    flag.draw_line(xc + semx*scale, yc + semy*scale, xc + senx*scale, yc + seny*scale);
    flag.draw_line(xc + semx*scale, yc + semy*scale, xc + sepx*scale, yc + sepy*scale);
    flag.draw_line(xc + sepx*scale, yc + sepy*scale, xc + seox*scale, yc + seoy*scale);
    flag.draw_line(xc + senx*scale, yc + seny*scale, xc + seox*scale, yc + seoy*scale);

    flag.draw_line(xc + seqx*scale, yc + seqy*scale, xc + serx*scale, yc + sery*scale);
    flag.draw_line(xc + seqx*scale, yc + seqy*scale, xc + setx*scale, yc + sety*scale);
    flag.draw_line(xc + serx*scale, yc + sery*scale, xc + sesx*scale, yc + sesy*scale);
    flag.draw_line(xc + setx*scale, yc + sety*scale, xc + sesx*scale, yc + sesy*scale);

    flag.draw_line(xc + seux*scale, yc + seuy*scale, xc + sevx*scale, yc + sevy*scale);
    flag.draw_line(xc + seux*scale, yc + seuy*scale, xc + sexx*scale, yc + sexy*scale);
    flag.draw_line(xc + sevx*scale, yc + sevy*scale, xc + sewx*scale, yc + sewy*scale);
    flag.draw_line(xc + sexx*scale, yc + sexy*scale, xc + sewx*scale, yc + sewy*scale);

    // fill in the black to white
    flag.draw_line(xc, yc - scale/2, xc, 0);
    flag.draw_line(xc, yc + scale/2, xc, height);
    flag.draw_line(xc - scale/2, yc, 0, yc);
    flag.draw_line(xc + scale/2, yc, width, yc);

    flag.recursive_fill(0, 0);
    flag.recursive_fill(0, height-1);
    flag.recursive_fill(width - 1, 0);
    flag.recursive_fill(width - 1, height - 1);

    flag.save("flag.ppm");

}

@SohamChowdhury完全是无意的,SEXY是东南角,X,Y点坐标。
user137 2014年

3
您的解决方案是唯一在风中飘扬的旗帜的解决方案!
CJ丹尼斯

2

PostScript572477字节

高尔夫代码:

5 5 scale 36 24 translate /R{.75 .05 .19 setrgbcolor}def/B{0 .20 .47 setrgbcolor}def/a 2 3 atan def/b{0 setgray[18 -6 2 12 21 -6 2 12 24 -6 2 12]rectfill 1 setgray{[18 -.5 2 1 24 -.5 2 1]rectfill}if{21 -.5 2 1 rectfill}if}def a neg rotate R 0 0 12 0 180 arc closepath fill B 0 0 12 180 0 arc closepath fill R -6 0 6 0 360 arc closepath fill B 6 0 6 0 360 arc closepath fill true true b 2 a mul rotate false true b 180 rotate true false b -2 a mul rotate false false b
showpage

取消程式码:

5 5 scale                                     % over-all scale
36 24 translate                               % over-all shift
/R {.75 .05 .19 setrgbcolor} def              % prodecure for setting red color
/B {0 .20 .47 setrgbcolor} def                % procedure for setting blue color
/a 2 3 atan def                               % calculate angle = arctan(2/3) = 33.7°
/b {                                          % procedure for drawing bars
 0 setgray                                    %   black
 [18 -6 2 12 21 -6 2 12 24 -6 2 12] rectfill  %   draw 3 bars
 1 setgray                                    %   white
 {[18 -.5 2 1 24 -.5 2 1] rectfill} if        %   conditionally draw gap in inner/outer bars 
 {21 -.5 2 1 rectfill} if                     %   conditionally draw gap in middle bar 
} def
a neg rotate                                  % rotate -33.7°
R 0 0 12 0 180 arc closepath fill             % big red half circle
B 0 0 12 180 0 arc closepath fill             % big blue half circle
R -6 0 6 0 360 arc closepath fill             % small red circle
B  6 0 6 0 360 arc closepath fill             % small blue circle
true true b                                   % draw bars (with gap in all bars)
2 a mul rotate                                % rotate 67.4°
false true b                                  % draw bars (with gap in inner/outer bars)
180 rotate                                    % rotate 180°
true false b                                  % draw bars (with gap in middle bar)
-2 a mul rotate                               % rotate -67.4°
false false b                                 % draw bars (without gaps)
showpage

结果:

结果


1

Python 2,483字节

from math import*
w,k,r,b="255 "*3,"0 "*3,"198 12 48 ","0 52 120 "
print "P3 600 400 255 "
a=atan2(2,3)
c,s=cos(a),sin(a)
T=lambda x,y:(c*x-s*y,s*x+c*y)
S=lambda x,y:150<x<216.6and x%25<16.6and y*y<2500
C=lambda x,y,p=50:(x-p)**2+y*y<2500
for y in range(-200,200):
 for x in range(-300,300):X,Y=T(x,y);W,Z=T(-x,y);print [[w,k][(S(abs(X),Y)and(Y*Y>16or(166.6<X<191.4or-200>X or 0>X>-166.6)))or(S(abs(W),Z)and(W>0 or abs(Z)>4))],[b,r][(Z<0 or C(W,Z))and not C(W,Z,-50)]][W*W+Z*Z<10000]

可能的改进:

  • 硬编码cos,sin常数
  • 二进制PPM
  • 转换为[3,2]平面
  • 优化布尔语句

输出为文本PPM,用法:

python golf_korea.py > korea.ppm

在此处输入图片说明

非高尔夫测试版

from math import*
w,k,r,b="255 255 255 ", "0 0 0 ", "255 0 0 ", "0 0 255 "
g="0 255 0 "
print "P3 600 400 255 "
a=atan2(2,3)
c,s=cos(a),sin(a)
trans=lambda x,y:(c*x-s*y,s*x+c*y)
stripe=lambda x:150<x<216.6 and x%25<16.6
small=lambda x,y,p=50:(x-p)**2+y*y<2500
for y in range(-200,200):
 for x in range(-300,300):
  X,Y=trans(x,y)
  W,Z=trans(-x,y)
  if stripe(abs(X)) and Y*Y<2500:
   if abs(Y)>4:  
    print k
   else:
    if X>0:
     if 166.6<X<191.4:
      print k
     else:
      print w
    else:
     if -200<X<-166.6:
      print w
     else:
      print k
  elif stripe(abs(W)) and Z*Z<2500 and(W>0 or abs(Z)>4):
   print k
  elif W*W+Z*Z<100*100:
   if (Z<0 or small(W,Z)) and not small(W,Z,-50):
    print r
   else:
    print b
  else:
   print w
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.