BBC BASIC
Rev B, 234 bytes
Instead of drawing one white and one red cross, we draw 100 progressively narrower crosses, switching from white background to red foreground at a coordinate of 60.
p=20761m=1049w=600h=300F.i=-1TO1V.29,w;h;18;4,m;134*i;0;m;w*i;-233;p;0;466;m;0;67*i;m;-466;h*i;p;932;0;18;1,m;511*i;h*i;25;89*i;0;29977;0;0;m;w*i;-h*i;28953;0;45*i;
N.F.c=-100TO0q=25881-c DIV60*512V.m;-c;-h;q;c;h;m;-w;-c;q;w;c;
N.
Download interpreter free at http://www.bbcbasic.co.uk/bbcwin/bbcwin.html
Fully golfed, 249 bytes
Single byte VDU codes e.g 25,0
combined into double-byte little endian e.g 25;
and maximum use of constants for common values. Keywords compressed to abbreviated form, e.g. FOR
=>F.
(interpreter expands automatically.)
p=20761q=26393r=25881m=1049c=100w=600h=300F.i=-1TO1V.29,w;h;18;4,m;134*i;0;m;w*i;-233;p;0;466;m;0;67*i;m;-466;h*i;p;932;0;18;1,m;511*i;h*i;25;89*i;0;29977;0;0;m;w*i;-h*i;28953;0;45*i;
N.V.m;-c;-h;q;c;h;2m;-w;-c;q;w;c;m;-60;-h;r;60;h;m;-w;-60;r;w;60;
Semigolfed
Raw VDU codes. In BBC BASIC, characters can be sent to the VDU controller like VDU65
(prints an A.) There are certain special characters particular to the BBC for graphics. These must be followed by several other bytes to specify coordinates, etc. Here we use PLOT
=>VDU25
, GCOL
=>VDU18
, ORIGIN
=>VDU29
.
c=100w=600h=300 :REM constants 100,width,height
FORi=-1TO1 :REM loop -1 and 1 (0 draws nothing)
VDU29,w;h; :REM set origin (bring inside loop for golfing reasons)
VDU18;4 :REM change to blue and draw triangles
VDU25,4,134*i;0;25,4,w*i;-233;25,81,0;466;25,4,0;67*i;25,4,-466;h*i;25,81,932;0;
VDU18;1 :REM change to red and draw parallelograms
VDU25,4,511*i;h*i;25,0,89*i;0;25,117,0;0;25,4,w*i;-h*i;25,113,0;45*i;
NEXT
VDU25,4,-c;-h;25,103,c;h;25,4,-w;-c;25,103,w;c; :REM draw white background rectangles
VDU25,4,-60;-h;25,101,60;h;25,4,-w;-60;25,101,w;60; :REM draw red foreground rectangles
First we draw half the diagonal parts: 2 blue triangles and 2 red parallelograms. Then we change the scale from -1 to +1 and draw the other half. Finally we draw the horizontal and vertical parts on top: 2 white rectangles to form a white cross, then 2 red rectangles. The image after the first iteration of the loop is shown below, along with the final image.
![enter image description here](../../I/static/images/77d0aba48bef848498a333d569b883034b08b8c8af111bd0e7357065676bef20.png)
Ungolfed code
BBC basic remembers the last 2 locations of the graphics cursor. PLOT81 draws a triangle between the new coordinates specified and these last two locations. PLOT113 and PLOT117 draw a parallelogram in a similar way: three corners of the parallelogram have to be given in the order they are found going round the perimeter. The last three bits of the PLOT code define whether the given coordinates are absolute or relative, and whether foreground or background colour is used. The more significant bits define what type of shape is drawn (point, line, triangle, parallelogram, rectangle, etc.)
ORIGIN600,300 :REM move the origin (which will be centre of flag) away from the corner of the screen.
FORi=-1TO1 :REM at scales of -1 and 1, plot half each of the diagonal parts (i=0 plots nothing).
GCOL0,4 :REM blue foreground colour
PLOT4,134*i,0 :REM absolute move to peak of upper/lower triangle
PLOT4,600*i,-233 :REM absolute move to left hand corner
PLOT81,0,466 :REM relative move to right hand corner, plotting triangle
PLOT4,0,67*i :REM absolute move to peak of left/right triangle
PLOT4,-466,300*i :REM absolute move to lower corner
PLOT81,932,0 :REM relative move to upper corner, plotting triangle
GCOL0,1 :REM red foreground colour
PLOT4,511*i,300*i :REM absolute move to long edge of flag
PLOT0,89*i,0 :REM relative move to corner of flag (top right / bottom left)
PLOT117,0,0 :REM absolute move to centre of flag, plotting parallelogram (stripe)
PLOT4,600*i,-300*i :REM absolute move to corner of flag (bottom right / top left)
PLOT113,0,45*i :REM relative move to short edge of flag, plotting parallelogram (stripe)
NEXT :REM diagonal parts completed, now plot vertical/horizontal parts on top.
PLOT4,-100,-300 :REM move to bottom left of vertical white stripe
PLOT103,100,300 :REM move to top right corner, plot it in background colour (white)
PLOT4,-600,-100 :REM move to bottom left corner of horizontal white stripe
PLOT103,600,100 :REM move to top right corner, plot it in background colour (white)
PLOT4,-60,-300 :REM move to bottom left of vertical red stripe
PLOT101,60,300 :REM move to top right corner, plot it in foreground colour (red)
PLOT4,-600,-60 :REM move to bottom left corner of horizontal red stripe
PLOT101,600,60 :REM move to top right corner, plot it in foreground colour (red)
Related, ASCII version – Fatalize – 2016-08-25T11:46:15.820
11"There are many "draw x flag" challenges, and upon searching it turns out there are no challenges to draw the" could be followed by any of thousands of national, organisational, state, etc. flags. What does this flag have which makes drawing it a fundamentally different challenge from all of the existing [tag:graphical-output] questions? – Peter Taylor – 2016-08-25T11:59:07.740
1This is a lot like the Iceland flag challenge, however I find this one has a particular twist in the construction of the diagonal stripes. Since they have rotational symmetry but not exact reflective symmetry, it adds an extra layer to the complexity. Most of the strategies for the Iceland flag would not be a simple conversion to get this one. – GuitarPicker – 2016-08-30T02:24:43.390
Not harder than the Portuguese flag! – sergiol – 2017-08-26T12:49:42.080