_TITLE "Jointed arms clock #4: Any changes color, digits change hours: 0 = 12 or click mouse at 1, 2, 3... o'clock" 'b+ started 2020-11-22 ' inspsired by STx Parametric clock specially the faces https://www.qb64.org/forum/index.php?topic=3277.msg125579#msg125579
' I wish to see what a large circle joint at center would look like, first can I get similar face? yes sorta
' 2020-11-23 More work on clock face, less LOC for drawPully, add modes and color changes
' 2020-11-24 add stuff to make different arms
CONST xmax
= 710, ymax
= 710, CX
= xmax
/ 2, CY
= ymax
/ 2, hhr0
= 20, hhr1
= 10, mhr1
= 5, shr1
= 0, hh
= 180, mh
= 110, sh
= 36 makeAFace
makeAFace
IF a
>= 0 AND a
<= 12 THEN mode
= a: makeAFace
hha
= (h
+ (m
/ 60)) / mode
* _PI(2) - _PI(.5) mha
= (m
/ 60 + (s
/ 3600)) * _PI(2) - _PI(.5) sha
= s
/ 60 * _PI(2) - _PI(.5) hhx
= CX
+ hh
* COS((hha
)): hhy
= CY
+ hh
* SIN((hha
)) mhx
= hhx
+ mh
* COS((mha
)): mhy
= hhy
+ mh
* SIN((mha
)) shx
= mhx
+ ((12 - mode
) * 3 + sh
) * COS((sha
)): shy
= mhy
+ ((12 - mode
) * 3 + sh
) * SIN((sha
)) 'drawPully CX, CY, hhr0, hhx, hhy, hhr1, &HFFFFFFFF
'drawPully hhx, hhy, hhr1, mhx, mhy, mhr1, &HFFFFFFFF
'drawPully mhx, mhy, mhr1, shx, shy, shr1, &HFFFFFFFF
RotoZoom3 CX, CY, hourHand&, 1, 1, hha
RotoZoom3 hhx, hhy, minHand&, 1, 1, mha
RotoZoom3 mhx, mhy, secHand&, 1, 1, sha
LINE (x1
+ r1
* COS(a
), y1
+ r1
* SIN(a
))-(x2
+ r2
* COS(a
), y2
+ r2
* SIN(a
)), c
colr
= _RGB32((RND < .5) * -1 * (RND * 128 + 127), RND * 128 + 127, (RND < .5) * -1 * (RND * 128 + 127), &H23) FOR vi
= 1 TO mode
* 3600 h = vi / 3600
hha
= h
/ mode
* _PI(2) - _PI(.5) hhx
= CX
+ hh
* COS((hha
)): hhy
= CY
+ hh
* SIN((hha
)) mhx
= hhx
+ mh
* COS((mha
)): mhy
= hhy
+ mh
* SIN((mha
)) shx
= mhx
+ ((12 - mode
) * 3 + sh
) * COS((sha
)): shy
= mhy
+ ((12 - mode
) * 3 + sh
) * SIN((sha
)) drawPully mhx, mhy, mhr1, shx, shy, shr1, colr
'arms look better with the draw color for the face on the edges, it hides raggity border edges.
' otherwise we could just draw these once at the beginning of program.
makeArmImage hourHand&, hh, hhr0, hhr1, &HFFFFFFFF, &H88000000
makeArmImage minHand&, mh, hhr1, mhr1, &HFFFFFFFF, &H88000000
makeArmImage secHand&, sh, mhr1, shr1, &HFFFFFFFF, &H88000000
' intend to use this with rotozoom so have to make image rotate-able in middle
' arm image starts big in middle and points right to smaller radius r2
' hdl& image handle to use
' length run of origins of half circles
' c1 is color on left in middle = bigger joint , c2 is color on right
DIM width, height
, wd2
, hd2
, x1
, y1
, x2
, y2
, a
width = 2 * (r2
+ length
) + 2: height
= 2 * r1
+ 2: wd2
= width / 2: hd2
= height
/ 2 x1
= wd2: y1
= hd2: x2
= wd2
+ length: y2
= hd2: a
= _PI(.5) LINE (x1
+ r1
* COS(a
), y1
+ r1
* SIN(a
))-(x2
+ r2
* COS(a
), y2
+ r2
* SIN(a
)), colr
arc x1
, y1
, r1
, _PI(.5), _PI(1.5), colr
arc x2
, y2
, r2
, _PI(1.5), _PI(.5), colr
paint4 x1, y1, c1, c2
'use radians
' raStart is first angle clockwise from due East = 0 degrees
' arc will start drawing there and clockwise until raStop angle reached
'x, y origin, r = radius, c = color
DIM raStart
, raStop
, dStart
, dStop
, al
, a
' Last time I tried to use this SUB it hung the program, possible causes:
' Make sure raStart and raStop are between 0 and 2pi.
' This sub does not have to be recursive, use GOSUB to do drawing to execute arc in one call.
'make copies before changing
raStart = raBegin: raStop = raEnd
dStart
= raStart: dStop
= _PI(2) - .00001 dStart = 0: dStop = raStop
dStart = raStart: dStop = raStop
drawArc: ' I am going back to lines instead of pset
al
= 2 * _PI * r
* (dStop
- dStart
) / _PI(2) lastx
= x
+ r
* COS(a
): lasty
= y
+ r
* SIN(a
)
DIM R1
, G1
, B1
, A1
, R2
, G2
, B2
, A2
cAnalysis c1, R1, G1, B1, A1
cAnalysis c2, R2, G2, B2, A2
Ink~&
= _RGB32(R1
+ (R2
- R1
) * fr##
, G1
+ (G2
- G1
) * fr##
, B1
+ (B2
- B1
) * fr##
, A1
+ (A2
- A1
) * fr##
)
DIM fillColor
AS _UNSIGNED LONG, W
, H
, parentF
, tick
, ystart
, ystop
, xstart
, xstop
, x
, y
fillColor
= POINT(x0
, y0
) 'PRINT fillColor
temp(x0, y0) = 1: parentF = 1
parentF = 0: tick = tick + 1
ystart = max(y0 - tick, 0): ystop = min(y0 + tick, H)
y = ystart
xstart = max(x0 - tick, 0): xstop = min(x0 + tick, W)
x = xstart
IF temp
(max
(0, x
- 1), y
) THEN x = x + 1
y = y + 1
' Description:
' Started from a mod of Galleon's in Wiki that both scales and rotates an image.
' This version scales the x-axis and y-axis independently allowing rotations of image just by changing X or Y Scales
' making this tightly coded routine a very powerful and versatile image tool.
' This assumes you have set your drawing location with _DEST or default to screen.
' X, Y - is where you want to put the middle of the image
' Image - is the handle assigned with _LOADIMAGE
' xScale, yScale - are shrinkage < 1 or magnification > 1 on the given axis, 1 just uses image size.
' These are multipliers so .5 will create image .5 size on given axis and 2 for twice image size.
' radianRotation is the Angle in Radian units to rotate the image
' note: Radian units for rotation because it matches angle units of other Basic Trig functions
' and saves a little time converting from degree.
' Use the _D2R() function if you prefer to work in degree units for angles.
DIM W&
, H&
, sinr!
, cosr!
, i&
, x2&
, y2&
' variables for image manipulation px(0) = -W& / 2: py(0) = -H& / 2 'left top corner
px(1) = -W& / 2: py(1) = H& / 2 ' left bottom corner
px(2) = W& / 2: py(2) = H& / 2 ' right bottom
px(3) = W& / 2: py(3) = -H& / 2 ' right top
sinr!
= SIN(-radianRotation
): cosr!
= COS(-radianRotation
) ' rotation helpers FOR i&
= 0 TO 3 ' calc new point locations with rotation and zoom x2& = xScale * (px(i&) * cosr! + sinr! * py(i&)) + X: y2& = yScale * (py(i&) * cosr! - px(i&) * sinr!) + Y
px(i&) = x2&: py(i&) = y2&