CPCWiki forum

General Category => Programming => Topic started by: Z|G on 12:31, 26 May 21

Title: Infamous Bouncing Ball(s) Type-in from book Working Graphics on cpc464/664
Post by: Z|G on 12:31, 26 May 21
Currently reading, Working Graphics on the Amstrad cpc464-664 by Mike James - Kay Ewbank - S.M.Gee *highly recommended*

(https://i.postimg.cc/6qtwXy0n/balls.png)
Thought this was a nice example.

Code: [Select]
`20 MODE 1:BORDER 26   30 PRINT"How many sprites ";40 INPUT n%50 CLS60 GOSUB 100070 WHILE TIME-rtime<1000080   GOSUB 200090   GOSUB 3000100 t%=t%+1110 WEND120 END1000 REM init1010 DIM s\$(n%),x(n%),y(n%),xv(n%),yv(n%)1020 DIM xa(n%),ya(n%),px(n%),py(n%)1030 FOR i%=1 TO n%1040 s\$(i%)=CHR\$(231)1050 x(i%)=INT(RND*37+2)1060 y(i%)=INT(RND*22+2)1070 px(i%)=x(i%)1080 py(i%)=y(i%)1090 xv(i%)=SGN(RND-0.5)1100 yv(i%)=SGN(RND-0.5)1110 xa(i%)=01120 ya(i%)=01130 NEXT i%1140 rtime=TIME1150 t%=01199 RETURN2000 REM animate2010 FOR i%=1 TO n%2020 px(i%)=x(i%)2030 py(i%)=y(i%)2040 x(i%)=x(i%)+xv(i%)2050 y(i%)=y(i%)+yv(i%)2060 xa(i%)=02070 ya(i%)=02080 IF x(i%)<=1 THEN x(i%)=1:xa(i%)=-2*xv(i%)2090 IF x(i%)>=40 THEN x(i%)=40:xa(i%)=-2*xv(i%) 2100 IF y(i%)<=1 THEN y(i%)=1:ya(i%)=-2*yv(i%)2110 IF y(i%)>=25 THEN y(i%)=25:ya(i%)=-2*yv(i%) 2120 xv(i%)=xv(i%)+xa(i%)2130 yv(i%)=yv(i%)+ya(i%)2140 NEXT i%2999 RETURN3000 FOR i%=1 TO n%3010  LOCATE px(i%),py(i%)3020  PRINT SPC(1);3030  LOCATE x(i%),y(i%)3040  PRINT s\$(i%);3050 NEXT i%3999 RETURN`
Note: Just in case you do not know, You can cut'n'paste this into winape. right click on screen then file->paste
Title: Re: Infamous Bouncing Ball(s) Type-in from book Working Graphics on cpc464/664
Post by: Z|G on 19:56, 31 May 21
Slowly going through the book, adding type-ins as I see fit.
Not sure why this scrolls right, to left and up one line. but still kinda nice effect. be way cooler to just scroll right to left..??

(https://i.postimg.cc/kghD7v9F/1.jpg)

Code: [Select]
`10 s%=020 d%=s% MOD 25630 r%=1340 GOSUB 100050 s%=s%+160 FOR j=1 TO 100:NEXT j70 GOTO 2080 GOTO 201000 OUT &BC00,r%1010 OUT &BD00,d%1020 RETURN`
Title: Re: Infamous Bouncing Ball(s) Type-in from book Working Graphics on cpc464/664
Post by: Animalgril987 on 21:02, 31 May 21
The OUT commands alter values in the CRTC register 13 (Display start Address)
Title: Re: Infamous Bouncing Ball(s) Type-in from book Working Graphics on cpc464/664
Post by: Z|G on 20:52, 02 June 21
(https://i.postimg.cc/4y5vxmwR/2.jpg)

Thought this was cool. Advanced peeps can skip it. (nothing new here)

Code: [Select]
`10 REM EXAMPLE: ROTATE A SHAPE20 REM ABOUT A POINT30 MODE 140 DEG50 orgX=300:orgY=200:theta=060 INPUT"Enter angle of rotation (degrees)";angle70 number=INT(360/angle)80 CLS90 FOR N%= l TO number   100 MOVE orgX,orgY 110 RESTORE120 FOR K=1 TO 4130 READ X,Y    140 GOSUB 10000150 DRAWR X,Y160 NEXT  170 theta=theta+angle 180 NEXT190 END  200 '210 REM DATA FOR RECTANGLE SHAPE220 DATA 150,0230 DATA 0,75240 DATA -150,0250 DATA 0,-75260 '9999 REM ROTATION SUBROUTINE10000 X1=X*COS(theta)-Y*SIN(theta)10010 Y1=X*SIN(theta)+Y*COS(theta)10020 X=X1:Y=Y110030 RETURN`

Colour mapping? The illusion of movement?

(https://i.postimg.cc/PJgNRK16/3.jpg)
Code: [Select]
`10 MODE 120 GOSUB 100030 GOSUB 200040 END1000 REM ? frame1010 FOR x=1 TO 40 STEP 41020 LOCATE x,11030 PEN 11040 PRINT STRING\$(2,143);1050 PEN 21060 PRINT STRING\$(2,143);1070 LOCATE x,241080 PEN 11090 PRINT STRING\$(2,143);     1100 PEN 21110 PRINT STRING\$(2,143);1120 NEXT x1130 FOR y=2 TO 231140 PEN y2 MOD 2+11150 LOCATE 1,y1160 PRINT CHR\$(143);1170 LOCATE 40,y1180 PEN (y2+1) MOD 2 +11190 PRINT CHR\$(143);1200 NEXT y1210 RETURN2000 INK 1,6,262010 INK 2,26,62020 SPEED INK 8,8 ' change these for different effects2030 RETURN`