home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / graphics / atsirds / atsirdss.lst < prev    next >
File List  |  1994-08-10  |  4KB  |  166 lines

  1. ' **** Atari SIRDS program v2.0 ****
  2. '    routine from the SIRDS FAQ
  3. ' 640x400 monochrome display version
  4. ' single depth from a degas picture
  5. '
  6. ' read *.pi3 (Degas mono screen) file into thedepth array
  7. ' write *.pic mono screen file
  8. '
  9. bkdepth%=-800             ! depth of background in pixels
  10. e%=180                    ! eye separation in pixels
  11. o%=700                    ! observer-screen distance in pixels
  12. oversam%=1                ! oversampling ratio -- can be 1, 2, 4, 6
  13. dohiddenrem!=FALSE        ! enable/disable SLOW hidden point removal
  14. xres%=640                 ! width of the picture in pixels
  15. yres%=390                 ! height of picture in pixels
  16. numcolors%=2
  17. '
  18. DIM thedepth|(xres%*yres%)
  19. depthofs%=VARPTR(thedepth|(0))
  20. DIM link%(xres%*oversam%)
  21. DIM pixels%(xres%*oversam%)
  22. DIM z%(xres%)
  23. '
  24. FILESELECT "\*.pi3","",dep$
  25. IF dep$=""
  26.   END
  27. ENDIF
  28. OPEN "i",#1,dep$
  29. SEEK #1,34
  30. BGET #1,XBIOS(2),32000
  31. CLOSE #1
  32. '
  33. init_depth
  34. CLS
  35. init_sirds
  36. do_sirds
  37. PRINT CHR$(7);
  38. '
  39. FILESELECT "\*.pic","",sir$
  40. IF sir$=""
  41.   END
  42. ENDIF
  43. BSAVE sir$,XBIOS(2),32000
  44. END
  45. '
  46. '
  47. '
  48. PROCEDURE init_depth
  49.   LOCAL x%,y%
  50.   FOR y%=0 TO yres%-1
  51.     FOR x%=0 TO xres%-1
  52.       IF POINT(x%,y%)
  53.         thedepth|(y%*xres%+x%)=128   ! 0=far, 255=near
  54.       ENDIF
  55.     NEXT x%
  56.   NEXT y%
  57. RETURN
  58. '
  59. PROCEDURE init_sirds
  60.   ' add "help lines"
  61.   LOCAL x%,y%,helpdist,th%
  62.   helpdist=ABS(bkdepth%)*e%/(2*(ABS(bkdepth%)+o%))
  63.   th%=0
  64.   FOR y%=9 DOWNTO 0
  65.     FOR x%=xres%/2-helpdist-th% TO xres%/2-helpdist+th%
  66.       PLOT x%,y%
  67.     NEXT x%
  68.     FOR x%=xres%/2+helpdist-th% TO xres%/2+helpdist+th%
  69.       PLOT x%,y%
  70.     NEXT x%
  71.     INC th%
  72.   NEXT y%
  73. RETURN
  74. '
  75. PROCEDURE do_sirds
  76.   ' render the SIRDS
  77.   LOCAL x%,y%,h%,u%,dx%,c%,xx%,highest%,separation%,left%,right%,pp%,v,visible!
  78.   FOR y%=0 TO yres%-1
  79.     FOR x%=0 TO xres%*oversam%-1
  80.       link%(x%)=x%
  81.     NEXT x%
  82.     highest%=bkdepth%
  83.     FOR x%=0 TO xres%-1
  84.       ' h%=bkdepth%+128+63*(SIN(x%/70*PI)+COS(y%/70*PI))
  85.       h%=bkdepth%+thedepth|(y%*xres%+x%)
  86.       z%(x%)=h%
  87.       IF h%>highest%
  88.         highest%=h%
  89.       ENDIF
  90.     NEXT x%
  91.     FOR x%=0 TO xres%*oversam%-1
  92.       separation%=(e%*oversam%*z%(x%/oversam%))/(z%(x%/oversam%)-o%)
  93.       left%=x%-separation%/2
  94.       right%=left%+separation%
  95.       IF (left%>=0) AND (right%<xres%*oversam%)
  96.         visible!=TRUE
  97.         IF dohiddenrem!
  98.           v=2*(o%-z%(x%/oversam%))/e%
  99.           dx%=1
  100.           REPEAT
  101.             u%=z%(x%/oversam%)+dx%*v
  102.             IF (z%((x%+dx%)/oversam%)>=u%) OR (z%((x%-dx%)/oversam%)>=u%)
  103.               visible!=FALSE
  104.             ENDIF
  105.             INC dx%
  106.           UNTIL (u%>highest%) OR (NOT visible!)
  107.         ENDIF
  108.         IF visible!
  109.           link%(right%)=left%
  110.         ENDIF
  111.       ENDIF
  112.     NEXT x%
  113.     pp%=0
  114.     FOR x%=0 TO xres%*oversam%-1
  115.       IF link%(x%)=x%
  116.         IF (pp% MOD oversam%)=0
  117.           c%=RANDOM(numcolors%)
  118.         ENDIF
  119.         pixels%(x%)=c%
  120.         INC pp%
  121.       ELSE
  122.         pixels%(x%)=pixels%(link%(x%))
  123.       ENDIF
  124.     NEXT x%
  125.     FOR x%=0 TO xres%-1
  126.       xx%=x%*oversam%
  127.       SELECT oversam%
  128.       CASE 1
  129.         c%=pixels%(xx%)
  130.       CASE 2
  131.         IF (x%>0) AND (x%<xres%-1)
  132.           c%=pixels%(xx%)*42+(pixels%(xx%-1)+pixels%(xx%+1))*24
  133.           c%=c%+(pixels%(xx%-2)+pixels%(xx%+2))*5
  134.           c%=c%/100
  135.         ELSE
  136.           c%=pixels%(xx%)
  137.         ENDIF
  138.       CASE 4
  139.         IF (x%>0) AND (x%<xres%-1)
  140.           c%=pixels%(xx%)*26+(pixels%(xx%-1)+pixels%(xx%+1))*18
  141.           c%=c%+(pixels%(xx%-2)+pixels%(xx%+2))*12
  142.           c%=c%+(pixels%(xx%-3)+pixels%(xx%+3))*7
  143.           c%=c%/100
  144.         ELSE
  145.           c%=pixels%(xx%)
  146.         ENDIF
  147.       CASE 6
  148.         IF (x%>0) AND (x%<xres%-1)
  149.           c%=pixels%(xx%)*14+(pixels%(xx%-1)+pixels%(xx%+1))*14
  150.           c%=c%+(pixels%(xx%-2)+pixels%(xx%+2))*11
  151.           c%=c%+(pixels%(xx%-3)+pixels%(xx%+3))*8
  152.           c%=c%+(pixels%(xx%-4)+pixels%(xx%+4))*5
  153.           c%=c%+(pixels%(xx%-5)+pixels%(xx%+5))*3
  154.           c%=c%+(pixels%(xx%-6)+pixels%(xx%+6))*2
  155.           c%=c%/100
  156.         ELSE
  157.           c%=pixels%(xx%)
  158.         ENDIF
  159.       ENDSELECT
  160.       IF c%=0
  161.         PLOT x%,y%+10
  162.       ENDIF
  163.     NEXT x%
  164.   NEXT y%
  165. RETURN
  166.