Practice your coding with the BASin coding teacher.

Try to code at least one program using the five codewords you have learned in this lesson, and any other codewords you have learned from the previous lessons.

Now we are going to learn three more codewords used for trigonometry calculations. Then two codewords which are useful for changing where some things appear on the screen.

**ASN **This codeword name comes from the trigonometry words “__A__rc __S__i__N__e”. It gives the computer the sine of an angle and tells the computer to calculate the size of the angle.

**ACS **This codeword name comes from the trigonometry words “__A__rc __C__o__S__ine”. It gives the computer the cosine of an angle and tells the computer to calculate the size of the angle.

**ATN **This codeword name comes from the trigonometry words “__A__rc __T__a__N__gent”. It gives the computer the tangent of an angle and tells the computer to calculate the size of the angle.

**TAB **TAB is short for “tabulate”. The TAB codeword changes the position of a line where items appear when we use the PRINT or INPUT codewords.

**LEN **LEN gives the length of a string, in other words the number of characters in the string.

The ASN codeword is a function.

The ASN codeword tells the computer to calculate an angle from its sine.

The ASN codeword must be followed by the sine of the angle for which you want the computer to determine the angle. This sine can be any number or value between -1 and +1.

The computer will return the angle in *radians*. You can convert an angle in radians into degrees by multiplying the number of radians by 180 and then dividing the result by PI.

So an angle in degrees = ( angle in radians * 180 / PI ).

For example, the program line:

**69 LET x = ASN 0.75**

will return the angle (in radians) whose sine is 0.75, and assign it to x and the line:

**70 LET c = ASN (a - b)**

will assign to the variable c the angle (in radians) whose sine is the value of the expression (a-b).

Note here that when we tell the computer to determine the angle whose sine is the value of an expression, rather than just a single variable, we must put that expression inside brackets as we have done in line 70.

The ACS codeword is a function.

The ACS codeword tells the computer to calculate an angle from its cosine.

The ACS codeword must be followed by the cosine of the angle for which you want the computer to determine the angle. This cosine can be any number or value between -1 and +1.

The computer will return the angle in *radians*. You can convert an angle in radians into degrees by multiplying the number of radians by 180 and then dividing the result by PI.

So an angle in degrees = ( angle in radians * 180 / PI ).

For example, the program line:

**71 LET x = ACS -0.6**

will return the angle (in radians) whose cosine is -0.6, and assign it to x

and the line:

**72 LET c = ACS (a - b)**

will assign to the variable c the angle (in radians) whose cosine is the value of the expression (a-b).

Note here that when we tell the computer to determine the angle whose cosine is the value of an expression, rather than just a single variable, we must put that expression inside brackets as we have done in line 70.

The ATN codeword is a function.

The ATN codeword tells the computer to calculate an angle from its tangent.

The ATN codeword must be followed by the tangent of the angle for which you want the computer to determine the angle. This tangent can be any number or value between -1 and +1.

The computer will return the angle in *radians*. You can convert an angle in radians into degrees by multiplying the number of radians by 180 and then dividing the result by PI.

So an angle in degrees = ( angle in radians * 180 / PI ).

For example, the program line:

**73 LET x = ATN 0.5**

will return the angle (in radians) whose tangent is 0.5, and assign it to x

and the line:

**74 LET c = ATN (a - b)**

will assign to the variable c the angle (in radians) whose tangent is the value of the expression (a-b).

Note here that when we tell the computer to determine the angle whose tangent is the value of an expression, rather than just a single variable, we must put that expression inside brackets as we have done in line 74

The TAB codeword is a print/input modifier.

The TAB codeword changes the position on a line that PRINT and INPUT items appear.

Do you remember learning about that AT codeword in Lesson 2?

You learned that you can think of the Spectrum screen for displaying characters as being made up of tiny boxes arranged in rows and columns. You also learned that there are 32 columns numbered from 0 to 31.

What the TAB codeword does is tell the computer in which column you want it to start displaying something.

