46
\$\begingroup\$

Draw the ionising-radiation-hazard-symbol in an arbitrary colour on a distinctly coloured background. The specific proportions were published in the June 27th 1974 issue of the Federal Register of the US Government.

Details

  • As output, writing to a file (raster and vector formats are permitted) or displaying on the screen are both allowed.

  • You can draw just the border or the filled shape.

  • If you use raster images, you should take a parameter (or two) as input that lets you adjust the resolution of the output (e.g. width/height).

  • The background must at least have the size of the bounding box of the symbol but may be larger.

  • Outputting the unicode symbol ☢ is not sufficient.

  • The exact ratios of the used distances are given in following diagram (which was originally from here):

Related: Draw the ☣ (Biohazard Symbol)

\$\endgroup\$
10
  • \$\begingroup\$ Can I take an input n such that the image has width 2*n+1? \$\endgroup\$
    – Luis Mendo
    Nov 23, 2019 at 18:50
  • \$\begingroup\$ @LuisMendo Sure! \$\endgroup\$
    – flawr
    Nov 23, 2019 at 19:42
  • 1
    \$\begingroup\$ Is it ok to return an integer matrix of 0s and 1s as the representation of the bitmap image? \$\endgroup\$ Nov 23, 2019 at 21:36
  • 2
    \$\begingroup\$ @NickKennedy I'd say a matrix just as a data type is not enough, but if it is printed nicely with two different characters as the "colours" (and no separators in between) it should be ok. \$\endgroup\$
    – flawr
    Nov 24, 2019 at 8:37
  • 1
    \$\begingroup\$ @mypronounismonicareinstate I added the twos suggestions in the "defaults for IO" on meta, please vote. (1) (2) \$\endgroup\$
    – flawr
    Nov 24, 2019 at 9:43

37 Answers 37

1
2
1
\$\begingroup\$

C (GCC), 176 bytes

main(r,w,j){scanf("%d",&r);w=r*6;float d,h,i=-w;for(printf("P5\n%d %d\n1\n",2*w,2*w);++i<w;)for(j=-w;j<w;)d=(i*i+j*j)/r/r,h=i/abs(j++),putchar(d>1&(2.25>d|d>25|h<-2|h>0&h<2));}

Attempt This Online!

Intended version:

main(r,w,j){
    scanf("%d",&r);
    w=r*6;
    float d,h,i=-w;

    for(printf("P5\n%d %d\n1\n",2*w,2*w);++i<w;)
        for(j=-w;j<w;)
            d=(i*i+j*j)/r/r,
            h=i/abs(j++),
            putchar(d>1&(2.25>d|d>25|h<-2|h>0&h<2));
}

Outputs a binary (black and white) PGM image.

With the following changes (and ~20 bytes less), it can output an ASCII image:

  • remove the printf call and add puts("") after ++i<w;
  • add a ternary operator (or some arithmetical hacks) in the last line to replace the boolean value with two printable chars
\$\endgroup\$
1
\$\begingroup\$

QBasic, 176 bytes

INPUT r
SCREEN 11
a=1.047
CIRCLE(r,r),r/5
FOR i=0TO 5
j=1AND i
k=i-j
CIRCLE(r,r),r-j*r*.7,,k*a,k*a+a
x=COS(i*a)
y=SIN(i*a)
LINE(r+r*x,r+r*y)-(r+r*x*.3,r+r*y*.3)
NEXT

Takes the radius of the figure (i.e. \$5R\$ in the diagram) as input.

You can try it at Archive.org; here's what the output looks like for an input of 100:

QBasic drawing of radiation symbol

Explanation

INPUT r

Input the radius.

SCREEN 11

Clear the screen and put it in graphics mode. Normally, I use SCREEN 9, but it doesn't seem to draw very circular circles, so the arcs didn't line up with the lines. SCREEN 11 did the trick for +1 byte.

a=1.047

Save \$\pi/3\$ in a variable.

CIRCLE(r,r),r/5

Draw the central circle, centered at \$(r,r)\$, with a radius of \$r/5\$.

FOR i=0TO 5

Loop six times. Each time through the loop, we're going to draw one arc and one line segment.

j=1AND i
k=i-j

Set j to i mod 2 using bitwise AND. Then set k to the value of i, "rounded down" to the nearest even number.

 i | j | k
---|---|---
 0 | 0 | 0
 1 | 1 | 0
 2 | 0 | 2
 3 | 1 | 2
 4 | 0 | 4
 5 | 1 | 4

We use k to calculate the starting angle of each arc, and j to determine its radius:

CIRCLE(r,r),r-j*r*.7,,k*a,k*a+a

The CIRCLE command can take extra arguments indicating the starting and ending angles in radians. Here, we draw an arc centered at \$(r,r)\$, with a radius of \$r-j \cdot r \cdot \frac7{10}\$: that is, \$r\$ when j is 0, and \$\frac3{10}r\$ when j is 1. The starting angle is \$k \cdot a\$ and the ending angle is \$k \cdot a + a\$ (so \$0\$ to \$\frac\pi3\$ on the first two iterations, \$\frac{2\pi}3\$ to \$\pi\$ on the next two, and \$\frac{4\pi}3\$ to \$\frac{5\pi}3\$ on the last two).

