'=========================================================================== ' Subject: BEZIER CURVE ROUTINE W/MOUSE Date: 01-14-97 (01:05) ' Author: Jim Emptage Code: QB, PDS ' Origin: 75504.2526@CompuServe.com Packet: GRAPHICS.ABC '=========================================================================== ' *************************************************************** ' * from Jim Emptage Rouge Valley Software * ' * after years of looking, I found some code for a bezier curve * ' * I adapted the code to be mouse driven ' * I added the code for the temporary mask * ' * If you are making a draw/paint program you NEED this code * ' * 75504.2526@compuserve.com * ' * please credit this code if used by leaving these comments in * ' * will need Quick Basic to compile this code * ' * ************************************************************* * DEFINT A-Z DECLARE SUB mouse (m0%, m1%, m2%, m3%) DECLARE SUB hidemouse () DECLARE SUB showmouse () DECLARE SUB getmxy (mx%, my%) DECLARE SUB setmxy (mx%, my%) DECLARE SUB mborders (x%, y%, h%, v%) DECLARE FUNCTION mbtn% () TYPE RegType ax AS INTEGER bx AS INTEGER cx AS INTEGER dx AS INTEGER bp AS INTEGER si AS INTEGER di AS INTEGER flags AS INTEGER END TYPE CLS SCREEN 13 FOR x = 0 TO 320 FOR y = 0 TO 200 PSET (x, y), 200 + (x + y) MOD 50 NEXT NEXT PALETTE 255, 60 CALL setmxy(5, 5) TYPE pts x AS INTEGER y AS INTEGER c AS INTEGER END TYPE DIM SHARED sam(105) AS pts CALL showmouse DO LOOP UNTIL mbtn% = 0 DO LOOP UNTIL mbtn% <> 0 CALL hidemouse CALL getmxy(x00, y00) PSET (x00, y00), 255 CALL showmouse DO LOOP UNTIL mbtn% = 0 DO LOOP UNTIL mbtn% <> 0 CALL hidemouse CALL getmxy(x03, y03) PSET (x03, y03), 255 DO LOOP UNTIL mbtn% = 0 DO CALL getmxy(x01, y01) X02 = x01 Y02 = y01 ' make these equal for a standard curve a = x03 - 3 * X02 + 3 * x01 - x00 e = y03 - 3 * Y02 + 3 * y01 - y00 b = 3 * X02 - 6 * x01 + 3 * x00 f = 3 * Y02 - 6 * y01 + 3 * y00 c = 3 * x01 - 3 * x00 g = 3 * y01 - 3 * y00 d = x00 h = y00 cnt = 0 FOR T! = 0 TO 1 STEP .01 xb = ((a * T! + b) * T! + c) * T! + d yb = ((e * T! + f) * T! + g) * T! + h IF POINT(xb, yb) <> 255 THEN cnt = cnt + 1 sam(cnt).x = xb sam(cnt).y = yb sam(cnt).c = POINT(xb, yb) PSET (sam(cnt).x, sam(cnt).y), 255 END IF NEXT T! FOR blk = 1 TO cnt PSET (sam(blk).x, sam(blk).y), sam(blk).c NEXT blk PSET (x00, y00), 14 LOOP UNTIL mbtn% <> 0 FOR l = 1 TO cnt LINE -(sam(l).x, sam(l).y), 14 NEXT LINE -(x03, y03), 14 END SUB getmxy (mx%, my%) STATIC mouse 3, 0, x, y ' get graphic coordinates mx% = x / 2 ' (x / 8) + 1 my% = y ' (y / 8) + 1 'convert to text coordinates END SUB SUB hidemouse STATIC CALL mouse(2, 0, 0, 0) END SUB SUB mborders (x, y, h, v) STATIC mouse 7, 0, (x - 1) * 8, (h - 1) * 8 mouse 8, 9, (y - 1) * 8, (v - 1) * 8 END SUB FUNCTION mbtn% STATIC mouse 3, buttons, 0, 0 mbtn% = buttons END FUNCTION SUB mouse (m0%, m1%, m2%, m3%) STATIC DIM inregs AS RegType, outregs AS RegType inregs.ax = m0% inregs.bx = m1% inregs.cx = m2% inregs.dx = m3% CALL INTERRUPT(51, inregs, outregs) m0% = outregs.ax m1% = outregs.bx m2% = outregs.cx m3% = outregs.dx END SUB SUB setmxy (x, y) STATIC mouse 4, 0, (x - 1) * 8, (y - 1) * 8 END SUB SUB showmouse STATIC mouse 1, 0, 0, 0 END SUB