Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!columbia!rutgers!ames!ucbcad!ucbvax!CORY.BERKELEY.EDU!dillon From: dillon@CORY.BERKELEY.EDU (Matt Dillon) Newsgroups: comp.sys.amiga Subject: BEZIER CURVES EXAMPLE (executable + source) Message-ID: <8705102037.AA25960@cory.Berkeley.EDU> Date: Sun, 10-May-87 16:37:05 EDT Article-I.D.: cory.8705102037.AA25960 Posted: Sun May 10 16:37:05 1987 Date-Received: Mon, 11-May-87 02:44:04 EDT Sender: daemon@ucbvax.BERKELEY.EDU Lines: 504 Here is a little program I wrote to fool around with Bezier curves. It allows you to fool around with a 4 point bezier curve, using the mouse to move the points, and using a prop gadget to change the granularity of the curve generation loop. A granualarity of about 40 is almost indestinguishable from a granularity of 1, and draws the curve 40 times faster (as in, **fast**) Have Fun! -Matt #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # bezier.c # bezier.uue # This archive created: Sun May 10 13:32:34 1987 export PATH; PATH=/bin:/usr/bin:$PATH echo shar: "extracting 'bezier.c'" '(5624 characters)' if test -f 'bezier.c' then echo shar: "will not over-write existing file 'bezier.c'" else cat << \!Funky!Stuff! > 'bezier.c' /* * BEZIER.C * * Matthew Dillon. * Public Domain (no Copyrights whatsoever) * * -Assumes AZTEC compilation, +L (32 bit ints), with all AMIGA symbols * precompiled. Additionally expects certain typedefs and routines * found in MY.LIB, as well as some MY.LIB #include files. * * An experienced programmer can remove the MY.LIB dependancies * (openlibs() call), and figure out what typedefs have been assumed if * he wishes to compile the program. You can also simply extract the * Bezier functions for your own use. */ #include #include #define SHIFTS 9 #define ONE (1<RPort; SetAPen(Rp, 1); setpoint(ptarray, 0, 32, 32); setpoint(ptarray, 1, 40, 40); setpoint(ptarray, 2, 50, 50); setpoint(ptarray, 3, 60, 60); setbounds(ptarray); while (notdone) { short mx, my, mm = 0; WaitPort(Win->UserPort); while (mess = GetMsg(Win->UserPort)) { switch(mess->Class) { case CLOSEWINDOW: notdone = 0; break; case NEWSIZE: setbounds(ptarray); break; case GADGETUP: case GADGETDOWN: { gg = mess->Class; gy = po->VertPot / 256; } break; case MOUSEBUTTONS: switch(mess->Code) { case SELECTDOWN: pt = getpoint(ptarray, mess->MouseX, mess->MouseY); break; case SELECTUP: pt = -1; break; } break; case MOUSEMOVE: if (gg == GADGETDOWN) { gy = po->VertPot / 256; break; } mm = 1; mx = mess->MouseX; my = mess->MouseY; break; default: break; } ReplyMsg(mess); } if (mm && pt >= 0) { movepoint(ptarray, pt, mx, my); drawcurve(ptarray); } if (gg) { char buf[32]; if (gg == GADGETUP) gg = 0; if (gy + 1 >= 0) Step = gy + 1; sprintf(buf, "gran: %4ld/%ld", Step, ONE); drawcurve(ptarray); Move(Rp, Ux + 1, Uy + 16); Text(Rp, buf, strlen(buf)); } } exiterr(1, NULL); } exiterr(n, str) char *str; { if (n) { if (str) puts(str); if (Win) CloseWindow(Win); closelibs(-1); exit(1); } } setbounds(a) register long *a; { Ux = Win->BorderLeft; Uy = Win->BorderTop; Lx = Win->Width - Win->BorderRight; Ly = Win->Height- Win->BorderBottom; drawcurve(a); } setpoint(a, pt, x, y) register short a[4][2]; { a[pt][0] = x; a[pt][1] = y; drawpoints(a, pt, pt + 1); } getpoint(a, x, y) register short a[4][2]; { register short i, bi; register long r, br; for (i = bi = 0, br = 0x7FFFFFFF; i < 4; ++i) { r = (x-a[i][0])*(x-a[i][0]) + (y-a[i][1])*(y-a[i][1]); if (r < br) { bi = i; br = r; } } return(bi); } movepoint(a, pt, x, y) register short a[4][2]; { SetAPen(Rp, 0); drawpoints(a, pt, pt + 1); SetAPen(Rp, 1); setpoint(a, pt, x, y); } #define S10(x) ((x) >> SHIFTS) #define S20(x) ((x) >> (2*SHIFTS)) /* * So I can use integer arithmatic, I am defining 512 as 1 (as far * as the mathematics go), which means that I must divide any power * multiplication by 512^(n-1). E.G. .5^2 = .25 ... to make 256^2 * equal 128, I must divide by 512^1 */ drawcurve(a) register short a[4][2]; { long m1[4]; /* t matrix */ long mr[4]; /* partial result matrix */ long corr[2]; register short t, i; char lastpt = 0; SetAPen(Rp, 0); RectFill(Rp, Ux, Uy, Lx - 1, Ly - 1); SetAPen(Rp, 1); drawpoints(a, 0, 4); Move(Rp, a[0][0], a[0][1]); for (t = 0; t <= ONE; t += Step) { /* t = 0 to 1 */ oncemore: m1[3] = ONE; m1[2] = t; m1[1] = t * t; m1[0] = m1[1] * t; mr[0] = -S20(m1[0] ) + S10(3*m1[1]) - 3*m1[2] + m1[3]; mr[1] = S20(3*m1[0]) - S10(6*m1[1]) + 3*m1[2]; mr[2] = -S20(3*m1[0]) + S10(3*m1[1]); mr[3] = S20(m1[0] ); for (i = 0; i < 2; ++i) { corr[i] = (mr[0] * a[0][i] + mr[1] * a[1][i] + mr[2] * a[2][i] + mr[3] * a[3][i]) >> SHIFTS; } Draw(Rp, corr[0], corr[1]); } if (lastpt == 0 && t - Step < ONE) { lastpt = 1; t = ONE; goto oncemore; } } drawpoints(a, is, ie) register short a[4][2]; { register short i; for (i = is; i < ie; ++i) { Move(Rp, a[i][0] - 2, a[i][1]); Draw(Rp, a[i][0] + 2, a[i][1]); Move(Rp, a[i][0], a[i][1] - 2); Draw(Rp, a[i][0], a[i][1] + 2); } } /* * GADGET ROUTINES! */ #define NG(nn) &Gadgets[nn+1] #define G_YGLOB 1 #define G_XGLOB 2 XPI Props[] = { { AUTOKNOB|FREEVERT , 0, 0, 0x1FFF, 0x1FFF } }; IM Images[] = { { 0,0,2,1,1, NULL, 1, 0, NULL }, }; GADGET Gadgets[] = { { NULL, -15, 11, 15, -19, GADGIMAGE|GADGHCOMP|GRELRIGHT|GRELHEIGHT, GADGIMMEDIATE|RIGHTBORDER|RELVERIFY,PROPGADGET, (APTR)&Images[0],NULL,NULL,0,(APTR)&Props[0], G_YGLOB, 0 }, }; GADGET *Gc; long GUx, GUy; init_gadgets(nw, ppo) NW *nw; XPI **ppo; { nw->FirstGadget = &Gadgets[0]; *ppo = &Props[0]; } !Funky!Stuff! fi # end of overwriting check echo shar: "extracting 'bezier.uue'" '(11291 characters)' if test -f 'bezier.uue' then echo shar: "will not over-write existing file 'bezier.uue'" else cat << \!Funky!Stuff! > 'bezier.uue' begin 644 bezier M```#\P`````````#``````````(```;<````_P````$```/I```&W$[Z"89" M97II97(``$Y5_[XO"CM\``'__CM\_____$)M_^A(;?_D2&R``DZZ!]A03TAZ M`KA(>``#3KH(OEA/2H!F!'`!8`)P`$C`+P!.N@+64$](>@*J2&R``DZZ&PA8 M3RE`@ZIF!'`!8`)P`$C`+P!.N@*R4$\@;(.J*6@`,H.N2'@``2\L@ZY.NAI^ M4$](>``@2'@`($*G2&W_[$ZZ`S1/[P`02'@`*$AX`"A(>``!2&W_[$ZZ`QQ/ M[P`02'@`,DAX`#)(>``"2&W_[$ZZ`P1/[P`02'@`/$AX`#Q(>``#2&W_[$ZZ M`NQ/[P`02&W_[$ZZ`G183TIM__YG``'>0FW_WB!L@ZHO*`!63KH9MEA/(&R# MJB\H`%9.NAEF6$\D0$J`9P``Z"`J`!1@``"F0FW__F```,Q(;?_L3KH"*EA/ M8```OCMJ`!;_Z"!M_^1P`#`H``3@B#M`_^I@``"D<``P*@`88"HP*@`B2,`O M`#(J`"!(P2\!2&W_[$ZZ`IA/[P`,.T#__&`8.WS____\8!"0O````&AGSI"\ M````@&?H8%X,;0`@_^AF$B!M_^1P`#`H``3@B#M`_^I@1#M\``'_WCMJ`"#_ MXCMJ`"+_X&`P8"Y5@&<`_V!=@&>"48!GPI"\````$&<`_UR0O````"!G`/]2 MD+P```'`9P#_,F#0+PI.NAB@6$]@`/\&2FW_WF``! M3KH4Y%A/3EU.=4Y5```O"B1M``@@;(.J$"@`-DB`.4"#HB!L@ZH0*``W2(`Y M0(.D(&R#JC`H``A(P")L@ZH2*0`X2(%(P9"!.4"#IB!L@ZHP*``*2,`B;(.J M$BD`.4B!2,&0@3E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H M$$*M`!1*K0`,;!)$K0`,2H1L"D2$*WP````!`!0B+0`,(`1.N@/20>R!$E.* M%+`(`"(M``P@!$ZZ`\HH`&;>2JT`%&<&4XH4O``M(`I,WP003EU.=4Y5_Q1( MYP@P)&T`""9M``Q"K?_X*VT`$/_\($M2BQ`02(!(P"@`9P`#,+B\````)68` M`PI"+?\B*WP````!__0K?````"#_\"M\```G$/_L($M2BQ`02(!(P"@`L+P` M```M9A!"K?_T($M2BQ`02(!(P"@`N+P````P9A0K?````##_\"!+4HL0$$B` M2,`H`+B\````*F8:(&W__%BM__PK4/_H($M2BQ`02(!(P"@`8#1"K?_H8")R M"B`M_^A.N@G`T(20O````#`K0/_H($M2BQ`02(!(P"@`0>R!)0@P``)(`&;2 MN+P````N9F(@2U*+$!!(@$C`*`"PO````"IF&B!M__Q8K?_\*U#_["!+4HL0 M$$B`2,`H`&`T0JW_[&`B<@H@+?_L3KH)5M"$D+P````P*T#_["!+4HL0$$B` M2,`H`$'L@24(,``"2`!FTBM\````!/_DN+P```!L9A8@2U*+$!!(@$C`*``K M?`````3_Y&`4N+P```!H9@P@2U*+$!!(@$C`*``@!&!^*WP````(_^!@'"M\ M````"O_@8!(K?````!#_X&`(*WS____V_^`O+?_D2&W_(B\M_^`O+?_\3KK] MM$_O`!`K0/_<("W_Y-&M__Q@6B!M__Q8K?_\*U#_W"\M_]Q.N@(<6$\K0/_D M8$H@;?_\6*W__"@00>W_(2M(_]P0A&`HD+P```!C9^)3@&>4D+P````+9P#_ M;EF`9[15@&<`_VY7@&<`_W)@S$'M_R*1[?_<*TC_Y"`M_^2PK?_L;P8K;?_L M_^1*K?_T9W`@;?_<#!``+6<*(FW_W`P1`"MF-`RM````,/_P9BI3K?_H(&W_ MW%*M_]P0$$B`2,`O`$Z26$^PO/____]F"G#_3-\,$$Y=3G5@&"\M__!.DEA/ ML+S_____9@1P_V#B4JW_^"`M_^A3K?_HL*W_Y&[:0JW_X&`D(&W_W%*M_]P0 M$$B`2,`O`$Z26$^PO/____]F!'#_8*I2K?_@(&W_W$H09PH@+?_@L*W_[&W* M("W_X-&M__A*K?_T9BI@&DAX`"!.DEA/L+S_____9@9P_V``_W!2K?_X("W_ MZ%.M_^BPK?_D;MA@&"\$3I)83["\_____V8&/__+RT`#$ZZ M`/Y03R@?3EU.=6#X3E4``"\*)&T`#"!2L>H`!&4:("T`","\````_R\`+PI. MN@#04$\D7TY=3G4@4E*2$"T`"Q"`2(!(P,"\````_V#D3E4``"\*0>R!IB1( M($K5_````!8O"&$06$]![(->M``!2&W__Q`J``U(@$C`+P!.N@(R3^\`#+"\`````6:8("T`#&``_V`DJ@`( M,"H`$$C`T*H`""5```0(Z@`"``P@4E*2$"T`#Q"`2(!(P,"\````_V``_S!. M50``+PI![(&F)$A**@`,9QC5_````!9![(->M`0`3KH`PEA/*T#__&88-7P``0`0(`K0 MO`````XE0``()%].74YU-7P$```0".H``0`,)6W__``($"H`#4B`2,`O`$ZZ M`-Y83TJ`9P8`*@"```Q@S$Y5``!(YP`P)&R#9F`4)E(@*@`$4(`O`"\*3KH$ M1E!/)$L@"F;H0JR#9DS?#`!.74YU3E4``"\*0?K_QBE(@YI"IR`M``A0@"\` M3KH#]%!/)$!*@&8(<``D7TY=3G4DK(-F)6T`"``$*4J#9B`*4(!@YDY5```O M+0`(8;983TY=3G5.50``2.<`,)?+)&R#9F`.(&T`"%&(LR#=DJM``AM$C`L@UY(P"(M``BR@&P$2I)F$"E\ M`````H.> M9PHO+(/>3KH!;%A/+'@`!`@N``0!*6<4+PU+^@`*3J[_XBI?8`9"I_-?3G-* MK(."9BI*K(.29R(O+(..+RR#DDZZ`6!03R`L@XI2@.6`+P`O+(.&3KH!3%!/ M8`Y.N@$\+RR#@DZZ`7183R`M__PN;(-J3G4H'TY=3G5.50``2.<.("@M``AR M!B`$3KH`1"1`U>R#=DJ$;0XP+(->2,"X@&P$2I)F$BE\`````H.>