'=========================================================================== ' Subject: DRAW A CADIOID (DAISY) Date: 08-30-96 (10:20) ' Author: Don Schullian/Jim Oliver Code: QB, QBasic, PDS ' Origin: d83@hol.gr Packet: EGAVGA.ABC '=========================================================================== 'Here's one for you that Jim and I got together on. It's kinda fun. 'Ok, this is it! No more beta versions of this thing! I'm DONE! 'Unless, of course, someone comes up with some improvements. :) 'The code below runs under Qbasic but is slower than growing 'rocks so you may want to just draw one daisy and leave it at that. 'Those of you with PowerBASIC will want to add BYVAL and 'LOCAL PUBLIC to the sub's declare line then tweek it all a bit 'to get it back into fighting posture; if you decide to keep it. 'Anyhow, thanks for the great idea. I'm putting this one in the 'box with my polygon routines for later. It may just come in handy. 'This, the final version will correctly draw Cadioid Curves (daisies) ' ** of any number from 1 up to ??? ' ** uses the "ASPECT" variable like CIRCLE ' ** will draw the curves at any degree of rotation 'One of the demo's (RollingWheel) draws a wheel as it rolls up off 'the screen. CanioidCurves is used to draw in the spokes and ASPECT 'is imployed to provide perspective. 'The other demo routine, (Daisies) draws 20 daisies on the screen then 'rotates them clockwize until the next lobe/petal/loop comes up to the '12o'clock position. 'Both these are pretty crude and intended to show the use of the main 'routine. In short, Speilberg and Lucas can rest easy for a while yet. 'It may be worthy to mention here that this routine uses DEGREES of 'the circle and not RADIANS. I find it easier to work/think in 'DEGREES so that's the way I made it. 'You will also want to play with the Aspect! variable. Try numbers 'between .5 and 1.6 for some neat effects with screen 12 or .75 to 'get round circles with SCREEN 9. 'Anyhow, this one goes into the PUBLIC DOMAIN so have at it! '================= ' START TEST CODE '================= SCREEN 12 RollingWheel Daisies '============================================================ '=== THIS CODE IS RELEASED INTO THE PUBLIC DOMAIN '=== USE AT YOUR OWN RISK and all that legal rott '============================================================ ' CONCEPT: Jim Oliver jim.oliver@welcom.net.nz 'CODED BY: Don Schullian, DASoft Software, d83@hol.gr 'CODED IN: The code is pretty well generic but may require ' some small changes to run. ' PURPOSE: Draw a cadioid (daisy) to the graphics screen (12) ' PARAMS: Col% center column (pixel) ' Row% center row (pixel) ' Radius% radius in pixels ' Asp! aspect ratio 1 = normal for VGA ' StartD! starting degree for "top" lobe ' 0 is 12o'clock, 90 is 3o'clock, etc ' Lobes% number of lobes/loops/petals ' Colour% color to draw in '============================================================ SUB CadioidCurves (Col%, Row%, Radius%, Asp!, StartD!, Lobes%, Colour%) IF (Lobes% MOD 2) = 1 THEN ' an odd number of lobes Petals% = Lobes% ' T% = 1 ' stop after 1st pass ELSE ' even number of lobes IF (Lobes% MOD 4) = 0 THEN T% = 2 ' only 1 pass required Petals% = (Lobes% / 2) ' decrease # lobes END IF ' Pi2! = (8 * ATN(1)) ' pi * 2 Srad! = StartD! - (90 \ Petals%) - 90 ' adjust to find top XRad! = Radius% ' horizontal radius YRad! = Radius% ' vertical radius IF Asp! > 1 THEN ' aspect = 1 for VGA is normal XRad! = Radius% / Asp! ' squish vertically ELSEIF Asp! < 1 THEN ' YRad! = Radius% * Asp! ' squish horizontally END IF ' ' DO ' IF T% = 1 THEN ' compute starting degree Srad! = Srad! + (180 \ Petals%) ' END IF ' Sr! = Srad! * (Pi2! / 360) ' compute radians for degrees PSET (Col%, Row%), Colour% ' center dot - sets LPR FOR T! = .01 TO Pi2! STEP .01 ' start drawing L! = SIN(Petals% * T!) ' compute factors to P! = T! - Sr! ' use to compute X and Y R! = XRad! * L! ' general purpose radius X% = Col% + (R! * COS(P!)) ' compute column for pixel IF Asp! <> 1 THEN R! = YRad! * L! ' if aspect other than normal Y% = Row% - (R! * SIN(P!)) ' compute row for pixel LINE -(X%, Y%), Colour% ' draw line from LPR to new XY NEXT ' T% = T% + 1 ' increase pass counter LOOP UNTIL (T% > 1) ' all done! END SUB ' ------------------ ' --- DEMO SUBS --- ' ------------------ SUB Daisies CLS Col% = 50 Row% = 50 Rad% = 50 Aspect! = 1! Colour% = 14 FOR Lobes% = 20 TO 1 STEP -1 I% = (360 \ Lobes%) FOR StartD! = 0 TO I% CadioidCurves Col%, Row%, Rad%, Aspect!, StartD!, Lobes%, Colour% IF StartD! = 0 AND C% > 0 THEN SLEEP .5 IF StartD! = I% THEN EXIT FOR G$ = INKEY$: IF LEN(G$) > 0 THEN EXIT SUB LINE (Col% - Rad%, Row% - Rad%)-(Col% + Rad%, Row% + Rad%), 0, BF NEXT Col% = Col% + 110 IF Col% > 580 THEN Row% = Row% + 110 Col% = 50 END IF NEXT END SUB SUB RollingWheel CLS Row% = 400 Rad% = 40 Aspect! = 1.2 StartD! = 0 Lobes% = 11 Colour% = 15 Col% = Rad% Sincr! = (360 \ Lobes%) DO CIRCLE (Col%, Row%), Rad%, Colour%, , , Aspect! CadioidCurves Col%, Row%, Rad%, Aspect!, StartD!, Lobes%, Colour% G$ = INKEY$: IF LEN(G$) > 0 THEN EXIT SUB Col% = Col% + 1 Row% = Row% - 1 StartD! = StartD! - Sincr! LINE (Col% - Rad% - 2, Row% - Rad% - 2)-(Col% + Rad% + 2, Row% + Rad% + 2), 0, BF LOOP UNTIL (Col% > 639) OR (Row% < Rad%) END SUB