ํƒœ๊ทธ ๋ณด๊ด€๋ฌผ: popularity-contest

popularity-contest

๋„คํŒ”์˜ ๊ตญ๊ธฐ๋ฅผ ๊ทธ๋ฆฌ์ž ๋„คํŒ”์˜ ๊ตญ๊ธฐ (

๋„คํŒ”์˜ ๊ตญ๊ธฐ ( Wikipedia , Numberphile )๋Š” ๋‹ค๋ฅธ ๊ฒƒ๊ณผ ๋งค์šฐ ๋‹ค๋ฅด๊ฒŒ ๋ณด์ž…๋‹ˆ๋‹ค. ๋˜ํ•œ ํŠน์ • ๋„๋ฉด ์ง€์นจ์ด ์žˆ์Šต๋‹ˆ๋‹ค (Wikipedia ๊ธฐ์‚ฌ์— ํฌํ•จ๋˜์–ด ์žˆ์Œ). ๋„คํŒ”์˜ ๊ตญ๊ธฐ๋ฅผ ๊ทธ๋ฆฌ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค์–ด ๋ณด์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

์‚ฌ์šฉ์ž๋Š” ์š”์ฒญ ๋œ ํ”Œ๋ž˜๊ทธ ๋†’์ด (100 ~ 10000 ํ”ฝ์…€)๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ํ”„๋กœ๊ทธ๋žจ์€ ๋„คํŒ”์˜ ํ”Œ๋ž˜๊ทธ๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. ASCII ์•„ํŠธ์—์„œ OpenGL์— ์ด๋ฅด๊ธฐ๊นŒ์ง€ ๋ชจ๋“  ํ”Œ๋ž˜๊ทธ๋ฅผ ๊ทธ๋ฆฌ๋Š” ๋ฐฉ๋ฒ•์„ ์„ ํƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด๊ฒƒ์€ ์ธ๊ธฐ ๊ฒฝ์—ฐ ๋Œ€ํšŒ์ด๋ฏ€๋กœ 2 ์›” 1 ์ผ์— ๊ฐ€์žฅ ๋งŽ์€ ํ‘œ๋ฅผ ์–ป์€ ๋‹ต์ด ์Šน์ž๊ฐ€ ๋  ๊ฒƒ์ด๋ฏ€๋กœ ์ฝ”๋“œ ๊ธธ์ด๋Š” ๊ฑฑ์ •ํ•˜์ง€ ๋ง๊ณ  ์งง์€ ์ฝ”๋“œ ์ผ์ˆ˜๋ก ๋” ๋งŽ์€ ํˆฌํ‘œ๊ถŒ์„ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ•œ ๊ฐ€์ง€ ์š”๊ตฌ ์‚ฌํ•ญ ๋งŒ ์žˆ์Šต๋‹ˆ๋‹ค. ์›น ๋ฆฌ์†Œ์Šค๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

์žฌ๋ฏธ์žˆ๊ฒŒ ๋ณด๋‚ด์„ธ์š” ๐Ÿ™‚

์œ„ํ‚ค ๋ฏธ๋””์–ด ๊ณต์šฉ์—์„œ ๋„คํŒ”์˜ ๊ตญ๊ธฐ์˜ ์ด๋ฏธ์ง€



๋‹ต๋ณ€

SVG, 1375, 1262, 1036, 999, 943, 939

<svg>
<defs>
<style>.w{fill:white}</style>
<g id="f"><path d="M1,1L1,20L18,20L6,10L17,10z" style="stroke:#003893;fill:#dc143c"/></g>
<g id="m"><polygon points="1,0 -.5,.86 -.5,-.86"/></g>
<g id="b"><polygon points="1,0 -.5,.86 -.5,-.86"/><polygon points="1,0 -.5,.86 -.5,-.86"transform="rotate(32)"/></g>
<g id="t"><use xlink:href="#b"/><use xlink:href="#b"transform="rotate(60)"/></g>
<g id="s">
<use xlink:href="#m"/>
<use xlink:href="#m"transform="rotate(20)"/>
<use xlink:href="#m"transform="rotate(45)"/>
<use xlink:href="#m"transform="rotate(70)"/>
<use xlink:href="#m"transform="rotate(90)"/>
</g>
</defs>
<g transform="scale(.7)">
<use xlink:href="#f" x="5" y="6"transform="scale(19,23)"/>
<use xlink:href="#t" x="2.8" y="7"class="w"transform="scale(70)"/>
<path d="M157,292 A 40,35 0 1 0 237,292 43,45 0 1 1 157,292z"class="w"/>
<use xlink:href="#s" x="5.6" y="8.9"class="w"transform="scale(35)"/>
</g>
</svg>

SVG์—๋Š” ์‹ค์ œ๋กœ ์‚ฌ์šฉ์ž ์ž…๋ ฅ AFAIK๊ฐ€ ์—†์œผ๋ฏ€๋กœ์ด ์ค„์„ ์ˆ˜์ •ํ•˜์—ฌ ๋ฐฐ์œจ์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

<g transform="scale(.7)">


๋‹ต๋ณ€

์ž๋ฐ” ์Šคํฌ๋ฆฝํŠธ, 569 ๊ฐœ 537 495 442 ๋ฌธ์ž (ASCII)

h="";M=Math;Z=M.max;Y=M.min;function d(a,b,r,s,t){n=M.sqrt(a*a+e*e);return n-(r+M.abs((M.atan2(a,e
)/M.PI*b+t)%1-0.5)*s*n)}f=parseInt(prompt(),10);for(g=0;g<f;g++){for(k=0;k<2*f;k++)e=k/(0.5*f)-0.8
,q=g/(0.25*f),u=q-1.08,v=q-1.29,z=e*e+u*u-0.3364,E=Z(-e-0.8,Y(Z(0.62*e+0.8-q,-2.06+q),Z(1*e+0.8+
0.85-q,-3.87+q))),p=0>Y(d(q-2.91,6,0.38,0.7,10),Y(Z(e*e+v*v-0.3025,-z),Z(d(q-1.54,8,0.25,0.6,10.5)
,q-1.7)))?" ":-0.13>E?";":0>=E?"8":"",h+=p;h+="\n"}h

์‹คํ–‰ํ•˜๋ ค๋ฉด ๋ธŒ๋ผ์šฐ์ € ์ฝ˜์†”์— ๋ณต์‚ฌํ•˜์—ฌ ๋ถ™์—ฌ ๋„ฃ๊ธฐ (์˜ˆ : Chrome ๊ฐœ๋ฐœ์ž ๋„๊ตฌ ๋˜๋Š” Firebug)

๊ฒฐ๊ณผ :

8
8888
8888888
8888;88888
8888;;;;88888
8888;;;;;;;888888
8888;;;;;;;;;;;88888
8888;;;;;;;;;;;;;;88888
8888;;;;;;;;;;;;;;;;;88888
8888;;;;;;;;;;;;;;;;;;;;888888
8888;;;;;;;;;;;;;;;;;;;;;;;;88888
8888;;;;;;;;;;;;;;;;;;;;;;;;;;;88888
8888;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;88888
8888;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;88888
8888;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;888888
8888;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;88888
8888;;;;;;;;;;;; ;  ;  ; ;;;;;;;;;;;;;;;;;;;;;;88888
8888;;; ;;;;;               ;;;;; ;;;;;;;;;;;;;;;;88888
8888;;;  ;;;;;;           ;;;;;;  ;;;;;;;;;;;;;;;;;;;888888
8888;;;;   ;;;             ;;;   ;;;;;;;;;;;;;;;;;;;;;;;;88888
8888;;;;;                       ;;;;;;;;;;;;;;;;;;;;;;;;;;;;88888
8888;;;;;;;                   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;88888
8888;;;;;;;;;               ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;88888
8888;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;888888
8888;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;88888
8888;;;;;;;;;;;;;;;;;;;;;;8888888888888888888888888888888888888888888888888888888
8888;;;;;;;;;;;;;;;;;;;;;;;;888
8888;;;;;;;;;;;;;;;;;;;;;;;;;;888
8888;;;;;;;;;;;;;;;;;;;;;;;;;;;;888
8888;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;888
8888;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;888
8888;;;;;;;;;   ;;;   ;;;   ;;;;;;;;;;888
8888;;;;;;;;;;             ;;;;;;;;;;;;;888
8888;;;;                         ;;;;;;;;;888
8888;;;;;;                     ;;;;;;;;;;;;;888
8888;;;;;;;                   ;;;;;;;;;;;;;;;;888
8888;;;                           ;;;;;;;;;;;;;;888
8888;;;;;                       ;;;;;;;;;;;;;;;;;;888
8888;;;;;;;                   ;;;;;;;;;;;;;;;;;;;;;;888
8888;;;;;                       ;;;;;;;;;;;;;;;;;;;;;;888
8888;;;; ;;;;;             ;;;;; ;;;;;;;;;;;;;;;;;;;;;;;888
8888;;;;;;;;;               ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;888
8888;;;;;;;;;  ;;;;   ;;;;  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;888
8888;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;888
8888;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;888
8888;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;888
8888;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;888
8888888888888888888888888888888888888888888888888888888888888888888888888
888888888888888888888888888888888888888888888888888888888888888888888888888

ํŽธ์ง‘ : ST3์ด ์ œ์•ˆํ•œ๋Œ€๋กœ ์‚ฌ์šฉ์ž ์ž…๋ ฅ์œผ๋กœ ๋†’์ด๋ฅผ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค. ํฐ ๊ฐ’์œผ๋กœ ๊ฐ€์žฅ ์ž˜ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค (์˜ˆ : 120)


๋‹ต๋ณ€

๋งค์Šค ๋งค ํ‹ฐ์นด

๋„คํŒ”์˜ ์ž„์‹œ ํ—Œ๋ฒ•-์ œ 1 ์กฐ (์ œ 6 ์กฐ ์ฐธ์กฐ), 260 ๋ฐ 262 ํŽ˜์ด์ง€๋Š” ๊นƒ๋ฐœ ๊ตฌ์„ฑ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ 25 ๊ฐ€์ง€ ์„ธ๋ถ€ ์ง€์นจ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ( http://www.ccd.org.np/resources/interim.pdf ์ฐธ์กฐ ). ์ฃผ์„์˜ ์ˆซ์ž๋Š” ํ—Œ๋ฒ•์˜ ํ•ด๋‹น ์ง€์นจ์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

์ •์‚ผ๊ฐํ˜•์„ ๊ทธ๋ฆฌ๊ณ  ์ ์—์„œ ์„ ๊นŒ์ง€์˜ ๊ฑฐ๋ฆฌ๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” ํ•จ์ˆ˜๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

ClearAll[triangle]
triangle[a_?NumericQ,b_?NumericQ,c_?NumericQ,labeled_:True]:=
Block[{x,y,pt,sqr},sqr=#.#&;
pt[a1_,b1_,c1_]:=Reduce[sqr[{x,y}]==b1^2&&sqr[{x,y}-{a1,0}]==c1^2&&y>0,{x,y}];
{(
(*Polygon[{{0,0},{a,0},{x,y}}]*)
Polygon[{{-a/2(*0*),0},{a/2,0},{x-a/2,y}}]),
If[labeled,
{Text[Style[Framed[a,Background->LightYellow],11],{a/2,0}],
Text[Style[Framed[b,Background->LightYellow],11],{x/2,y/2}],
Text[Style[Framed[c,Background->LightYellow],11],{(a+x)/2,y/2}]},{}]}/.ToRules[pt[a,b,c]]]

(*distance from point to a line *)
dist[line_,{x0_,y0_}]:=(Abs[a x0+b y0+c]/.{x0-> m[[1]],y0-> m[[2]]})/Sqrt[a^2+b^2]; (* used below *)

์ง€์‹œ ์‚ฌํ•ญ์„ ์ฐธ์กฐํ•˜๋Š” ์ˆซ์ž๊ฐ€์žˆ๋Š” ๋‚˜๋จธ์ง€ ์ฝ”๋“œ. ์ง€๊ธˆ๊นŒ์ง€ ๊ฐ€์žฅ ์–ด๋ ค์šด ๋ถ€๋ถ„์€ ๋‹ฌ๊ณผ ํƒœ์–‘์˜ ๊ด‘์„ ์„ ๋งŒ๋“œ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. GeometricalTransformation๋ฒˆ์—ญ ๋ฐ ํšŒ์ „์— ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.

    (*shape inside flag*)
(*1*)
w=100;a={0,0};b={w,0};
lAB=Line[{a,b}];
tA=Text["A",Offset[{-10,-20},a]];
tB=Text["B",Offset[{20,-20},b]];

(*2*)
c={0,w 4/3};d={0,w};
lAC=Line[{a,c}];
tC=Text["C",Offset[{-10,20},c]];
lAD=Line[{a,d}];
tD=Text["D",Offset[{-10,0},d]];
lBD=Line[{b,d}];

(*3*)
e=Solve[(x-w)^2+y^2==(w)^2&&y==w-x,{x,y}][[1,All,2]];
tE=Text["E",Offset[{15,0},e]];

(*4*)
f={0,e[[2]]};tF=Text["F",Offset[{-10,0},f]];
g={w,e[[2]]};tG=Text["G",Offset[{15,0},g]];
lFG=Line[{f,g}];
poly={a,b,e,g,c};

(*5*)lCG= Line[{c,g}];

(*moon*)
(*6*)
lineCG=N[((f[[2]]-c[[2]])/w)x+c[[2]](*100*)];
h={w/4,0};tH=Text["H",Offset[{0,-20},h]];
i={h[[1]],lineCG/.x->h[[1]]};tI=Text["I",Offset[{10,0},i]];
lHI={Dashed, LightGray,Line[{h,i}]};

(*7*)
j={0,f[[2]]+(c[[2]]-f[[2]])/2};tJ=Text["J",Offset[{-10,10},j]];
lineJG=N[((f[[2]]-j[[2]])/g[[1]])x+j[[2]]];
k={Solve[lineCG==j[[2]],x][[1,1,2]],j[[2]]};tK=Text["K",Offset[{10,10},k]];
(*k={Solve[lineCG\[Equal]c[[2]],x][[1,1,2]],j[[2]]};tK=Text["K",Offset[{10,10},k]];*)
lJK={Dashed, LightGray,Line[{j,k}]};

(*8*)l={i[[1]],j[[2]]};tL=Text["L",Offset[{0,10},l]];
(*9*)lJG={LightGray,Dashed,Line[{j,g}]};
(*10*)m={h[[1]],(lineJG/.x-> h[[1]])};tM=Text["M",Offset[{0,10},m]];
(*11*)distMfromBD=dist[{1,1,-w(*100*)},m];
 n={i[[1]],m[[2]]-distMfromBD};tN=Text["N",Offset[{0,0},n]];
(*ln=Abs[l[[2]]-n[[2]]];*)
(*12*)o={0,m[[2]]};tO=Text["O",Offset[{-10,0},o]];
lM={Dashed,LightGray,Line[{o,{g[[1]],o[[2]]}}]};

(*13*)
radiusLN=l[[2]]-n[[2]];
p={m[[1]]-radiusLN,m[[2]]};tP=Text["P",Offset[{0,10},p]];
q={m[[1]]+radiusLN,m[[2]]};tQ=Text["Q",Offset[{0,10},q]];
moonUpperEdge={White,Circle[l,radiusLN,{Pi,2 Pi}]};
moonLowerEdge={White,Circle[m,radiusMQ,{Pi,2 Pi}]};


(*14*)radiusMQ=q[[1]]-m[[1]];


(*15*)radiusNM=m[[2]]-n[[2]];
arc={Yellow,Circle[n,radiusNM,{Pi/7,6 Pi/7}]};
{r,s}=Solve[(x-l[[1]])^2+(y-l[[2]])^2==(radiusLN)^2 &&(x-n[[1]])^2+(y-n[[2]])^2==(radiusNM)^2,{x,y}][[All,All,2]];
tR=Text["R",Offset[{0,0},r]];
tS=Text["S",Offset[{0,0},s]];
t={h[[1]],r[[2]]};
tT={Black,Text["T",Offset[{0,0},t]]};


(*16*)radiusTS=Abs[t[[1]]-s[[1]]];
(*17*)radiusTM=Abs[t[[2]]-m[[2]]];

(*18 triangles*)
t2=Table[GeometricTransformation[GeometricTransformation[triangle[4,4,4,False][[1]],RotationTransform[k Pi/8]],{TranslationTransform[t]}],{k,-4,3}];
midRadius=(Abs[radiusTM+radiusTS]/2-2);
pos=1;table2=GeometricTransformation[t2[[pos++]],{TranslationTransform[#]}]&/@Table[midRadius {Cos@t,Sin[t]},{t,Pi/16,15 Pi/16,\[Pi]/8}];

(*19 sun*)u={0,f[[2]]/2};tU=Text["U",Offset[{-10,0},u]];
lineBD=N[(d[[2]]/w)x+d[[2]]];
v={-Solve[lineBD==u[[2]],x][[1,1,2]],u[[2]]};tV=Text["V",Offset[{10,0},v]];
lUV={LightGray,Dashed,Line[{u,v}]};

(*20*)w={h[[1]],u[[2]]};tW={Black,Text["W",Offset[{0,0},w]]};
(*21*)
(*22*)

t3=Table[GeometricTransformation[GeometricTransformation[triangle[9,9,9,False][[1]],RotationTransform[k Pi/6]],{TranslationTransform[w]}],{k,-3,9}];
midRadius3=(Abs[radiusTM+radiusTS]/2+2.5);
pos=1;
table3=GeometricTransformation[t3[[pos++]],{TranslationTransform[#]}]&/@Table[midRadius3 {Cos@t,Sin[t]},{t,0,2 Pi,2\[Pi]/12}];



Show[
Graphics[{Gray,
(*1*)lAB,tA,tB,
(*2*)lAC,tC,lAD,tD,lBD,
(*3*)tE,
(*4*)tF,lFG,tG,{Red,Opacity[.4],Polygon[poly]},
(*5*)lCG,
(*6*)tH,lCG,tI,lHI,
(*7*)tJ,lJK,tK,
(*8*)tL,
(*9*)lJG,
(*10*)tM,
(*11*)tN,
(*12*)lM,tO,
(*13*)moonUpperEdge,tP,tQ,
(*14*)moonLowerEdge,
(*15*)arc,tR,tS,tT,
(*16*){White,Dashed,Circle[t,radiusTS(*,{0, Pi}*)]},

(*17*){White,Opacity[.5],Disk[t,radiusTM,{0, 2 Pi}]},
(*18 triangles*){White,(*EdgeForm[Black],*)table2},
(*19 sun*)tU,tV,lUV,

(*20*)tW,{Opacity[.5],White,Disk[w,Abs[m[[2]]-n[[2]]]]},
(*21*)Circle[w,Abs[l[[2]]-n[[2]]]],
(*22*){Black(*White*),EdgeForm[Black],triangle[4,4,4,False](*table3*)},
{White,(*EdgeForm[Black],*)table3},

(*23*)
{Darker@Blue,Thickness[.03],Line[{a,b,e,g,c,a}]}

},
Ticks-> None(*{{0,100},{0,80,120,130}}*), BaseStyle-> 16,AspectRatio-> 1.3,Axes-> True],

(*cresent moon*)
RegionPlot[{(x-25)^2+(y-94.19)^2<21.4^2&&(x-25)^2+(y-102.02)^2>21.4^2},{x,0,100},{y,30,130},PlotStyle->{Red,White}]]

์œ„ ์ฝ”๋“œ์—์„œ ๋‹ค์Œ ํ”Œ๋ž˜๊ทธ๋Š” ํ—Œ๋ฒ•์˜ ์ง€์‹œ์— ๋”ฐ๋ผ ๋งŒ๋“ค์–ด์ง‘๋‹ˆ๋‹ค.

๊ตฌ์„ฑ ์„ ์„๋ณด๋‹ค ์‰ฝ๊ฒŒ โ€‹โ€‹๋ณผ ์ˆ˜ ์žˆ๋„๋ก ์ƒ‰์ƒ์ด ์ˆ˜์ •๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๋ฌธ์ž๋Š” ์ง€์นจ์˜ ํฌ์ธํŠธ์™€ ๋ผ์ธ์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.


๊ทธ๊ฑด ๊ทธ๋ ‡๊ณ , Mathematica ๋‚ด์—์„œ ์„ธ๊ณ„์˜ ๊นƒ๋ฐœ์„ ์ง์ ‘ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Graphics[CountryData["Nepal", "Flag"][[1]], ImageSize->{Automatic,200}]


๋‹ต๋ณ€

ํŒŒ์ด์ฌ

import turtle, sys
from math import sqrt, sin, cos, pi

height = int(sys.argv[1])
width = height / 4 * 3
turtle.screensize(width, height)
t = turtle.Turtle()

# the layout
t.pencolor("#0044cc")
t.fillcolor("#cc2244")
t.pensize(width / 25)
t.pendown()
t.fill(True)
t.forward(width)
t.left(135)
t.forward(width)
t.right(135)
t.forward(width / sqrt(2))
t.right(90)
t.goto(0, height)
t.forward(height)
t.fill(False)
t.penup()

# the bottom star
t.fillcolor("#ffffff")
t.pencolor("#ffffff")
t.pensize(1)
radius = width / 5
x = width / 4
y = height / 4
t.goto(x + radius, y)
t.pendown()
t.fill(True)
for i in range(24):
    t.goto(x + radius * (5 + (-1) ** i) / 6 * cos(i * pi / 12), y + radius * (5 + (-1) ** i) / 6 * sin(i * pi / 12))
t.fill(False)
t.penup()

# the top star
radius = width / 9
x = width / 4
y = height * 2 / 3
t.goto(x + radius, y)
t.pendown()
t.fill(True)
for i in range(28):
    t.goto(x + radius * (6 + (-1) ** i) / 7 * cos(i * pi / 14), y + radius * (6 + (-1) ** i) / 7 * sin(i * pi / 14))
t.fill(False)
t.penup()

# the moon
radius = width / 5
x = width / 4
y = height / sqrt(2)
t.goto(x + radius, y)
t.pendown()
t.fill(True)
for i in range(30):
    t.goto(x + radius * cos(i * pi / 30), y - radius * sin(i * pi / 30))
for i in range(30):
    t.goto(x - radius * cos(i * pi / 30), y - radius / 2 * sin(i * pi / 30))
t.fill(False)
t.penup()
t.hideturtle()

raw_input("press enter")

ํŒŒ์ด์ฌ์˜ TK์— ๊ฑฐ๋ถ์˜ ์˜ˆ๋ฅผ ์‚ฌ์šฉ python nepal.py 150ํ•˜๊ณ  python nepal.py 200๊ฐ๊ฐ์„ :


๋‹ต๋ณ€

R ( ๊ธธ์ด ์— ๋Œ€ํ•ด ์ด์•ผ๊ธฐํ•˜์ง€ ๋ง์ž )

nepaliflag = function(imaginary = FALSE, color = c("red", "white", "blue")){
    #Draws flag of Nepal with default colors red for inner area, white for Sun and Moon,
    #and blue for outer border
    #Based on instructions from http://www.servat.unibe.ch/icl/np01000_.html
    #Coded by Darshan Baral, with help from Urja Acharya
    #Fork at https://github.com/darshanbaral/R_codes/blob/master/nepali_flag.r
    graphics.off()
    windows(width = 6, height = 8)
    par(mar = c(3, 0.5, 2, 0.5))
    fs = 1 #Arbitrary scale unit for flag
    plot(fs, fs, xlim = c(0, fs), ylim = c(0, 1.5*fs),
         type = "p", pch = NA, axes = FALSE,
         xlab = "", ylab = "",
         asp = 1)

    title(main = "Flag of Nepal")

    #Perpendicular distance from a to bc
    dist_point_line <- function(a, b, c) {
        v1 <- b - c
        v2 <- a - b
        m <- cbind(v1,v2)
        return(abs(det(m))/sqrt(sum(v1*v1)))
    }

    #Distance from a to b
    dist_2_points <- function(a, b) {
        return(sqrt((a[1]-b[1])^2+(a[2]-b[2])^2))
    }

    #Intersection between lines ab and mn
    lines_intersection = function(a,b,m,n){
        A1 = b[2] - a[2]
        B1 = a[1] - b[1]
        C1 = a[1]*b[2] - a[2]*b[1]

        A2 = n[2] - m[2]
        B2 = m[1] - n[1]
        C2 = m[1]*n[2] - m[2]*n[1]

        Delta = A1*B2 - A2*B1
        if(Delta == 0){
            return("Lines are parallel")
        } else {
            x = (B2*C1 - B1*C2)/Delta
            y = (A1*C2 - A2*C1)/Delta
            return(c(x,y))
        }
    }

    A = c(0,0)
    B = c(fs, 0)
    C = c(0, 4*B[1]/3)
    D = c(0, B[1])
    E = c( (B[1] - B[1]/sqrt(2)), B[1]/sqrt(2) )
    tE = c(E[1], A[2]) #Projecting E onto x-axis
    F = c(0, E[2] )
    G = c(B[1], E[2] )

    F_C = dist_2_points(F,C) #Distance between points F and C
    F_G = dist_2_points(F,G)
    B_tE = dist_2_points(B,tE)
    E_tE = dist_2_points(E,tE)

    upper_angle = pi/2 - atan(F_C/F_G) #Corner angle of upper triangle
    lower_angle = pi/2 - atan(E_tE/B_tE) #Corner angle of bottom triangle

    H = c(B[1]/4,0)
    I = c(H[1], G[2]+(G[1]-H[1])*(C[2]-F[2])/G[1] )
    J = c(0, 0.5*(C[2] + F[2]) )
    K = c( (C[2]-J[2])*G[1]/(C[2]-F[2]), J[2])
    L = c(H[1],J[2])
    M = lines_intersection(J, G, H, I)
    M_BD = dist_point_line(M, B, D) #Perpendicular distance between point M and line BD
    N = c(H[1], M[2]-M_BD)
    O = c(0, M[2])
    L_N = dist_2_points(L, N)
    L_M = dist_2_points(L, M)
    P = c(M[1] - sqrt(L_N^2 - L_M^2), M[2])
    Q = c(M[1] + sqrt(L_N^2 - L_M^2), M[2])
    L_Q = dist_2_points(L, Q)
    M_Q = dist_2_points(M, Q)
    M_N = dist_2_points(M, N)

    #Points of intersection of two circles
    temp_1 = (L_Q^2 - M_N^2 + M_N^2 ) / (2 * M_N)
    temp_2 = sqrt(L_Q^2 - temp_1^2)

    R = c(N[1]-temp_2, L[2]-temp_1)
    S = c(N[1]+temp_2, L[2]-temp_1)
    T = c(H[1], R[2])
    T_N = dist_2_points(T, N)
    T_S = dist_2_points(T, S)
    T_M = dist_2_points(T, M)

    U = c(A[1], 0.5 * (A[2]+F[2]))
    temp_U = c(H[1],U[2])
    V = lines_intersection(U, temp_U, B, E)
    W = c(H[1], U[2])

    #Draw inner polygon in red
    area = rbind(G, C, A, B, E)
    polygon(area, col = color[1], border = NA)

    #Draw Moon arcs
    symbols (x = L[1], y = L[2], circles=c(L_N), add =TRUE, inches=FALSE, fg = NA, bg = color[2])
    symbols (x = M[1], y = M[2], circles=c(M_Q), add =TRUE, inches=FALSE, fg = NA, bg = color[2])
    symbols (x = L[1], y = L[2], circles=c(L_N), add =TRUE, inches=FALSE, fg = NA, bg = color[1])
    symbols (x = T[1], y = T[2], circles=c(T_M), add =TRUE, inches=FALSE, bg = color[2], fg = NA)

    #Draw Sun circles
    symbols (x = W[1], y = W[2], circles=c(M_N), add =TRUE, fg = NA, inches=FALSE, bg = NA)

    #Obtain points of triangles of the Sun
    sun_points = c(0,0)
    theta = 0
    for (i in 1:24){
        if (i %% 2 != 0){
            sun_points = rbind( sun_points, c( W[1]+L_N*cos(theta), W[2]+L_N*sin(theta)) )
        } else {
            sun_points = rbind( sun_points, c( W[1]+M_N*cos(theta), W[2]+M_N*sin(theta)) )
        }
        theta = theta + 2*pi/24
    }
    sun_points = sun_points[2:25,]

    #Obtain points of triangles of the Moon
    moon_points = c(0,0)
    theta = 0 - pi/8
    for (i in 1:20){
        if (i %% 2 != 0){
            moon_points = rbind( moon_points, c( T[1]+T_M*cos(theta), T[2]+T_M*sin(theta)) )
        } else {
            moon_points = rbind( moon_points, c( T[1]+T_S*cos(theta), T[2]+T_S*sin(theta)) )
        }
        theta = theta + pi/16
    }
    moon_points = moon_points[2:21,]

    par(xpd = TRUE)

    Ax = c(A[1] - T_N, A[2]) #Shift A to the left with a distance of TN
    Cx = c(C[1] - T_N, C[2])
    Ay = c(A[1], A[2] - T_N)
    By = c(B[1], B[2] - T_N) #Shift B to the bottom with a distance of TN

    Gx = c(G[1] + T_N, G[2])
    Gy = c(G[1], G[2] - T_N)
    Ey = c(E[1], E[2] - T_N)

    Kx = c(K[1] + T_N/cos(upper_angle), K[2]) #a point on parallel line TN away from upper slanting line
    Ix = c(I[1] + T_N/cos(upper_angle), I[2]) #another point on parallel line TN away from upper slanting line

    Bb = c(B[1] + T_N/cos(lower_angle), B[2]) #a point on parallel line TN away from lower slanting line
    Ee = c(E[1] + T_N/cos(lower_angle), E[2]) #another point on parallel line TN away from lower slanting line

    #Point of intersection for offsetting borders in corners
    Ap = lines_intersection(Ax, Cx, Ay, By)
    Cp = lines_intersection(Kx, Ix, Ax, Cx)
    Gp = lines_intersection(Ix, Kx, Ey, Gy)
    Ep = lines_intersection(Bb, Ee, Ey, Gy)
    Bp = lines_intersection(Ay, By, Ee, Bb)

    #Draw triangles for Sun and Moon
    polygon(sun_points, col = color[2], border = NA)
    polygon(moon_points, col = color[2], border = NA)

    #Draw outer border
    borders = rbind(B, Bp, Ap, Cp, Gp, Ep, Bp, B, A, C, G, E, B)
    polygon(borders, col=color[3], border = NA)

    #Draw white polygon on outside of upper triangle to get rid of part of initial circle
    outer_white = rbind(Cp,Gp,c(Gp[1],Cp[2]))
    polygon(outer_white,col = "white", border = NA)

    #Draw grids, cirlces, and points if imaginary is TRUE
    if (imaginary == TRUE){
        main_points = rbind(A, B, C, D, E, F, G, H, I, J, K, L, M, N,
                            O, P, Q, R, S, T, U, V, W)
        points(main_points, pch = 19, cex = 0.5)
        text(main_points, c("A", "B", "C", "D", "E", "F", "G", "H", "I",
                            "J", "K", "L", "M", "N", "O", "P", "Q", "R",
                            "S", "T", "U", "V", "W"), pos = 3, font =2)
        lines(rbind(H,I), lty = 2)
        lines(rbind(J,G), lty = 2)
        lines(rbind(J,K), lty = 2)
        lines(rbind(U,V), lty = 2)

        #Draw Moon arcs
        symbols (x = L[1], y = L[2], circles=c(L_N), add =TRUE, inches=FALSE, bg = NA)
        symbols (x = M[1], y = M[2], circles=c(M_Q), add =TRUE, inches=FALSE, bg = NA)
        symbols (x = N[1], y = N[2], circles=c(M_N), add =TRUE, inches=FALSE, bg = NA)
        symbols (x = T[1], y = T[2], circles=c(T_S), add =TRUE, inches=FALSE, bg = NA)
        symbols (x = T[1], y = T[2], circles=c(T_M), add =TRUE, inches=FALSE, bg = NA)

        #Draw Sun circles
        symbols (x = W[1], y = W[2], circles=c(M_N), add =TRUE, inches=FALSE, bg = NA)
        symbols (x = W[1], y = W[2], circles=c(L_N), add =TRUE, inches=FALSE, bg = NA)
    }
}


๋‹ต๋ณ€

ํŒŒ์ด์ฌ (+ PIL), 578

์˜ค๋Š˜ ์‹ฌ์‹ฌํ•ด์„œ ..

from PIL import Image,ImageDraw
from math import*
I,k,l,m,n,o,_=Image.new('P',(394,480)),479,180,465,232,347,255;D=ImageDraw.Draw(I);P,G=D.polygon,D.pieslice
I.putpalette([_,_,_,0,0,_,_,20,60])
def S(x,y,r,e,l,b):
 p,a,h=[],2*pi/e,r*l;c,d=[0,-a/2][b],[a/2,0][b]
 for i in range(e):p+=[(x+r*cos(i*a+c),y+r*sin(i*a+c)),(x+h*cos(i*a+d),y+h*sin(i*a+d))]
 P(p,fill=0)
P([(0,0),(393,246),(144,246),(375,k),(0,k)],fill=1)
P([(14,25),(o,n),(110,n),(o,m),(14,m)],fill=2)
S(96,o,68,12,.6,0)
G([(31,90),(163,221)],0,l,fill=0)
G([(28,68),(166,200)],0,l,fill=2)
S(96,178,40,16,.7,1)
I.show()


๋‹ต๋ณ€