You can use the TAB codeword by putting a number after it. For example, the program line:

**60 PRINT TAB 15; "Elephants"**

tells the computer to display “**Elephants”** and to start it (the letter “E”) in column 15.

Because there are 32 columns numbered from 0 to 31, the number you put after a TAB codeword should be at least 0 and not greater than 31.

The LEN codeword is a function.

The LEN codeword gives the length of a string, for example the word “house” is a string of 5 characters, so its length is 5.

LEN is followed by a string value, for example

**50 LET x=LEN a$**

Here the length of the string called a$ is assigned to the variable x.

This program draws a right angled triangle and allows you to increase it’s base and height. Lines 460 to 500

display some instructions. Line 510 and 520 calculate the angles of the triangle. Lines 530 to 590 draw the triangle.

Lines 600 to 760 control the key presses to adjust the size.

```
460 LET x=90: LET y=90
465 REM x is the horizontal length of our triangle
466 REM y is the vertical length of our triangle
470 CLS
480 INK 0: PRINT AT 0,0;"Use a and s to change adjacent"
490 PRINT AT 1,0;"Use w and z to change opposite"
500 PRINT AT 2,0;"Press q to quit"
505 REM Display the instructions for which keys to use
510 LET t=(y-40)/(x-40)
515 REM Calculate the tangent of our angle by dividing the horizontal length by the vertical length
520 LET a=INT ((ATN (t)*180)/PI)
525 REM Calculate the angle by getting the ATN and converting from radians to degrees
530 INK 0: PRINT AT 20,0;"Angles are ";: INK 2: PRINT "red";: INK 0: PRINT ",lengths are ";: INK 1: PRINT "blue": INK 0: PRINT AT 21,0;"Tan of ";a;" is ";t
535 REM Display the TANgent and angle
540 INK 2: PRINT AT 18,4;a
545 REM Print the angle
550 INK 1: PRINT AT 18,4+((x-40)/8);x-40
555 REM Print the length of the adjacent side
560 LET y1=17-(y)/8: LET x1=6+(x)/8
565 REM Calculate where to display the other angle
570 INK 2: PRINT AT y1,x1;90-a
575 REM Print the other angle
580 INK 1: PRINT AT y1+5,x1;y-40
585 REM PRINT the length of the opposite side
590 INK 0: PLOT 40,32: DRAW x,0: DRAW 0,y: DRAW -x,-y
595 REM Draw the triangle
600 LET a$=INKEY$
610 IF a$="" THEN GO TO 600
615 REM wait for a key press
620 IF a$="a" THEN GO TO 680
625 REM If key is decrease adjacent goto 680
630 IF a$="s" THEN GO TO 700
635 REM If key is increase adjacent goto 700
640 IF a$="w" THEN GO TO 740
645 REM If key is increase opposite goto 740
650 IF a$="z" THEN GO TO 720
655 REM If key is decrease opposite goto 720
660 IF a$="q" THEN GO TO 770
665 REM If key is quit goto 770
670 GO TO 600
675 REM ignore any other key press and wait for another key
680 IF x<=75 THEN GO TO 600
685 REM if the the adjacent side is at the lower limit ignore the key press
690 LET x=x-1: GO TO 760
695 REM Decrease the adjacent side and continue
700 IF x>=110 THEN GO TO 600
705 REM If the adjacent side is at the upper limit ignore the key press
710 LET x=x+1: GO TO 760
715 REM Increase the adjacent side and continue
720 IF y<=75 THEN GO TO 600
725 REM If the opposite side is at the lower limit ignore the key press
730 LET y=y-1: GO TO 760
735 REM Decrease the opposite side and continue
740 IF y>=110 THEN GO TO 600
745 REM If the opposite side is at the upper limit ignore the key press
750 LET y=y+1
755 REM Increase the opposite side and continue
760 CLS : GO TO 480
765 REM Remove the old display then continue in our loop
770 STOP
775 REM Stop the program
```