home *** CD-ROM | disk | FTP | other *** search
RISC OS BBC BASIC V Source | 1996-02-19 | 8.3 KB | 309 lines |
- > PathEffects
- Some effects with path objects. There are subroutines
- below to produce circles, arcs, sectors and elipses.
- df_buff_size% = (64<<10)
- df_buff% (df_buff_size%)
- fpo% = 0
- "DF_InitialiseFile", 1, df_buff%,,df_buff_size%, "DUB_Demo", &501, 0, 4
- ,,fpo%
- --------------------
- This example simply draws a number of elipses rotated
- by different angles about a common centre, and uses
- the even-odd winding rule to produce an interesting
- fill effect.
- wid% = 0
- colr% = &0000FF00
- fill% = &00EEEE00
- dash% = 0
- "DF_PathStart", 1, df_buff%, fpo%, colr%, fill%, wid%, dash%, 0, 0
- ,,fpo%
- p% = df_buff% + fpo%
- a% = 0
- 170
- elipse(p%,
- (a%),
- mm2du(100),
- mm2du(100),
- mm2du(85),
- mm2du(30))
- fpo% = p% - df_buff%
- "DF_PathEnd", 5, df_buff%, fpo%
- ,,fpo%
- --------------------
- This example obtains the path outline for a text
- string and transforms it so that the text appears
- written on the edge of a circle. The even-odd
- winding rule is used again: initially a background
- consisting of concentric circles with different
- grey fill colours is produced and the text appears
- transparent on top of this, giving a graded-fill
- effect to the characters.
- coordinates of centre
- x0% =
- mm2du(190)
- y0% =
- mm2du(60)
- font & size (points)
- font$ = "Trinity.Medium"
- xsize% = 50
- ysize% = 50
- 4 text$ = "Fancy text effects"
- 5(r1% = 44 :
- outer radius of 'badge'
- 6)r2% = 30 :
- radius for text baseline
- 7;r3% = 25 :
- inner radius (r1 and r3 determine zone for
-
- graded fill)
- "DF_StartGroup", 1, df_buff%, fpo%, 0
- ,,fpo%
- "DF_StartGroup", 1, df_buff%, fpo%, 0
- ,,fpo%
- r = r1%
- r3%
- =D c% = (r-r3%)/(r1%-r3%)*&FF : fill% = (c%<<24)+(c%<<16)+(c%<<8)
- "DF_PathStart", 1, df_buff%, fpo%, -1, fill%, 0,0,0,0
- ,,fpo%
- p% = df_buff% + fpo%
- circle(p%, x0%, y0%,
- mm2du(r))
- fpo% = p% - df_buff%
- "DF_PathEnd", 5, df_buff%, fpo%
- ,,fpo%
- "DF_EndGroup", 1, df_buff%, fpo%
- ,,fpo%
- E!colr% = 0 : fill% = &FFFFFF00
- "DF_PathStart", 1, df_buff%, fpo%, colr%, fill%, 0,0,0,0
- ,,fpo%
- p% = df_buff% + fpo%
- circle(p%, x0%, y0%,
- mm2du(r1%))
- fpo% = p% - df_buff%
- "DF_SelectFont", 1, df_buff%,,font$, (xsize%<<8), (ysize%<<8), 0, &FFFFFF00
- p% = df_buff% + fpo%
- "DF_PathTextOutline", 1, df_buff%, fpo%, text$, 0, 0, 0
- ,,fpo%
- badge(p%, font$, (xsize% << 4), (ysize% << 4), text$, x0%, y0%,
- mm2du(r2%),
- "DF_PathEnd", 5, df_buff%, fpo%
- ,,fpo%
- "DF_EndGroup", 1, df_buff%, fpo%
- ,,fpo%
- --------------------
- "DF_CompleteFile", 1, df_buff%, fpo%
- ,,fpo%
- "OS_File",10,"<DUBdemo$Dir>.Demos.DrawFile",&AFF,,(df_buff%+1024),(df_buff%+fpo%)
- V-*Filer_Run "<DUBdemo$Dir>.Demos.DrawFile"
- p% is an actual pointer to the start of the text
- outline subpath. The font etc. is needed to obtain
- the length of the string baseline (the string bounding
- box values are converted from millipoints to draw
- units). Coordinates within the subpath are rotated
- about the centre (x0,y0) by an angle a which is
- determined by their initial horizontal distance from
- the midpoint of the baseline; a ranges from (-atot/2)
- to (atot/2) where atot is the length of the baseline
- divided by the circumference of a circle radius r times
- . The whole thing can be tilted by angle w.
- Angles in radians, font sizes in 16ths pt, coordinates
- in draw units. The text outline must be the final sub-
- path in the path object.
- badge(p%, font$, xsize%, ysize%, text$, x0, y0, r, w)
- a, cy, i%, n%, s, t, x, xmin, xmax, y
- "Font_FindFont",,font$, xsize%, xsize%, 0, 0
- "ColourTrans_SetFontColours", n%, &FFFFFF00, 0, 14
- "Font_StringBBox",,text$
- , xmin,,xmax
- xmin = xmin / 1.5625
- xmax = xmax / 1.5625
- p! s = xmax - xmin : t = s / r
- !p%
-
- 2: n% = 1
-
- 6: n% = 3
-
- 8: n% = 1
-
- 0: n% = -1
- w
- n% = 0
- y
- p% += 4
- n% > 0
-
- i% = 1
- x = !p% : y = p%!4
- ~4 a = (
- + t) / 2 - (x - xmin) / s * t + w
- x = r *
- (a) + x0
- cy = r *
- (a) + y0
- y = cy + y
- 1
- rotate_point(x, y, x, cy, a -
- / 2)
- ( !p% = x : p%!4 = y : p% += 8
-
-
- n% < 0
- insert a circle as subpath with centre at
- x0,y0 and radius = r. x0, y0 and r in draw
- units. p% is an actual pointer (would be
- calculated as buffer address + current
- free position offset).
- circle(
- p%, x0, y0, r)
- a, b, i%, s%, z
- a = r / 1.81056 : b = r
- 6 !p% = 2 : p%!4 = (x0 - r) : p%!8 = y0 : p% += 12
- s% = 1
- i% = 0
- !p% = 6
- p%!4 = (x0 - r * s%)
- p%!8 = (y0 + a)
- p%!12 = (x0 - a * s%)
- p%!16 = (y0 + r)
- p%!20 = (x0 + z)
- p%!24 = (y0 + b)
- 6 a = -a : b = -b : r = -r : z = -z : p% += 56
-
- p% -= 84
- a, r
- z, b
- " p% += 56 : !p% = 5 : p% += 4
- insert an arc (s%=0) or sector (s%<>0) as
- subpath; centre at x0,y0, radius r, angle
- between radii = t, rotated about x0,y0 by
- w (w = 0 gives vertical midline above x0,y0).
- angles in radians, rest are draw units.
- p%, w, x0, y0, r, t, s%)
- a, b, c, d, i%, k, n%, p0%, q
- + p0% = p% : n% = 1 : q = t : k =
- q > k
- q -= k : n% += 1
- q = t / 2 / n%
- + t = 4 * r *
- ((q)) / (3 *
- ((q)) + 3)
- & k =
- (q) : b = r * k : c = t * k
- & k =
- (q) : a = r * k : d = t * k
- 8 !p% = 2 : p%!4 = x0 - a : p%!8 = y0 + b : p% += 12
- i% = 1
- !p% = 6
- p%!4 = x0 - a + c
- p%!8 = y0 + b + d
- p%!12 = x0 + a - c
- p%!16 = y0 + b + d
- p%!20 = x0 + a
- p%!24 = y0 + b
- p% += 28
- p% = p0%
- n% > 1
- w += ((n% - 1) * q)
- spc_rotate(p%, x0, y0, w)
- i% = 1
- 1
- spc_rotate(p%, x0, y0, w) : w -= (q * 2)
- ' !p% = 8 : p%!4 = x0 : p%!8 = y0
- 1 p%!12 = 8 : p%!16 = p0%!4 : p%!20 = p0%!8
- p%!24 = 5 : p% += 28
- insert elipse as subpath; centre at x0,y0
- major radius r1, minor radius r2, rotated
- about x0,y0 by w (w = 0 gives major radius
- vertical). angle in radians, rest in draw
- units.
- elipse(
- p%, w, x0, y0, r1, r2)
- a, b, dx, dy, i%, k, s%, t
- . k =
- / 4) : dx = r2 * k : dy = r1 * k
- 8 k =
- (r1 * r1 + r2 * r2) / 2.5605 : t =
- (r2 / r1)
- ! a = k *
- (t) : b = k *
- : !p% = 2 : p%!4 = x0 - dx : p%!8 = y0 + dy : p% += 12
- i% = 1
- s% = -1
- !p% = 6
- " p%!4 = x0 + s% * dx + a
- " p%!8 = y0 + dy - s% * b
- " p%!12 = x0 + dx + s% * a
- " p%!16 = y0 - s% * dy + b
- p%!20 = x0 + dx
- p%!24 = y0 - s% * dy
- p% += 28
-
- - a = -a : b = -b : dx = -dx : dy = -dy
- w <> 0
- p% -= 124
- i% = 1
- $
- spc_rotate(p%, x0, y0, w)
-
- !p% = 5 : p% += 4
- rotate a subpath component 2, 6 or 8 pointed
- to by p% about x0,y0 by angle a (in radians)
- on exit p% points to next subpath component.
- spc_rotate(
- p%, x0, y0, a)
- i%, n%, x, y
- !p%
- 2: n% = 1
- 6: n% = 3
- 8: n% = 1
- n% = 0
- p% += 4
- n% <> 0
- i% = 1
- x = !p% : y = p%!4
- (
- rotate_point(x, y, x0, y0, a)
- & !p% = x : p%!4 = y : p% += 8
-
- rotate_point(
- y, x0, y0, a)
- dx, dy, r, t, z
- (a <> 0)
- ! dx = x - x0 : dy = y - y0
- , r =
- (dx * dx + dy * dy) : z =
- r > 0
- $
- dx <> 0
- t =
- (dy / dx)
-
- (dx)
-
- -1: t +=
- 6
- 0:
- dy > 0
- t =
- / 2
- t = 3 / 2 *
- #
- 1:
- dy < 0
- t += z
-
- t += a
-
- t < 0 : t += z :
-
- t > z : t -= z :
- 5 dx = (r *
- (t) + x0) : dy = (r *
- (t) + y0)
- x = dx : y = dy
-
- convert mm to draw units.
- mm2du(x)
- w% = 640 * 72 / 25.4 * x
-