The Sunrise Tutorial Program and Challenge
Posted: Tue Jun 18, 2024 6:31 am
Just for fun, I'd like to propose folks submit their version of "the sunrise program." This is just something I came up with: a graphical demo that depicts a morning sunrise over the ocean.
The following is my initial baseline starter reference. It's a simple enough challenge, as a good tutorial/intro on programming the X16 system. For instance, one of the first challenges might be just how to get this TEXT version of the program into a .PRG on hardware (in the emulator you can just CTRL+V paste it, but on the hardware it won't be that simple).
The next evolutions of this tutorial might be:
- a BASLOAD version
- (I'm not sure how to do a double-buffered version in BASIC, maybe someone else has ideas?)
- a sprite version (with palette changes)
- add simple audio, add animated waves/birds
- add a day/night cycle? (stars and transition back down to a sunset?)
- an asm version?
- gamepad support speed up/slow down
- actual time of day overlay, real-time sun movement
Would love to see what others come up with (doesn't have to be in BASIC, but am looking for simpler solutions that the community can learn from {i.e. commented code, haha!}). It would be nice to keep the solution to a single file - which does bias it towards using BASIC and whatever the System ROM provides, but more "extreme" solutions are certainly welcomed as well.
Maybe turn this into a contest, due say by Thanksgiving time?
(reminder: don't go past 80-columns for the System ROM BASIC)
The following is my initial baseline starter reference. It's a simple enough challenge, as a good tutorial/intro on programming the X16 system. For instance, one of the first challenges might be just how to get this TEXT version of the program into a .PRG on hardware (in the emulator you can just CTRL+V paste it, but on the hardware it won't be that simple).
The next evolutions of this tutorial might be:
- a BASLOAD version
- (I'm not sure how to do a double-buffered version in BASIC, maybe someone else has ideas?)
- a sprite version (with palette changes)
- add simple audio, add animated waves/birds
- add a day/night cycle? (stars and transition back down to a sunset?)
- an asm version?
- gamepad support speed up/slow down
- actual time of day overlay, real-time sun movement
Would love to see what others come up with (doesn't have to be in BASIC, but am looking for simpler solutions that the community can learn from {i.e. commented code, haha!}). It would be nice to keep the solution to a single file - which does bias it towards using BASIC and whatever the System ROM provides, but more "extreme" solutions are certainly welcomed as well.
Maybe turn this into a contest, due say by Thanksgiving time?
(reminder: don't go past 80-columns for the System ROM BASIC)
Code: Select all
10 SCREEN $80
20 RECT 0,0,319,239,6 : REM WATER / SKY (6 IS BLUE)
30 RECT 0,180,319,239,7 : REM SAND (7 IS YELLOW)
45 A=RND(0) : REM INIT RNG "FROM ENTROPY"
50 FOR I = 1 TO 400:PSET RND(.)*320,212+RND(.)*28,5:NEXT I:REM GRASS (5=GREEN)
51 REM COLORS: DECIMAL 8 IS ORANGE, OTHER ORANGES ARE 43 44 45 (BY DEFAULT)
52 CC=45
55 W=14 : H=9 : IX=148 : Y=178 : DX=0 : REM IX == INITIAL X
56 REM W/H IS WIDTH/HEIGHT OF THE SUPPORTING DATA
57 REM IX == INITIAL X, ADJUST TO MOVE SUNRISE LEFT/RIGHT
58 REM DX TRACKS DELTA OF X, HOW MUCH WE'VE DRAWN THIS CYCLE
60 FOR I = 1 TO 30
65 IF I=4 THEN CC=8 : REM ADJUST TO NEW COLOR
66 IF I=7 THEN CC=44 : REM ADJUST TO YET-ANOTHER NEW COLOR (FEW CYCLES LATER)
70 RESTORE 1000 : REM RESTORE BACK TO START OF THE DATA SEQUENCE
80 FOR DY=1 TO H : REM HEIGHT
83 AY=Y+DY : REM ACTUAL Y
84 X=IX
85 FOR DX=1 TO W : REM WIDTH
90 READ A : REM READ THE NEXT DATA SEQUENCE VALUE INTO VARIABLE A
92 IF A=$FF THEN A=CC
95 FOR N=0 TO 3:PSET X+DX+N,AY,A:NEXT N : REM RE-SCALE THE SUN DATA
96 X=X+3 : REM ADJUST FOR THE HORIZONTAL SCALING
120 NEXT DX
125 IF AY > 178 THEN GOTO 150
130 NEXT DY
150 Y=Y-1 : IF AY < 179 THEN RECT IX-10,AY+1,IX+W*5,179,6
155 SLEEP 10 : REM DELAY A LITTLE WHILE
160 NEXT I
170 END
900 REM 1 2 3 4 5 6 7 8 9 10 11 12 13 14
1000 DATA $06,$06,$06,$06,$06,$06,$FF,$FF,$FF,$06,$06,$06,$06,$06 : REM 1
1010 DATA $06,$06,$06,$06,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$06,$06,$06 : REM 2
1020 DATA $06,$06,$06,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$06,$06 : REM 3
1030 DATA $06,$06,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$06 : REM 4
1040 DATA $06,$06,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$06 : REM 5
1050 DATA $06,$06,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$06 : REM 6
1060 DATA $06,$06,$06,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$06,$06 : REM 7
1070 DATA $06,$06,$06,$06,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$06,$06,$06 : REM 8
1080 DATA $06,$06,$06,$06,$06,$06,$FF,$FF,$FF,$06,$06,$06,$06,$06 : REM 9