home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / utilities / utilsd / dubmodule / !DUBdemo / Demos / PathEffect (.txt) < prev    next >
RISC OS BBC BASIC V Source  |  1996-02-19  |  9KB  |  309 lines

  1.  > PathEffects
  2.  Some effects with path objects. There are subroutines
  3.  below to produce circles, arcs, sectors and elipses.
  4. df_buff_size% = (64<<10)
  5.  df_buff% (df_buff_size%)
  6. fpo% = 0
  7.  "DF_InitialiseFile", 1, df_buff%,,df_buff_size%, "DUB_Demo", &501, 0, 4 
  8. ,,fpo%
  9.  --------------------
  10.  This example simply draws a number of elipses rotated
  11.  by different angles about a common centre, and uses
  12.  the even-odd winding rule to produce an interesting
  13.  fill effect.
  14. wid%  = 0
  15. colr% = &0000FF00
  16. fill% = &00EEEE00
  17. dash% = 0
  18.  "DF_PathStart", 1, df_buff%, fpo%, colr%, fill%, wid%, dash%, 0, 0 
  19. ,,fpo%
  20. p% = df_buff% + fpo%
  21.  a% = 0 
  22.  170 
  23. elipse(p%, 
  24. (a%), 
  25. mm2du(100), 
  26. mm2du(100), 
  27. mm2du(85), 
  28. mm2du(30))
  29. fpo% = p% - df_buff%
  30.  "DF_PathEnd", 5, df_buff%, fpo% 
  31. ,,fpo%
  32.  --------------------
  33.  This example obtains the path outline for a text
  34.  string and transforms it so that the text appears
  35.  written on the edge of a circle. The even-odd
  36.  winding rule is used again: initially a background
  37.  consisting of concentric circles with different
  38.  grey fill colours is produced and the text appears
  39.  transparent on top of this, giving a graded-fill
  40.  effect to the characters.
  41.  coordinates of centre
  42. x0% = 
  43. mm2du(190)
  44. y0% = 
  45. mm2du(60)
  46.  font & size (points)
  47. font$ = "Trinity.Medium"
  48. xsize% = 50
  49. ysize% = 50
  50. 4 text$ = "Fancy text effects"
  51. 5(r1% = 44 : 
  52.  outer radius of 'badge'
  53. 6)r2% = 30 : 
  54.  radius for text baseline
  55. 7;r3% = 25 : 
  56.  inner radius (r1 and r3 determine zone for
  57.            
  58.  graded fill)
  59.  "DF_StartGroup", 1, df_buff%, fpo%, 0 
  60. ,,fpo%
  61.  "DF_StartGroup", 1, df_buff%, fpo%, 0 
  62. ,,fpo%
  63.  r = r1% 
  64.  r3% 
  65. =D  c% = (r-r3%)/(r1%-r3%)*&FF : fill% = (c%<<24)+(c%<<16)+(c%<<8)
  66.  "DF_PathStart", 1, df_buff%, fpo%, -1, fill%, 0,0,0,0 
  67. ,,fpo%
  68.   p% = df_buff% + fpo%
  69. circle(p%, x0%, y0%, 
  70. mm2du(r))
  71.   fpo% = p% - df_buff%
  72.  "DF_PathEnd", 5, df_buff%, fpo% 
  73. ,,fpo%
  74.  "DF_EndGroup", 1, df_buff%, fpo% 
  75. ,,fpo%
  76. E!colr% = 0 : fill% = &FFFFFF00
  77.  "DF_PathStart", 1, df_buff%, fpo%, colr%, fill%, 0,0,0,0 
  78. ,,fpo%
  79. p% = df_buff% + fpo%
  80. circle(p%, x0%, y0%, 
  81. mm2du(r1%))
  82. fpo% = p% - df_buff%
  83.  "DF_SelectFont", 1, df_buff%,,font$, (xsize%<<8), (ysize%<<8), 0, &FFFFFF00
  84. p% = df_buff% + fpo%
  85.  "DF_PathTextOutline", 1, df_buff%, fpo%, text$, 0, 0, 0 
  86. ,,fpo%
  87. badge(p%, font$, (xsize% << 4), (ysize% << 4), text$, x0%, y0%, 
  88. mm2du(r2%), 
  89.  "DF_PathEnd", 5, df_buff%, fpo% 
  90. ,,fpo%
  91.  "DF_EndGroup", 1, df_buff%, fpo% 
  92. ,,fpo%
  93.  --------------------
  94.  "DF_CompleteFile", 1, df_buff%, fpo% 
  95. ,,fpo%
  96.  "OS_File",10,"<DUBdemo$Dir>.Demos.DrawFile",&AFF,,(df_buff%+1024),(df_buff%+fpo%)
  97. V-*Filer_Run "<DUBdemo$Dir>.Demos.DrawFile"
  98.  p% is an actual pointer to the start of the text
  99.  outline subpath. The font etc. is needed to obtain
  100.  the length of the string baseline (the string bounding
  101.  box values are converted from millipoints to draw
  102.  units). Coordinates within the subpath are rotated
  103.  about the centre (x0,y0) by an angle a which is
  104.  determined by their initial horizontal distance from
  105.  the midpoint of the baseline; a ranges from (-atot/2)
  106.  to (atot/2) where atot is the length of the baseline
  107.  divided by the circumference of a circle radius r times
  108. . The whole thing can be tilted by angle w.
  109.  Angles in radians, font sizes in 16ths pt, coordinates
  110.  in draw units. The text outline must be the final sub-
  111.  path in the path object.
  112. badge(p%, font$, xsize%, ysize%, text$, x0, y0, r, w)
  113.  a, cy, i%, n%, s, t, x, xmin, xmax, y
  114.  "Font_FindFont",,font$, xsize%, xsize%, 0, 0 
  115.  "ColourTrans_SetFontColours", n%, &FFFFFF00, 0, 14
  116.  "Font_StringBBox",,text$ 
  117. , xmin,,xmax
  118.   xmin = xmin / 1.5625
  119.   xmax = xmax / 1.5625
  120. p!  s = xmax - xmin : t = s / r
  121.  !p% 
  122.       
  123.  2: n% = 1
  124.       
  125.  6: n% = 3
  126.       
  127.  8: n% = 1
  128.       
  129.  0: n% = -1
  130. w        
  131.       n% = 0
  132. y        
  133.     p% += 4
  134.  n% > 0 
  135.       
  136.  i% = 1 
  137.         x = !p% : y = p%!4
  138. ~4        a = (
  139.  + t) / 2 - (x - xmin) / s * t + w
  140.         x = r * 
  141. (a) + x0
  142.         cy = r * 
  143. (a) + y0
  144.         y = cy + y
  145. 1        
  146. rotate_point(x, y, x, cy, a - 
  147.  / 2)
  148. (        !p% = x : p%!4 = y : p% += 8
  149.       
  150.         
  151.  n% < 0
  152.   insert a circle as subpath with centre at
  153.   x0,y0 and radius = r. x0, y0 and r in draw
  154.   units. p% is an actual pointer (would be
  155.   calculated as buffer address + current
  156.   free position offset).
  157. circle(
  158.  p%, x0, y0, r)
  159.  a, b, i%, s%, z
  160.   a = r / 1.81056 : b = r
  161. 6  !p% = 2 : p%!4 = (x0 - r) : p%!8 = y0 : p% += 12
  162.  s% = 1 
  163.  i% = 0 
  164.       !p% = 6
  165.       p%!4 = (x0 - r * s%)
  166.       p%!8 = (y0 + a)
  167.       p%!12 = (x0 - a * s%)
  168.       p%!16 = (y0 + r)
  169.       p%!20 = (x0 + z)
  170.       p%!24 = (y0 + b)
  171. 6      a = -a : b = -b : r = -r : z = -z : p% += 56
  172.         
  173.     p% -= 84
  174.  a, r
  175.  z, b
  176. "  p% += 56 : !p% = 5 : p% += 4
  177.   insert an arc (s%=0) or sector (s%<>0) as
  178.   subpath; centre at x0,y0, radius r, angle
  179.   between radii = t, rotated about x0,y0 by
  180.   w (w = 0 gives vertical midline above x0,y0).
  181.   angles in radians, rest are draw units.
  182.  p%, w, x0, y0, r, t, s%)
  183.  a, b, c, d, i%, k, n%, p0%, q
  184. +  p0% = p% : n% = 1 : q = t : k = 
  185.  q > k
  186.     q -= k : n% += 1
  187.   q = t / 2 / n%
  188. +  t = 4 * r * 
  189. ((q)) / (3 * 
  190. ((q)) + 3)
  191. &  k = 
  192. (q) : b = r * k : c = t * k
  193. &  k = 
  194. (q) : a = r * k : d = t * k
  195. 8  !p% = 2 : p%!4 = x0 - a : p%!8 = y0 + b : p% += 12
  196.  i% = 1 
  197.     !p% = 6
  198.     p%!4  = x0 - a + c
  199.     p%!8  = y0 + b + d
  200.     p%!12 = x0 + a - c
  201.     p%!16 = y0 + b + d
  202.     p%!20 = x0 + a
  203.     p%!24 = y0 + b
  204.     p% += 28
  205.   p% = p0%
  206.  n% > 1 
  207.  w += ((n% - 1) * q)
  208. spc_rotate(p%, x0, y0, w)
  209.  i% = 1 
  210. 1    
  211. spc_rotate(p%, x0, y0, w) : w -= (q * 2)
  212. '    !p% = 8 : p%!4 = x0 : p%!8 = y0
  213. 1    p%!12 = 8 : p%!16 = p0%!4 : p%!20 = p0%!8
  214.     p%!24 = 5 : p% += 28
  215.   insert elipse as subpath; centre at x0,y0
  216.   major radius r1, minor radius r2, rotated
  217.   about x0,y0 by w (w = 0 gives major radius
  218.   vertical). angle in radians, rest in draw
  219.   units.
  220. elipse(
  221.  p%, w, x0, y0, r1, r2)
  222.  a, b, dx, dy, i%, k, s%, t
  223. .  k = 
  224.  / 4) : dx = r2 * k : dy = r1 * k
  225. 8  k = 
  226. (r1 * r1 + r2 * r2) / 2.5605 : t = 
  227. (r2 / r1)
  228. !  a = k * 
  229. (t) : b = k * 
  230. :  !p% = 2 : p%!4 = x0 - dx : p%!8 = y0 + dy : p% += 12
  231.  i% = 1 
  232.  s% = -1 
  233.       !p% = 6
  234. "      p%!4  = x0 + s% * dx + a
  235. "      p%!8  = y0 + dy - s% * b
  236. "      p%!12 = x0 + dx + s% * a
  237. "      p%!16 = y0 - s% * dy + b
  238.       p%!20 = x0 + dx
  239.       p%!24 = y0 - s% * dy
  240.       p% += 28
  241.         
  242. -    a = -a : b = -b : dx = -dx : dy = -dy
  243.  w <> 0 
  244.     p% -= 124
  245.  i% = 1 
  246. $      
  247. spc_rotate(p%, x0, y0, w)
  248.         
  249.   !p% = 5 : p% += 4
  250.   rotate a subpath component 2, 6 or 8 pointed
  251.   to by p% about x0,y0 by angle a (in radians)
  252.   on exit p% points to next subpath component.
  253. spc_rotate(
  254.  p%, x0, y0, a)
  255.  i%, n%, x, y
  256.  !p% 
  257.  2: n% = 1
  258.  6: n% = 3
  259.  8: n% = 1
  260.     n% = 0
  261.   p% += 4
  262.  n% <> 0 
  263.  i% = 1 
  264.       x = !p% : y = p%!4
  265. (      
  266. rotate_point(x, y, x0, y0, a)
  267. &      !p% = x : p%!4 = y : p% += 8
  268.         
  269. rotate_point(
  270.  y, x0, y0, a)
  271.  dx, dy, r, t, z
  272.  (a <> 0) 
  273. !    dx = x - x0 : dy = y - y0
  274. ,    r = 
  275. (dx * dx + dy * dy) : z = 
  276.  r > 0 
  277. $      
  278.  dx <> 0 
  279.  t = 
  280. (dy / dx)
  281.       
  282. (dx) 
  283.         
  284.  -1: t += 
  285. 6        
  286.   0: 
  287.  dy > 0 
  288.  t = 
  289.  / 2 
  290.  t = 3 / 2 * 
  291. #        
  292.   1: 
  293.  dy < 0 
  294.  t += z
  295.       
  296.       t += a
  297.       
  298.  t < 0 : t += z : 
  299.       
  300.  t > z : t -= z : 
  301. 5      dx = (r * 
  302. (t) + x0) : dy = (r * 
  303. (t) + y0)
  304.       x = dx : y = dy
  305.         
  306.  convert mm to draw units.
  307. mm2du(x)
  308.   w% = 640 * 72 / 25.4 * x
  309.