>Segment3 : Cy Booker : 86 Church View : Main Road : Crockenhill : Swanley : Kent : BR8 8 JW Test algorithm for drawing an hsv cone dynamically Instead of drawing curves, we draw quadrangles We pre-calculate all trig multiplications The circle is split into NT% = 8*2^N% angles [N% = 0, 1, 2, 3] The outer radius is R [= Radius * Value] Each annulus is DR% wide There are NA% annuli = floor(R / DR%) Note tried just storing points at corners of each quadrangle but this results in too much screen overwriting, so now going to store for each quadrangle the four points, suitably grown in one half pixel No, this leaves some gaps, so trying to align to 2 OS unit "pixel" grid No, if align all up to 2 pixel grid, at least leaves no gaps Note that for radius R, the max distance between straight line and actual radius occurs when N% = 0, and get d = r*(1-COS(PI/8)) which for r= 128 => d= 9.74 The above means when try blanking out need to add 10 OS units to radius to ensure blank all This produces a nice demo of the finnished program The lhs is the value bar, click with mouse to set value $+ " {"+ )+ "}" "7Value = -1 : 0 <= Value < 1.0 #BRadius = 127.5 : Radius of cone, in OS units $AN% = 0 : measure of accuracy [0, 3] %4HalfPixel% = 1 : min(x,y half) &$EigthHue% = (360 * &10000) / 8 RadiusFudge = 10 SegmentPartsPerFrame% = 13 X%(8-1, 32-1, 3) Y%(8-1, 32-1, 3) Hue%(8-1) Saturation%(32-1) Drawn%(32*8*8 - 1) /5DisplayedRadius = -1 : sentinel value "Wimp_SetColour", 1 512, 512 -512, -512, 40, 1024 _Change_Value(1.00) x%, y%, b% 9+ _Change_Value((y%+512)/1024) _Update_HSV _Update_HSV n%, i%, j% NA% = 0 NToDraw% = 0 N% = 3 N% += 1 _Calc_HSV_Constants F n% = SegmentPartsPerFrame% n% > NToDraw% n% = NToDraw% n%=0 1, "ASSERT" i%= 1 JC j%= (NT%*NA%) - 2 : now in range [-1, n-1) K j% += 1 M' j%=(NT%*NA%-1) Drawn%(j%) Drawn%(j%) O$ j%=0: Drawn%(j%):j%+=1: P' j%>=NT%*NA% 1, "ASSERT" Q R. _Draw_SegmentPart(j% NT%, j% NT%) Drawn%(j%) = NToDraw% -= n% W : _Change_Value(v) v%, c%, x0, x1, x2, x3, y0, y1, y2, y3 Value=v Value = v "Wimp_SetColour", 12 v% = Value * 1024 -512, -512, 40, v% "Wimp_SetColour", 11 -512, -512+v%, 40, 1024 R = Radius * Value bG N% = 0 : start off coarse _Calc_HSV_Constants DisplayedRadius > R e( now must immediately blank out "Wimp_SetColour", 1 NA% >= 1 h( x0 = R : y0 = 0 i( x1 = DisplayedRadius : y1 = 0 t%= 1 t = 2* *(t%/15) cos = sin = n1 x2 = R*cos : y2 = R*sin o? x3 = DisplayedRadius*cos : y3 = DisplayedRadius*sin x0, y0 x1, y1 &55, x2, y2 x3, y3 &55, x1, y1 x0 = x2 : y0 = y2 x1 = x3 : y1 = y3 x y% 0, 0, DisplayedRadius z |7 : draw grey center of cone (greyness is "value") c% = (Value*255) + 0.5 "ColourTrans_SetGCOL", (c% * &010101) << 8,,,&100,0 0, 0, R - DR%*NA% ' DisplayedRadius = R + RadiusFudge _Calc_HSV_Constants A OT% = 1 << N% : #divisions in one octant C NT% = 8 * OT% : #divisions in whole circle : DR% = 32 OT% : size of each annuli : NA% = floor(R, DR%) : #annuli (complete) NA% >= 1 _Calc_Octant _Calc_Octant a%, t%, a, cos, r, sin, t a%= 0 NA%-1 , : get radius of middle of annuli a% ( r = (R - (a% * DR%)) - (DR% / 2) 2 Saturation%(a%) = ((r / R) * &10000) + 0.5 t%= 0 OT%-1 5 : angle in middle of segment in range (0, 1) t = (t% + 0.5) / OT% 1 Hue%(t%) = (360 * &10000 * (t / 8)) + 0.5 % Value% = (Value * &10000) + 0.5 delta = (HalfPixel% / R) t%= 0 OT%-1 : angles {0, .., PI/4} ! tmin = ( /4) * (t% / OT%) # tmax = tmin + (( /4) / OT%) cosmin = (tmin) sinmin = (tmin) cosmax = (tmax) sinmax = (tmax) a%= 0 NA%-1 rmax = R - (a% * DR%) rmin = rmax - DR% / X%(t%, a%, 0) = roundup(rmin*cosmin) / Y%(t%, a%, 0) = roundup(rmin*sinmin) / X%(t%, a%, 1) = roundup(rmax*cosmin) / Y%(t%, a%, 1) = roundup(rmax*sinmin) / X%(t%, a%, 2) = roundup(rmax*cosmax) / Y%(t%, a%, 2) = roundup(rmax*sinmax) / X%(t%, a%, 3) = roundup(rmin*cosmax) / Y%(t%, a%, 3) = roundup(rmin*sinmax) Drawn%() = NToDraw% = NT% * NA% [-1 .. +1) --> 0 round(x) ((x / 2) + 0.5) * 2 roundup(x) = 2 * ceiling(x, 2) rounddown(x) = 2 * floor(x, 2) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ integer round x/y towards +infinity ceiling(x, y) x <> x = x / y x = x <> x = 1 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ integer round x/y towards -infinity floor(x, y) x <> x = - x = x / y _Draw_SegmentPart(a%, t%) x0%,x1%,x2%,x3%, y0%,y1%,y2%,y3%, hue%, saturation% _Draw_SegmentPart_Point(x0%,y0%, a%, t%, 0) _Draw_SegmentPart_Point(x1%,y1%, a%, t%, 1) _Draw_SegmentPart_Point(x2%,y2%, a%, t%, 2) _Draw_SegmentPart_Point(x3%,y3%, a%, t%, 3) 6 hue% = Hue%(t% OT%) + ((t% OT%) * EigthHue%) hue% >= 360*&10000 1, "ASSERT" hue% <= 0 1, "ASSERT" # saturation% = Saturation%(a%) "ColourTrans_ConvertHSVToRGB", hue%, saturation%, Value% red%, green%, blue% red% = rgb(red%) << 8 ! green% = rgb(green%) << 16 blue% = rgb(blue%) << 24 "ColourTrans_SetGCOL", red% green% blue%,,, &100, 0 x0%, y0% x1%, y1% &55, x2%, y2% x3%, y3% &55, x0%, y0% MOVE x0%, y0% DRAW x1%, y1% DRAW x2%, y2% DRAW x3%, y3% DRAW x0%, y0% rgb(A%) & A% = ((A% * 255) / &10000) + 0.5 A% < 0 1 , "negative" A% > 255 1, "too big" _Draw_SegmentPart_Point( x%, y%, a%, t%, i%) x% = X%(t% OT%, a%, i%) y% = Y%(t% OT%, a%, i%) t% = t% t% > 7 1, "bad t%" t% = t% (t% >> 1) x%, y% x% = -x% y% = -y%