20
6
Inspired by this listing from the Commodore 64 User's Guide:
10 PRINT "{CLR/HOME}"
20 POKE 53280,7 : POKE 53281,13
30 X = 1 : Y = 1
40 DX = 1 : DY = 1
50 POKE 1024 + X + 40 * Y, 81
60 FOR T = 1 TO 10 : NEXT
70 POKE 1024 + X + 40 * Y, 32
80 X = X + DX
90 IF X <= 0 OR X >= 39 THEN DX = -DX
100 Y = Y + DY
110 IF Y <= 0 OR Y >= 24 THEN DY = -DY
120 GOTO 50
Make a similar program in your chosen language/platform to bounce a ball-alike object around your terminal, screen, canvas or other visual display area.
You don't have to mimic the C64's PETSCII graphics exactly, a simple O
or o
will do, nor do you have to use the GOTO
command if it exists in your language still. As long as your ball starts at the top of your canvas and travels diagonally until it hits a canvas limit, and then bounces accordingly, as follows:
- Travelling downwards and right and hits the bottom of the screen area, bounces up and continues right;
- Travelling up and right and hits the right-most boundary, and bounces left and up;
- Travelling left and up and hits the top, bounces left and down;
- Travelling left and down and reaches the left-most boundary, bounces right and down;
- Hits any corner and reverses direction;
Then we're all good.
You don't have to move the ball 8-pixels at a time either, like is happening in the BASIC listing on the C64; you can move one character block or one pixel at a time, whichever you think is most appropriate.
To see this BASIC listing working, you can type it in with this online Commodore 64 emulator providing your browser supports Flash.
2JavaScript canvas. D'uh. – Matthew Roh – 2017-02-17T14:05:13.007
I'm not sure what you call a screen nowadays. You used to have just the screen and border area viewed through your television set or VDU... and now you've got terminals, windows, canvases, stdout etc... it's all very confusing to me. – Shaun Bebbers – 2017-02-17T14:09:26.393
It'd be better if we had a constant pixel size value. – Matthew Roh – 2017-02-17T14:11:15.760
But that depends on what you are outputting and whether or not you are using fixed-width fonts surely? – Shaun Bebbers – 2017-02-17T14:18:17.967
If you want the ball height and width to be a constant then submit your entry on an 8 bit computer like the Sinclair ZX Spectrum or something ;) – Shaun Bebbers – 2017-02-17T14:30:58.840
Have you managed to type it into and run it on that emulator? – Jonathan Allan – 2017-02-17T14:50:10.800
^ A gif with the result would be nice @ShaunBebbers – Luis Mendo – 2017-02-17T14:51:32.587
I'm using my mobile phone; I'll GIF it asap – Shaun Bebbers – 2017-02-17T15:30:39.280
Jonathan Allan: I've typed this program on a real C64 and variants on a VIC-20, PET, ZX81 and Spectrum many times. The program listing works – Shaun Bebbers – 2017-02-17T15:34:45.493
@ShaunBebbers Jonathan's comment was probably along the lines that the emulator doesn't seem to accept pasting, so you have to type it in by hand – Luis Mendo – 2017-02-17T16:31:03.423
Can we use
0
for the ball? – Conor O'Brien – 2017-02-17T16:45:27.633Yes you may use a zero - whatever you are comfortable with. As long as it bounces around the screen. – Shaun Bebbers – 2017-02-17T17:16:04.287
Yes, you have to type it in by hand to the online emulator as far as I know. If you use more recent versions of VICE you can copy and paste to that. Read the VICE dox to find out how – Shaun Bebbers – 2017-02-17T18:27:55.960
Even if you do copy/paste to VICE it probably won't recognise the
{CLR/HOME}
from the listing. Change line 10 to10 PRINT CHR$(147)
– Shaun Bebbers – 2017-02-17T18:32:21.320Actually I made it clear in the question and description "To see this BASIC listing working, you can type it in with this online Commodore 64 emulator providing your browser supports Flash." – Shaun Bebbers – 2017-02-17T19:46:21.103
@ShaunBebbers Yes, it was clear. It's just annoying not being able to paste it :-) – Luis Mendo – 2017-02-17T20:31:33.767
Ah the joys of 8 bit computing. At least the C64 had a real keyboard unlike some machines. – Shaun Bebbers – 2017-02-17T20:34:31.103
4Can we assume the screen size of 1x1 and print o forever? – Matthew Roh – 2017-02-18T05:27:14.670
Yes if you had a 1x1 screen it would print forever, but you wouldn't see it animate either. You'd have an issue with a 20 x 20 screen where it'd bounce corner to corner unless it started from somewhere other than the top left. – Shaun Bebbers – 2017-02-18T07:39:31.787
I can´t get it typed. All my C64s are inoperative and I can´t find the
CLR/HOME
key in that emulator (on a german keyboard). This thing could really use a screen keyboard. – Titus – 2017-02-21T23:53:02.267Try
print chr$(147)
instead of CLR/HOME or press the Home key if you use Windows emulation – Shaun Bebbers – 2017-02-22T07:18:33.6131
possible duplicate of ASCII Ball in Box Animation
– Titus – 2017-03-02T14:07:48.803Sorry about the possible duplication - the programming speak is so much different nowadays (scrolly texts are now animated scrolling marquees, for instance). I did a search but probably missed it or searched for the incorrect expression. – Shaun Bebbers – 2017-03-03T08:55:19.447
Btw, IMHO better online demo
– Felix Palmen – 2017-09-04T15:27:07.550I think this site is quite nice, just uses an emscripten-compiled
vice
:) – Felix Palmen – 2017-09-04T15:27:48.747