IGNORED

# How do I do a horizontally scrolling sine wave in Applesoft BASIC?

## Recommended Posts

I tweaked this program from something I saw on the 8-bit Guy.  Managed to get the wave to fill most of the screen, repeat, and end where it begins on the screen.  However, I was wondering if I could get it to scroll horizontally across the screen? or draw from right to left? I don't know, I'm just playing with BASIC and wanted some pointers.

Program listing:

5 HGR

10 HCOLOR=3

20 FOR X=0 TO 278

30 LET Y=INT(-65*SIN(X*3.14/28))+70

40 HPLOT X,Y

50 NEXT X

60 GOTO 5

##### Share on other sites

Use vertical plotting to erase each vertical column before plotting the next pixel.  And instead of the screen scrolling left, which is cpu intensive, have the plotted sin wave start over at the left edge of the screen again but it should have a different X coordinate.  The code basically looks like this then.

- create first loop

- create second loop

- calculate Y

- set HCOLOR to black

- draw a vertical line using HPLOT X,0 TO X,191

- set HCOLOR to white

- plot pixel

- END

change line #30 to this 30 LET Y=INT(-65*SIN((X+Z*M)*3.14/28))+70 where Z is the first loop variable and M is a multiplier (try 2,3,4 etc)

##### Share on other sites

Thanks for this!  Although I'm still working out how to create separate loops (I'm not very good with programing, and I don't have a manual).  But for the moment, I think I can set my bar a little lower to achieve a similar effect.  Since "HPLOT X,0 TO X,191" draws a vertical line, is it possible to make that line thicker and black, and get it to move across my screen through the sine wave?  Essentially, give the illusion that the computer is continuously redrawing the wave?  Or am I getting into sprite territory that the Apple II doesn't have?

Even if it only fills the screen, I could set another wave to dray through it.  Whipe the screen white, then draw a black wave, whipe black, white wave, repeat?

Edited by DistantStar001
##### Share on other sites

Better yet.  You could make the SIN wave look like a heart monitor and just have a double wide plotted pixel follow the SIN wave pattern.

Line #40 basically looks like this then

40 HCOLOR=3: HPLOT X,Y: HPLOT X+1,Y : HCOLOR=0: HPLOT OX,OY : HPLOT OX+1,OY

then make Line #45 into this:

45 OX=X: OY=Y

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.