Up one sincos.bas. By Lee Davison. Up to top

Download zipped .

Introduction

A more sophisticated wiggly line program example. Both sine and cosine curves are printed along with a right hand border.

sincos.bas


100 REM SIN and COS wave draw for EhBASIC
110 REM (c) L.Davison 2003/4/5
120 REM leeedavison@lycos.co.uk

130 REM scale :  offset  : curve centre
140 SC = 18.5 : OF = 1.5 : CS = SC + OF
150 WIDTH 64 : REM makes POS() absolute

160 DO
170 FOR A = 0 TO TWOPI STEP PI / 10
180 S = INT(SIN(A)*SC)
190 C = INT(COS(A)*SC)
200 IF S<C THEN PRINT SPC(CS+S)"+";SPC(C-S)"x";
210 IF S>C THEN PRINT SPC(CS+C)"x";SPC(S-C)"+";
220 PRINT SPC(CS+CS-POS(0));" ."
230 FOR D = 1 TO 400 : NEXT
240 NEXT
250 LOOP

The WIDTH command in line 150 makes the POS() function return the position along the current line from the beginning of the line. In the default state the line width is effectively infinite so POS() returns the position from the last TAB() point. See the language reference for more details.

Line 220 prints the right hand column of "."s, this is mostly to make each line printed take about the same length of time so that the scroll speed seems constant no matter how quickly the program runs.

Line 230 is a simple delay, adjust this to suit your system's speed. About one whole cycle a second being displayed seems optimum.


Last page update: 17th August, 2005. e-mail me e-mail