9
\$\begingroup\$

Challenge

Create the image of a progress pride flag.

Output

Progress pride flag

Dimensions

Dimensions

Rules

  • Your program must create the image and not just load it from a website

  • The colours can be just your language's default if it is very difficult / impossible to load RGB values, else they should be: red: (255,0,0), orange: (255,140,0), yellow: (255,240,0), green: (0,138,40), (dark) blue: (0,80,255), purple: (120,0,140), black: (0,0,0), brown: (100,50,20), (light) blue: (110,220,240), pink: (255,180,200), white: (255,255,255)

  • The flag can be a scaled up version of the one shown, but the dimensions given are the smallest size allowed. An error of 1 pixel is allowed.

  • Please include an image of the output of your program.

This post was (somewhat) inspired by this one.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ but the dimensions given are the smallest size allowed -> graphical-output challenges are good candidates for answers on old-school systems such as Commodore 64/128, Atari ST, Apple ][, etc. But 1059x672 is too large for them. :-/ \$\endgroup\$
    – Arnauld
    Jul 1 at 14:05
  • 1
    \$\begingroup\$ @Arnauld I've given an answer in BBC BASIC, but it's on an enhanced emulator with higher resolution and more colours. The original BBC BASIC considered coordinates of 1280x1024 for the screen but the actual resolution was less (and varied depending on the screen mode selected.) This was one of many features included to allow for future expansion. \$\endgroup\$ Jul 3 at 0:32

4 Answers 4

5
\$\begingroup\$

C (GCC), 192 176 bytes

char*r="binary stuff (see ATO)";i,j;main(x){write(1,"P6 1059 672 255 ",16);for(;i<672;++i)for(j=0;j<1059;++j)write(1,r+((x=abs(i-336)+j)<504?6+x/84:i/112)*3,3);}

-16 bytes thanks to @ceilingcat

Attempt this online! (you must set encoding to Base64)

Outputs a PPM image.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ Just to understand: The ATO link says the binary stuff is 239 bytes. Why it’s not included in the answers total? \$\endgroup\$
    – hdrz
    Jul 2 at 17:44
  • \$\begingroup\$ I linked a wrong ATO (I didn't set base64 as encoding) \$\endgroup\$
    – matteo_c
    Jul 2 at 18:31
  • \$\begingroup\$ I wasn't able to link an ATO with base64 preselected: in base64 it's 239 bytes, decoded it's 176 \$\endgroup\$
    – matteo_c
    Jul 2 at 18:37
  • \$\begingroup\$ Thanks, obviously it should be base64, I should have guessed \$\endgroup\$
    – hdrz
    Jul 2 at 21:30
  • \$\begingroup\$ I think the first write() can be a printf() \$\endgroup\$
    – ceilingcat
    Jul 3 at 15:59
4
\$\begingroup\$

Java 17, 475 bytes

import java.awt.*;v->new Frame(){public void paint(Graphics g){int i=0;for(;i<6;g.fillRect(168,i++*112+25,891,112))g.setColor(new Color(i<3?255:i/5*120,i%5<1?0:i<3?140+i/2*100:i<4?138:80,i<3?0:i<4?40:i<5?255:140));for(i=0;i<4;g.fillPolygon(new int[]{0,0,(i+2)*84,i/3*84,i<1?0:~-i*84,(i+3)*84},new int[]{109-i*84,193-i*84,361,(i<3?6+i:8)*84+25,i++<1?613:697,361},6))g.setColor(new Color(i<1?255:i<2?110:i<3?100:0,i<1?180:i<2?220:i<3?50:0,i<1?200:i<2?240:i<3?20:0));}{show();}}

enter image description here

Explanation:

TODO: Will try to golf it some more first.

\$\endgroup\$
3
\$\begingroup\$

BBC Basic 210 190 bytes

Golfing mainly comprises removal of unnecessary whitespace and use of abbreviations for keywords. At one point VDU25,0 is condensed to a single 16-bit value V.25; (the ; delimiter denotes that the preceding value is a 16-bit value instead of 8-bit.). At another, VDU25,101 is replaced with the higher level command PLOT101

MODE27h=672F.i=1TO33j=i MOD3IFj=1V.19,7,16
V.(ASCM."8 < 0S o(SP S< S     4*$6LPSDHSSS",i,1)-32)*5MOD257
IFj N.
IFi<19PLOT101,i MOD2*1782+336;h*i/9ELSEV.25;h;-h;25,81,-h;-h;25,97,-168;h*2;
N.

Download interpreter at https://www.bbcbasic.co.uk/bbcwin/download.html

This interpreter has certain features not included in the original BBC basic. It allows for larger screen modes and more colours. MODE 27 is 1280x960 pixels but the coordinate system is double that at 2560x1920.

The original BBC basic had (depending in screen mode) a maximum of 16 logical colours displayed at one time (to save memory) but there was facility to change these colours to any 18-bit physical colour using VDU19. This would instantaneously change the colour of all pixels of that colour on the screen (which was useful for fast animation.) This interpreter works differently. On execution of a VDU19 colours of existing pixels do not change, only newly drawn ones, and full 24-bit colour is supported.

Selecting the colour is a major part of this code, with 33 different RGB values. Most of them are divisible by 5, so I compressed them into printable ASCII by dividing by 5 and adding 32. The one exception is 138 for the green, which is taken as a larger number mod 257

Stripes are drawn using absolute coordinates with x=1059*2=2118 at the right and x=168*2=336 at the left. This leaves the graphics cursor in the correct position at the top right of the black chevron. 19VDU25,101,i MOD2*1782+336 causes the graphics cursor to zigzag from the default location in the bottom left corner of the screen to the top left corner of the red bar. The code 101 is for a rectangle defined by its opposite corners.

Chevrons are drawn using relative coordinates as a house-shape rotated 90 degrees, comprising a triangle and a rectangle. Subsequent chevrons overdraw the house shape to produce the correct chevron shape.

The graphics cursor is already at top right from the previous operation. It moves diagonally to the centre right point VDU25,0,h;-h;, then a triangle is drawn linking the last two positions of the graphics cursor to the bottom right VDU25,81,-h;-h;. The shape is completed by drawing a rectangle to the top left VDU25,97,-168;h*2; which leaves the cursor in the correct position for the next chevron.

After the brown chevron, certain parts of the final three chevrons are off the left side of the screen and are therefore not plotted.

First working version

MODE27
h=672
FORi=1TO33
j=i MOD3
IFj=1VDU19,7,16
VDU(ASCMID$("8 < 0S o(SP S< S     4*$6LPSDHSSS",i,1)-32)*5MOD257
IFj NEXT
IFi<19VDU25,101,i MOD2*1782+336;i/9*h;ELSEVDU25,0,h;-h;25,81,-h;-h;25,97,-168;h*2;
NEXT

Commented Code

MODE27                         :REM select screen mode with 2560x920 logical coordinates, 1280x960 pixels
h=672                          :REM half the logical height of the flag
FORi=1TO33                     :REM iterate R,G,B through 11 colours
j=i MOD3                       :REM if i MOD 3 = 1 tell VDU controller to expect a redefiniton of default logical colour 7  
IFj=1VDU19,7,16                :REM (below) extract R,G or B value from 1-indexed string, send to VDU controller
VDU(ASCMID$("8 < 0S o(SP S< S     4*$6LPSDHSSS",i,1)-32)*5MOD257
IFj NEXT                       :REM if i MOD 3 is not 0 draw nothing yet 
IFi<19VDU25,101,i MOD2*1782+336;i/9*h;ELSEVDU25,0,h;-h;25,81,-h;-h;25,97,-168;h*2;
NEXT                           :REM (above) if i MOD 3 = 0 draw a bar if i<19, otherwise draw a chevron.

enter image description here

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

PostScript, 156 ... 115 bytes

00000000: 3020 3087 6101 3232 3492 7f28 ffff ffff  0 0.a.224..(....
00000010: b4c8 6edc f064 3214 0000 00ff 0000 ff8b  ..n..d2.........
00000020: 00ff f000 0089 4800 50ff 7800 8b29 7b32  ......H.P.x..){2
00000030: 3535 9236 7d92 4936 7b92 9d30 2030 8761  55.6}.I6{..0 0.a
00000040: 0133 3892 8030 8870 3392 3692 ad7d 9283  .38..0.p3.6..}..
00000050: 3136 3888 9092 ad31 3335 9288 357b 929d  168....135..5{..
00000060: 3020 3087 e703 9238 9280 8814 3230 92ad  0 0....8....20..
00000070: 7d92 83                                  }..

Before tokenization:

0 0 353 224 rectclip
<FFFFFFFFB4C86EDCF0643214000000FF0000FF8B00FFF0000089480050FF78008B>{255 div}forall
6{setrgbcolor 0 0 353 38 rectfill 0 112 3 div translate}repeat
168 -112 translate 135 rotate
5{setrgbcolor 0 0 999 dup rectfill 20 20 translate}repeat

output

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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