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

6 posts / 0 new
Last post
Last seen: 1 week 2 days ago
Joined: Jul 14 2018 - 12:54
Posts: 119
How do I do a horizontally scrolling sine wave in Applesoft BASIC?

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:



20 FOR X=0 TO 278

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



60 GOTO 5

Last seen: 12 months 8 hours ago
Joined: Dec 1 2021 - 04:41
Posts: 4
It's not simple...

Right to left is simple - just change line 20 to:

20 FOR X = 278 TO 0 STEP -1

Scrolling - especially horizontally is going to be painful (and especially in BASIC). Probably quicker to use tricks like pre-calculating all the points, storing in an array - and then plotting / unplotting them to the screen.

Even doing that is going to be really, really slow in BASIC Sad - You'd need to look at other options (lores graphics) - or even character mode. Or using assembly language.

Last seen: 1 month 2 weeks ago
Joined: May 27 2009 - 01:37
Posts: 1000
Wavy Navy does it.

Wavy Navy does it.

Last seen: 1 week 2 days ago
Joined: Jul 14 2018 - 12:54
Posts: 119
I'm pretty sure that Wavy

I'm pretty sure that Wavy Navy is doing that in machine code.  But thank's for drawing my attention to that!  It looks like a awsome game! And I'm always looking for new stuff!


Maybe 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?

Last seen: 9 hours 14 min ago
Joined: Nov 30 2021 - 11:50
Posts: 1
Horizontal scrolling at

Horizontal scrolling at anything like the speed you'd want would have to be done in assembly language.

The strategy would be to write an assembly language function that would copy from either the 1st hi-res graphics buffer to the 2nd, or vice versa. The function would copy each of the source buffer's 192 lines over to the destination buffer, rotating "left" by one byte (7 pixels), so the 0th byte is copied to the 39th byte, 1st to the 0th, 2nd to the 1st, ... 39th to the 38th. Repeat for all 192 lines. Then access the flag that toggles between graphics buffers. Repeat in the other direction and toggle back.

That gets you a 7-pixel scroll which is about as smooth as you'll realistically get on an Apple II without quite a bit of wizardry to avoid color palette confusion.

This is significantly harder than writing in Applesoft Basic, but honestly it would probably be a great first project to learn 6502 assembly. Don't expect it to be easy though! Maybe start by writing a program to just scroll the first of the 192 lines and go from there.

mmphosis's picture
Last seen: 4 days 7 hours ago
Joined: Aug 18 2005 - 16:26
Posts: 388
Here is a Sine Wave Demo

Here is a Sine Wave Demo written in Applesoft BASIC.



Log in or register to post comments