x=COS(i*a)
y=SIN(i*a)

To draw the line segments, we'll need to calculate their endpoints. First we calculate the x and y coordinates of a point on the unit circle at each of our six angles.

LINE(r+r*x,r+r*y)-(r+r*x*.3,r+r*y*.3)

Then we scale each point by \$r\$ and \$\frac3{10}r\$, translate both of those points by \$r\$, and draw a line between them.

NEXT

And continue to the next value of i.

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

PostScript, 83 81 43 41 bytes

00000000: 2f61 7b92 9b30 8768 0192 0592 a77d 9233  /a{..0.h.....}.3
00000010: 347b 3730 7d92 8335 880a 615b 3334 5d30  4{70}..5..a[34]0
00000020: 9294 3332 2e35 8823 61                   ..32.5.#a

Before tokenization (78 bytes):

/a{setlinewidth 0 360 arc stroke}def
4{70}repeat
5 10 a[34]0 setdash
32.5 35 a

Just two stroked circles, the larger one with a very thick dashed stroke. The dash width 34 seems close enough to the "correct" value of \$32.5\pi/3=34.033...\$ to make no visual difference.

output rendered by Preview.app

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

Pikchr, 153 bytes

color=-1
define${go 2heading 30*}
define@{
line from 0,0$$1$$2close fill white}
define o{
circle at 0,0fill}
o 0ht 2o white ht.6@(1,9)@(3,7)@(9,5)o 0ht.4

Output

Requires the browser to be in light mode.

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 580.32 503.151">
<circle cx="290" cy="251" r="144" style="fill:rgb(0,0,0);"></circle>
<circle cx="290" cy="251" r="43.2" style="fill:rgb(255,255,255);"></circle>
<path d="M290,251L434,2L146,2Z" style="fill:rgb(255,255,255);"></path>
<path d="M290,251L578,251L434,500Z" style="fill:rgb(255,255,255);"></path>
<path d="M290,251L2,251L146,500Z" style="fill:rgb(255,255,255);"></path>
<circle cx="290" cy="251" r="28.8" style="fill:rgb(0,0,0);"></circle>
</svg>

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

JavaScript, 53 bytes

s=>(x,y,r=(x*x+y*y)/s)=>r<4|r>9&r<100&(4*x*x/s<r^y<0)

A function taking a scale s as input, and outputs a pixel shader taking x and y between -s/2 and s/2.

I took inspiration from Arnauld's answer.

shader =
s=>(x,y,r=(x*x+y*y)/s)=>r<4|r>9&r<100&(4*x*x/s<r^y<0)

const scale = 400;

const canvas = document.getElementById('canvas');
canvas.width = canvas.height = scale;
const ctx = canvas.getContext('2d');

let x, y;
for (x = 0; x < scale; x++) for (y = 0; y < scale; y++) {
  ctx.fillStyle = shader(scale)(x - scale / 2, y - scale / 2) ? 'black' : 'yellow';
  ctx.fillRect(x, y, 1, 1);
}
<canvas id="canvas"/>

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

Desmos, 95 bytes

b<=25
polygon((6,0),(3,-6),(-3,6),(3,6),(-3,-6),(-6,0),(6,0))
b<=2.25
b<=1
c=hsv(0,0,1)
b=xx+yy

Try it on Desmos!

Unsure if c=hsv(0,0,1) needs to be included in the byte count, but included it just to be safe.

This does steal the polygon from the SQL answer.

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

Scratch, 262 238 232 bytes

Try it online!

For the method being used, I feel that this is quite optimal. The size, albeit small, is as large as possible without adding bytes. Alternatively, 21 blocks.

define(a)(b
set pen color to(a
set pen size to(b
pen down
when gf clicked
repeat(2
point in direction(30
erase all
repeat(3
repeat(60
set pen size to(1
turn cw(1)degrees
move(15)steps
go to x()y(
end
turn cw(60)degrees
[#fff][9
[][6

Explanation

define(a)(b             Draws circle of color (a) and diameter (b)
set pen color to(a      sets the circle color
set pen size to(b       sets the circle diameter
pen down                Draws the circle
when gf clicked         Syntax
repeat(2                Loops code twice - removes need to reset position
point in direction(30   Resets angle
erase all               Clears the stage
repeat(3                Loops code for each 'leaf'
repeat(60               Loops code for each degree in a 'leaf'
set pen size to(1       Sets pen diameter to 1
turn cw(1)degrees       Rotates 1 degree
move(15)steps           Draws ray
go to x()y(             Resets to the origin
end                     Syntax
turn cw(60)degrees      Rotates to position of next 'leaf'
[#fff][9                Draws white circle of diameter 9
[][6                    Draws black (default undefined color) circle of diameter 6
\$\endgroup\$
1
2

Your Answer

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

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