Advertisement
SCaparrosJ

Renderizado de esferas en Amstrad CPC

Jul 23rd, 2022
4,777
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. REM Renderizado de esferas en Amstrad CPC
  2.  
  3. 5 MODE 0:INK 0,0:xm=4:ym=2
  4. 10 DATA 1,2,5,11,14,20,23,26,3,6,15,25
  5. 12 FOR n%=1 TO 12:READ c%:INK n%,c%:NEXT n%
  6. 15 DATA 0,9,10,11,12
  7. 17 DIM cl%(5):FOR n%=1 TO 5:READ cl%(n%):NEXT n%
  8. 20 s%=4:DIM c(s%,3):DIM r(s%):DIM q(s%)
  9. 30 FOR k=1 TO s%:READ c(k,1),c(k,2),c(k,3),r:r(k)=r:q(k)=r*r:NEXT k
  10. 40 DATA -0.8,-1,3.2,0.7
  11. 45 DATA 0,-0.45,2,0.3
  12. 50 DATA 1.2,-0.7,2.5,0.5
  13. 55 DATA 0.4,-1,4,0.4
  14. 60 FOR i=0 TO 400 STEP ym:FOR j=0 TO 640 STEP xm
  15. 70 x=0.3:y=-0.5:z=0:ba%=3:dx=j-320:dy=200-i:dz=450:dd=dx*dx+dy*dy+dz*dz
  16. 80 GOSUB 100:NEXT j:NEXT i
  17. 90 GOTO 90
  18. 100 n=(y>=0 OR dy<=0):IF NOT n THEN s=-y/dy
  19. 110 FOR k=1 TO s%
  20. 120 px=c(k,1)-x:py=c(k,2)-y:pz=c(k,3)-z
  21. 130 pp=px*px+py*py+pz*pz
  22. 140 sc=px*dx+py*dy+pz*dz
  23. 150 IF sc<=0 THEN GOTO 200
  24. 160 bb=sc*sc/dd
  25. 170 aa=q(k)-pp+bb
  26. 180 IF aa<=0 THEN GOTO 200
  27. 190 sc=(SQR(bb)-SQR(aa))/SQR(dd):IF sc<s OR n<0 THEN n=k:s=sc
  28. 200 NEXT k
  29. 210 IF n<0 THEN r=1+INT((dy*dy/dd)*15):GOSUB 1000:PLOT j,i,r:n=0:RETURN
  30. 220 dx=dx*s:dy=dy*s:dz=dz*s:dd=dd*s*s
  31. 230 x=x+dx:y=y+dy:z=z+dz
  32. 240 IF n=0 THEN GOTO 300
  33. 250 nx=x-c(n,1):ny=y-c(n,2):nz=z-c(n,3)
  34. 260 nn=nx*nx+ny*ny+nz*nz
  35. 270 l=2*(dx*nx+dy*ny+dz*nz)/nn
  36. 280 dx=dx-nx*l:dy=dy-ny*l:dz=dz-nz*l
  37. 290 GOTO 100
  38. 300 FOR k=1 TO s%
  39. 310 u=c(k,1)-x:v=c(k,3)-z: IF u*u+v*v<=q(k) THEN ba%=1
  40. 320 NEXT k
  41. 330 IF (x-INT(x)>0.5)=(z-INT(z)>0.5) THEN r=cl%(ba%) ELSE r=cl%(ba%+1)
  42. 335 PLOT j,i,r
  43. 340 RETURN
  44. 1000 l=((j/xm)+(i/ym)) MOD 2
  45. 1010 IF r=2 AND l=0 THEN r=1:RETURN
  46. 1020 IF r=2 AND l=1 THEN r=2:RETURN
  47. 1030 IF r=3 THEN r=2:RETURN
  48. 1040 IF r=4 AND l=0 THEN r=2:RETURN
  49. 1050 IF r=4 AND l=1 THEN r=3:RETURN
  50. 1060 IF r=5 THEN r=3:RETURN
  51. 1070 IF r=6 AND l=0 THEN r=3:RETURN
  52. 1080 IF r=6 AND l=1 THEN r=4:RETURN
  53. 1090 IF r=7 THEN r=4:RETURN
  54. 1100 IF r=8 AND l=0 THEN r=4:RETURN
  55. 1110 IF r=8 AND l=1 THEN r=5:RETURN
  56. 1120 IF r=9 THEN r=5:RETURN
  57. 1130 IF r=10 AND l=0 THEN r=5:RETURN
  58. 1140 IF r=10 AND l=1 THEN r=6:RETURN
  59. 1150 IF r=11 THEN r=6:RETURN
  60. 1160 IF r=12 AND l=0 THEN r=6:RETURN
  61. 1170 IF r=12 AND l=1 THEN r=7:RETURN
  62. 1180 IF r=13 THEN r=7:RETURN
  63. 1190 IF r=14 AND l=0 THEN r=7:RETURN
  64. 1200 IF r=14 AND l=1 THEN r=8:RETURN
  65. 1210 IF r=15 THEN r=8:RETURN
  66. 1220 RETURN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement