home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1995 September / Image.iso / pcplus / handson / wilfw107 / polygons.bas < prev   
Encoding:
BASIC Source File  |  1995-06-22  |  893 b   |  54 lines

  1. SCREEN 9
  2.  
  3. DIM Points%(13, 2)
  4.  
  5. FOR NumPoints% = 3 TO 13 STEP 2
  6.  
  7. ' Calculate length of side and angle for polygon
  8.  
  9.  CLS
  10.  Angle% = 180 - INT((NumPoints% - 2) * 180 / NumPoints%)
  11.  Side% = 1450 / NumPoints%
  12.  
  13. ' Draw the polygon (invisibly)
  14.  
  15.  DRAW "BM" + STR$(320 - INT(Side% / 2)) + ",340"
  16.  
  17.  FOR iter% = 1 TO NumPoints%
  18.  
  19.   Points%(iter%, 1) = POINT(0)
  20.   Points%(iter%, 2) = POINT(1)
  21.  
  22.   DRAW "TA" + STR$(Angle% * (iter% - 1)) + "BR" + STR$(Side%)
  23.  
  24.  NEXT
  25.  
  26. ' Take a point at random
  27.  
  28.  x% = INT(RND * 640)
  29.  y% = INT(RND * 350)
  30.  
  31. ' Fill in polygon with repeated algorithm
  32.  
  33.  FOR iter% = 1 TO 30000
  34.   Dir% = INT(RND * NumPoints%) + 1
  35.   xx% = Points%(Dir%, 1)
  36.   yy% = Points%(Dir%, 2)
  37.   x% = (xx% + x%) / 2
  38.   y% = (yy% + y%) / 2
  39.   PSET (x%, y%), 14
  40.  NEXT
  41.  
  42.  
  43. ' Wait and repeat with another polygon
  44.  
  45.  
  46.  x$ = ""
  47.  WHILE LEN(x$) = 0
  48.   x$ = INKEY$
  49.  WEND
  50.  
  51. NEXT
  52.  
  53.  
  54.