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
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 - You'd need to look at other options (lores graphics) - or even character mode. Or using assembly language.
Wavy Navy does it.
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?
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.
Here is a Sine Wave Demo written in Applesoft BASIC.