home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / s / spring12.zip / SPRING12.BAS < prev    next >
BASIC Source File  |  1992-08-26  |  7KB  |  234 lines

  1. DEFDBL A-Z
  2. CONST FALSE = 0
  3. CONST TRUE = NOT FALSE
  4. CONST PI = 3.141592653589#
  5. CONST Rad2Deg = 180 / PI
  6. DEF fnNum$ (L, x) = MID$(STR$((10 ^ L) + x), 3)
  7. DEF fnMargin (x) = x * 1.000001
  8.  
  9. Init:
  10.   PRINT "SPRING generator for PVRAY 1.0 by K. Koehler v1.2"
  11.   print "       Additions by Jeff Bowermaster"
  12.   PRINT
  13.   ' 05-03-92 KJK New program for PVRay 0.51, from STAR v1.1
  14.   ' 07-08-92 Jeff Bowermaster added:
  15.   '    sine wave motion
  16.   '    torus code,
  17.   '    sinister colors.
  18.   ' 08-26-92 KJK Updated to POVRay 1.0
  19.  
  20.   INPUT "Wire radius             :"; wr
  21.   INPUT "Spring radius           :"; sr
  22.  
  23.   a9 = -2 * (sr ^ 2 + wr ^ 2)
  24.   a25 = 2 * (sr ^ 2 - wr ^ 2)
  25.   a34 = (sr ^ 2 - wr ^ 2) ^ 2
  26.  
  27.   INPUT "Number of coils         :"; nc
  28.   INPUT "Spring height min.      :"; shmin
  29.  
  30.   IF nc * wr * 2 < shmin THEN shmin = nc * wr * 2  ' prevent smushed coils
  31.  
  32.   INPUT "Spring height max.      :"; shmax
  33.   INPUT "Number of frames        :"; nf
  34.   INPUT "Subdirectory to write to (i.e. \POV) :"; sub$
  35.   length = LEN(sub$)
  36.   IF length > 0 THEN
  37.       IF LEFT$(sub$, 1) <> "\" THEN sub$ = "\" + sub$
  38.       sub$ = sub$ + "\"
  39.   END IF
  40.  
  41.   OPEN sub$ + "runem.bat" FOR OUTPUT AS #2
  42.  
  43.   video = TRUE
  44.   IF shmax > sr + wr THEN wy = shmax * 1.1 ELSE wy = (sr + wr) * 1.1
  45.   wx = wy * 1.5' adjust aspect ratio
  46.  
  47.   sb = 0    ' spring bottom
  48.   CoilRange = shmax - shmin
  49.   boundxz = (wr + sr) * 1.01
  50.   boundy = shmax * 1.01
  51.   IF boundxz > boundy THEN size = boundxz ELSE size = boundy' !boundy recalc later!
  52.  
  53. Main:
  54.   IF video THEN
  55.      SCREEN 12
  56.      WINDOW (-wx, -wy)-(wx, wy)
  57.   END IF
  58.   dsp$ = sub$ + "sprdsp.inc"
  59.   OPEN dsp$ FOR OUTPUT AS #1
  60.   GOSUB DspFile
  61.   CLOSE #1
  62.  
  63.   obj$ = sub$ + "sprobj.inc"
  64.   OPEN obj$ FOR OUTPUT AS #1
  65.   GOSUB ObjTop
  66.   ' build object INClude guts
  67.   FOR Part = nc * 2 TO 1 STEP -2
  68.      PRINT #1, "    object { CoilHalf"
  69.      PRINT #1, "      rotate <0 0 -LoopAngle>"
  70.      PRINT #1, USING "      translate <0 CoilHalf\  \Y 0>"; fnNum$(4, Part)
  71.      PRINT #1, "    }"
  72.      PRINT #1, "    object { CoilHalf"
  73.      PRINT #1, "      rotate <180 0 0>"
  74.      PRINT #1, "      rotate <0 0 LoopAngle>"
  75.      PRINT #1, USING "      translate <0 CoilHalf\  \Y 0>"; fnNum$(4, Part - 1)
  76.      PRINT #1, "    }"
  77.   NEXT Part
  78.   GOSUB ObjBottom
  79.   CLOSE #1
  80.  
  81.   FOR FrameNum = 0 TO nf-1
  82.      a = 180 * (1 + FrameNum / nf)
  83.      shcur = shmin + CoilRange * (1 + COS(a / Rad2Deg)) / 2
  84.      GOSUB BuildDat
  85.   NEXT FrameNum
  86.   PRINT #2, "dta spr*.tga /r6 /p /ffspring /s17"
  87.   CLOSE #2
  88.   END
  89.  
  90. BuildDat:
  91.   IF video THEN
  92.      CLS
  93.      ink = 5
  94.   END IF
  95.   PRINT #2, "call p spr" + fnNum$(5, FrameNum); " "
  96.   OPEN sub$ + "spr" + fnNum$(5, FrameNum) + ".pov" FOR OUTPUT AS #1
  97.   GOSUB DatTop
  98.   PRINT #1, ""
  99.   PRINT #1, USING "declare BoundTop      = #####.#################"; fnMargin(shcur + wr)
  100.   PRINT #1, USING "declare BoundRadius   = #####.#################"; fnMargin(sr + wr)
  101.   PRINT #1, USING "declare BoundBottom   = #####.#################"; fnMargin(sb - wr)
  102.   PRINT #1, USING "declare CoilRadius    = #####.#################"; sr
  103.   PRINT #1, USING "declare CoilTop       = #####.#################"; shcur
  104.   IF video THEN LINE (-sr, sb)-(sr, sb), ink: ink = ink XOR 1
  105.  
  106.   inc1 = shcur / (nc * 2)   ' distance moved in 1/2 cycle
  107.   inc2 = shcur / (nc * 4)   ' 1/4 cycle
  108.  
  109.   ch = shcur / (nc * 4)
  110.   cw = SQR((sr ^ 2) - (ch ^ 2))
  111.   ca = ATN(ch / cw) * Rad2Deg
  112.  
  113.   PRINT #1, USING "declare LoopAngle     = ######.#################"; ca
  114.  
  115.   cyold = sb: cwold = -cw
  116.  
  117.   FOR Part = nc * 2 TO 1 STEP -1
  118.         cy = (Part * inc1) - inc2
  119.         PRINT #1, USING "declare CoilHalf\  \Y = ######.#################"; fnNum$(4, Part); cy
  120.  
  121.         IF video THEN
  122.             LINE (-cwold, cy)-(cwold, cy + ch * 2), ink
  123.             cwold = -cwold
  124.             ink = ink XOR 1
  125.         END IF
  126.  
  127.         cyold = cy
  128.   NEXT Part
  129.  
  130.   PRINT #1, USING "declare CoilBottom    = ######.#################"; sb
  131.   IF video THEN LINE (-sr, sb)-(sr, sb), ink
  132.   GOSUB DatBottom
  133.   CLOSE #1
  134. RETURN
  135.  
  136. ObjTop:
  137.   PRINT #1,
  138.   PRINT #1, "#declare SpringTex   = texture { Shiny  colour Red  }"
  139.   PRINT #1,
  140.   PRINT #1, "#declare torus01 ="
  141.   PRINT #1, "   quartic {"
  142.   PRINT #1, "      <1.0 0.0 0.0 0.0 2.0 0.0 0.0 2.0 0.0 "
  143.   PRINT #1, "      "; a9; " 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0"
  144.   PRINT #1, "       0.0 0.0 1.0 0.0 0.0 2.0 0.0 "; a25; " 0.0"
  145.   PRINT #1, "       0.0 0.0 0.0 1.0 0.0 "; a9; "0.0"; a34; ">"
  146.   PRINT #1, "    }"
  147.   PRINT #1,
  148.   PRINT #1, "#declare CoilWhole ="
  149.   PRINT #1, "  object {"
  150.   PRINT #1, "    quartic { torus01  rotate <0 0 0>  }"
  151.   PRINT #1, "    texture { SpringTex }"
  152.   PRINT #1, "  }"
  153.   PRINT #1,
  154.   PRINT #1, "#declare CoilHalf ="
  155.   PRINT #1, "  object {"
  156.   PRINT #1, "    intersection {"
  157.   PRINT #1, "      quartic {torus01  rotate <0 0 0>  }"
  158.   PRINT #1, "      plane { <0  0 -1> 0.0 }"
  159.   PRINT #1, "    }"
  160.   PRINT #1, "    texture { SpringTex }"
  161.   PRINT #1, "  }"
  162.   PRINT #1,
  163.   PRINT #1, "#declare Spring ="
  164.   PRINT #1, "  composite {"
  165.   PRINT #1, "       // wr="; wr; "  sr="; sr; "  shmin="; shmin; "  shmax="; shmax; "  nc="; nc; "  nf="; nf
  166.   PRINT #1, "    object { CoilWhole"
  167.   PRINT #1, "      translate <0 CoilTop 0>"
  168.   PRINT #1, "    }"
  169. RETURN
  170.  
  171. ObjBottom:
  172.   PRINT #1, "    object { CoilWhole"
  173.   PRINT #1, "      translate <0 CoilBottom 0>"
  174.   PRINT #1, "    }"
  175.   PRINT #1, "    bounded_by {"
  176.   PRINT #1, "      intersection {"
  177.   PRINT #1, "        plane { <0  1  0> BoundTop }"
  178.   PRINT #1, "        quadric {Cylinder_Y  scale <BoundRadius 1 BoundRadius>  }"
  179.   PRINT #1, "        plane { <0 -1  0> -BoundBottom }"
  180.   PRINT #1, "      }"
  181.   PRINT #1, "    }"
  182.   PRINT #1, "  }"
  183. RETURN
  184.  
  185.  
  186. DspFile:
  187.   PRINT #1,
  188.   PRINT #1, "camera {"
  189.   PRINT #1, USING "   location <#######.####  ######.####  ######.####>"; shmax / -2, 1.125 * shmax, -1.5 * shmax
  190.   PRINT #1, "   direction <0.0 0.0  1.0>"
  191.   PRINT #1, "   up  <0.0  1.0  0.0>"
  192.   PRINT #1, "   right <1.33333 0.0 0.0>"
  193.   PRINT #1, "   look_at ";
  194.   PRINT #1, USING "<0.0 ######.#### 0.0>"; shmax / 2
  195.   PRINT #1, "}"
  196.   PRINT #1,
  197.   PRINT #1, "// put down a disputbing yellow and blue checker floor"
  198.   PRINT #1, "object {"
  199.   PRINT #1, USING "   plane {<0.0 1.0 0.0> ######.#### }"; -fnMargin(wr)
  200.   PRINT #1, "   texture {"
  201.   PRINT #1, "      checker colour Coral colour CornflowerBlue"
  202.   PRINT #1, USING "      scale <#####.#### #####.#### #####.####>"; sr; sr; sr
  203.   PRINT #1, "      ambient 0.3"
  204.   PRINT #1, "      diffuse 0.7"
  205.   PRINT #1, "   }"
  206.   PRINT #1, "}"
  207.   PRINT #1,
  208.   PRINT #1, "composite { Spring"
  209.   PRINT #1, "    rotate <0 45 0>"
  210.   PRINT #1, "  }"
  211.   PRINT #1,
  212.   print #1,"object { light_source { ";
  213.   print #1,"<";10*size;" ";12*size;" ";-13*size;"> colour White } }"
  214.  
  215. RETURN
  216.  
  217. DatTop:
  218.   PRINT #1, "// Persistence of Vision Raytracer"
  219.   PRINT #1, "#include "; CHR$(34); "colors.inc"; CHR$(34)
  220.   PRINT #1, "#include "; CHR$(34); "shapes.inc"; CHR$(34)
  221.   PRINT #1, "#include "; CHR$(34); "textures.inc"; CHR$(34)
  222.   PRINT #1, ""
  223.   PRINT #1, "// ----------------------- Definitions start here -----------------------"
  224. RETURN
  225.  
  226. DatBottom:
  227.   PRINT #1,
  228.   PRINT #1, "#include "; CHR$(34); "sprobj.inc"; CHR$(34)
  229.   PRINT #1,
  230.   PRINT #1, "// ----------------------- Display starts here -----------------------"
  231.   PRINT #1,
  232.   PRINT #1, "#include "; CHR$(34); "sprdsp.inc"; CHR$(34)
  233. RETURN
  234.