CPCWiki forum
General Category => Programming => Topic started by: SkulleateR on 19:31, 02 January 20

I´m just doing some experiments here for future projects with Loco Basic.
Wrote a quick simple code to let the word "HELLO" circle around the screen. I think it´s fast enough for my needs but are there any optimisations there ?
Or maybe other solutions ?

There might be some pointers in video 11 of this thread:
http://www.cpcwiki.eu/forum/applications/smallpdgraphicdisplayfiles/25/

Hmmm, thx but not really ...
This is how far I am right now ...
https://youtu.be/LzO6O0QZmyE (https://youtu.be/LzO6O0QZmyE)

Mine is more like a Diamond, feeding ' HELLO ' using LOCATE and PRINT MID$ around in a Diamond Like Shape, the Spaces between HELLO are important in this case based on the position held, so if it were shorted to 10 Characters instead of 12 and the 12 adjusted to 10 then HELLO would be jumping 2 positions in the Diamond shape.
100 MODE 0:a$=" HELLO "
110 x=9:y=9:d1=1:d2=1
120 p=1:p2=1:c=1
130 a$=a$+MID$(a$,1,1):a$=RIGHT$(a$,LEN(a$)1)
140 WHILE c<>12
150 LOCATE x+d1,y+d2
160 PRINT MID$(a$,p2,1);
170 x=x+d1:y=y+d2
180 IF x=12 THEN d1=1 ELSE IF x=6 THEN d1=1
190 IF y=15 THEN d2=1 ELSE IF y=9 THEN d2=1
200 p2=p2+1:IF p2=12 THEN p2=1
210 WEND
220 IF c=12 THEN c=1
230 GOTO 130

This might be more to your liking, it creates a Text Coordinate based Circle with a Radius of 2, I had to then find out how to Draw each point, a Circle with a Radius of 2 Draws a Circle with 16 points, so Dividing 360/16 gave me 22.5. The message then becomes 16 characters long, which I filled with Hash Characters.
Earlier, in my Diamond example I'd realised my initial c Loop isn't incrementing c at all and Line 130 isn't really doing anything as well as Lines 220230 because it's stuck in an Infinite Loop, so removing those won't change anything.
The problem with these Circle examples is when the radius changes, the steps between each point changes and then the Length of the Message needs to change.
My first example uses a Radius of 2 which produces a Squarish circle using 16 points, so my String Message is 16 points long and is adjusted accordingly in Line 160. The steps for this becomes 360/16 = 22.5 and incremented in line 1010. The radius of 2 is set on Line 1020.
100 MODE 0
110 DEG
120 a$=CHR$(127)+"HELLO"+STRING$(10,127)
130 p=1:p2=1:a=0:c=0
140 WHILE 1
150 GOSUB 1000
160 p2=p2+1:IF p2=16 THEN p2=1
170 WEND
1000 WHILE c=a
1010 a=a+22.5
1020 x=102*COS(a):y=102*SIN(a)
1030 LOCATE x,y:PRINT MID$(a$,p2,1);
1040 WEND
1050 c=a
1060 RETURN
The second example I've altered the Radius to 5, so it looks more like a Circle, initially I had an odd looking Circle, which I fixed when I set 'a' and 'c' to 0 in line 130, the string size in 120 has been altered to 28 characters, which is the number of points used when a Circle with a Radius of 5 is created and apart from that the other change is the Length of the message in Line 160 to reflect the length of the message and the Radius itself in line 1020 becomes 5 instead of 2.
100 MODE 0
110 DEG
120 a$=CHR$(127)+"HELLO"+STRING$(22,127)
130 p=1:p2=1:a=0:c=0
140 WHILE 1
150 GOSUB 1000
160 p2=p2+1:IF p2=28 THEN p2=1
170 WEND
1000 WHILE c=a
1010 a=a+12.8571429
1020 x=105*COS(a):y=105*SIN(a)
1030 LOCATE x,y:PRINT MID$(a$,p2,1);
1040 WEND
1050 c=a
1060 RETURN
EDIT:In my last example with the Circle becomming larger, the whole drawing process slows down and it's only really necessary to Move the Hello Message along with the 1st character of the Hash, so here's an alternative which Draws the Circle initially (along with HELLO in it) and then works out where it has to move to.
100 MODE 0
110 DEG
120 a$=CHR$(127)+"HELLO"+STRING$(22,127)
130 p=1:p2=1:a=0:c=0:c2=1:f=1
140 FOR p2=1 TO 28:GOSUB 1000:NEXT p2
150 a=0:c=0:c2=1:p2=1:f=1
160 WHILE 1
170 GOSUB 1000
180 p2=p2+1:IF p2=28 THEN p2=1:f=1
190 IF p2>7 THEN f=0
200 WEND
1000 WHILE c<>c2
1010 a=a+12.8571429:c=c+1
1020 x=105*COS(a):y=105*SIN(a)
1030 IF f=1 THEN LOCATE x,y:PRINT MID$(a$,p2,1);
1040 WEND
1050 c=0
1060 RETURN
EDIT2:And if you don't like the Message moving backwards, it can be made to move Forwards like this:
100 MODE 0
110 DEG
120 a$=CHR$(127)+"HELLO"+STRING$(22,127)
130 a=0:c=0:c2=1:f=1
140 FOR p=1 TO 28:GOSUB 1000:NEXT p
150 a=0:c=0:c2=1:p=2:f=1
160 WHILE 1
170 GOSUB 1000
180 p=p+1:IF p=28 THEN p=1:f=1
190 IF p>7 THEN f=0
200 WEND
1000 WHILE c<>c2
1010 a=a12.8571429:c=c+1
1020 x=10+5*COS(a):y=10+5*SIN(a)
1030 IF f=1 THEN LOCATE x,y:PRINT MID$(a$,p,1);
1040 WEND
1050 c=0
1060 RETURN

Thx there are some nice ideas in your listings, maybe i'll do a mix of graphics and text based code, have to try around a little 8)