7
\$\begingroup\$

A station model is a diagram for recording the weather at a certain place and time.

Challenge

You must write the shortest code possible to graphically output a simplified (explained later) station model.

Ticks

A tick is a line on the wind barb. A 50 knot tick is a triangle. A 10 knot tick is a line. A 5 knot tick is half the length of a 10 knot tick. The windspeed is indicated by summing the ticks, using the largest value symbols whenever possible. The ticks start at the end of the line and are arranged in descending order of size toward the circle. An exception is 5 knots, where the tick is placed a short distance away from the end (to avoid ambiguity with 10 knots.)

Here is some pseudocode to calculate the ticks required

set f=int(s/5)
set t=int(f/2)
f=f-(t*2)
set ft = int(t/5)
t=t-(ft*5)

Where f is the number of 5 knot ticks, t is the number of 10 knot ticks and ft is the number od 50 knot ticks. (This rounds down to the nearest 5, but your code should round up or down, whichever is nearer.) Note that there is only ever one 5 knot tick.

Other

You may only display two things on your station model: wind speed and direction. These must be supplied by the user: hardcoding is not permitted. The wind speed must be a positive integer in knots while the wind direction must be in letters (e.g. NNE, W, ESE). 16 points of the compass will be considered (up to three letters.) See http://en.wikipedia.org/wiki/Points_of_the_compass

The 50 knots tick must be as in the picture above.

Set cloud cover to clear (the circle must be empty.) The highest wind speed allowed is 201 knots (round it to 200).

Since the wind ticks only increase in imcrements of 5, round all wind speeds to the nearest 5.

As always, since this is code golf, the shortest code wins.

Examples

All of the following have a cloud cover of clear.

20 knots, SW (225°)

15 knots, N (0°)

Test cases

50 knots, NNE
0 knots
12 knots S
112 knots WNW

\$\endgroup\$
  • \$\begingroup\$ What's the maximum wind speed we need to support? \$\endgroup\$ – Martin Ender Sep 4 '14 at 14:18
  • \$\begingroup\$ @Martin Well the fastest ever wind was 201 knots so go with that \$\endgroup\$ – Beta Decay Sep 4 '14 at 14:23
  • 6
    \$\begingroup\$ The sample diagram you provide contains about 18 items of data. You've specified input for 2 of them. That leaves a massive hole in the spec. And then the level of detail in the output spec ("either graphically or using ascii") also leaves a massive hole, pretty much the entire thing. There's no point in a code golf question where people aren't trying to golf the same mapping from input to output: it becomes about arguing over formatting rather than about writing clever code. \$\endgroup\$ – Peter Taylor Sep 4 '14 at 14:24
  • 1
    \$\begingroup\$ @PeterTaylor I think "You must use two variables: wind speed and direction." is intended to mean that only this subset of the larger diagram is to be represented. \$\endgroup\$ – Martin Ender Sep 4 '14 at 14:25
  • 1
    \$\begingroup\$ @BetaDecay I've clarified that the answer should round to the nearest 5, not round down. Also, compass points SEE and NWW do not exist (or at least are not standard.) A 3-letter compass point is made by combining a 1-letter and a 2-letter (in that order.) I don't think we've had a question about parsing compass points before, but we've had the inverse, twice: codegolf.stackexchange.com/q/21927/15599 codegolf.stackexchange.com/q/17438/15599 \$\endgroup\$ – Level River St Sep 4 '14 at 21:21
2
\$\begingroup\$

BBC BASIC, 273 ASCII characters (not golfed yet)

Emulator at http://www.bbcbasic.co.uk/bbcwin/bbcwin.html

Parsing the direction is a dirty hack. I simply take a walk through a cartesian grid for each letter input. They aren´t echoed to the screen, and the input is terminated when a space is received.

As this is codegolf, I don't bother to normalise the direction vector. Therefore the size of the symbol drawn is dependent on the number of characters input. The proportions are the same for all inputs, however. Also, for the 3-letter inputs the angle is 4 degrees closer to the diagonal than it should be. For example, NNE is atan(0.5)=26.57 degrees instead of the correct 22.5 degrees, but it is barely noticeable. Both these points could be corrected for about 20-30 characters.

After the direction, the speed is input (this is echoed to the screen and terminated with a newline.)

  x=0
  y=0
  REPEAT
    d=GET                             :REM get character from keyboard
    x+=(d=87)-(d=69)                  :REM d=87 evaluates to -1 if "W", d=69 is -1 if "E"
    y+=(d=83)-(d=78)                  :REM d=83 evaluates to -1 if "S", d=69 is -1 if "N"
  UNTILd=32
  x*=20                               :REM boost the sizes of x and y
  y*=20                               :REM normalization code would go here
  INPUTs
  s=INT(s/5+.5)                       :REM divide s by 5 and round to nearest int. 50-tick=10, 10-tick=2, 5-tick=1 
  MOVE600,500                         :REM move to centre of circle
  PLOT145,x,y                         :REM draw circle centred at 600,500 with 600+x,500+y on its edge. cursor remains at the latter position.
  IFs=0END                            :REM exit if wind=0
  DRAWBY 9*x,9*y                      :REM draw the shaft of the arrow, 9 units long, from current position
  IFs>1 MOVEBY x,y                    :REM if rounded windspeed >5 move one more space out.
  WHILEs>1                            :REM while there are still 50-ticks and 10-ticks to draw
    MOVEBY 2*y,-2*x                   :REM move 2 units clockwise of the shaft
    PLOT1-(s>9)*80,-2*y-x,2*x-y       :REM draw a diagonal line back to the shaft. If s is 10 or over, plot mode 81 will take the last 2 positions of the graphics cursor and draw a triangle. 
    s-=2-(s>9)*8                      :REM Decrement s by 2 or 10, according to the last barb drawn. 
  ENDWHILE
  IFs MOVEBY -x,-y:DRAWBY x/2+y,y/2-x :REM If s=1 draw the 5-tick. Unlike the other ticks, it is drawn from its root outwards.

Output

All the test cases from the quesion are shown, plus two more to illustrate 2-letter directions:

50 knots, NNE
0 knots
12 knots S
112 knots WNW
195 knots SE
5 knots SW

In order to show them all together, I didn't clear the screen between runs. The different sizes (but constant proportions) of the arrows can be seen.

enter image description here

\$\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.