_TITLE "Tangram 1 press r reset if handles get stuck" 'b+ 2020-11-09 & 10
' ============================= Instructions ==================================================
'
' The little dot on the pieces are handles for dragging pieces or rotating them with mousewheel.
' Don't drag a handle near another or the pieces will stick together, press r if they do.
'
'=================================================================================================
CONST sqr2d2
= SQR(2) / 2 ' for converting lengths with 45/90 triangles.
_SCREENMOVE 70, 5 'sorry this works for my screen, yours is likely different
obj
(1).typ
= 1: obj
(1).cx
= _WIDTH / 2 - 125: obj
(1).cy
= _HEIGHT / 2: obj
(1).lenBase
= 500: obj
(1).rotDegrees
= 90: obj
(1).colr
= &HFFFF8800drawObj 1
obj
(2).typ
= 1: obj
(2).cx
= _WIDTH / 2: obj
(2).cy
= _HEIGHT / 2 - 125: obj
(2).lenBase
= 500: obj
(2).rotDegrees
= 180: obj
(2).colr
= &HFF008800drawObj 2
obj
(3).typ
= 1: obj
(3).cx
= _WIDTH / 2 - 2: obj
(3).cy
= _HEIGHT / 2 + 65: obj
(3).lenBase
= 250: obj
(3).rotDegrees
= 0: obj
(3).colr
= &HFF000066drawObj 3
obj
(4).typ
= 1: obj
(4).cx
= _WIDTH / 2 + 125 + 64: obj
(4).cy
= _HEIGHT / 2 - 125: obj
(4).lenBase
= 250: obj
(4).rotDegrees
= 270: obj
(4).colr
= &HFF00DDDDdrawObj 4
obj
(5).typ
= 1: obj
(5).cx
= _WIDTH / 2 + 125 + 64: obj
(5).cy
= _HEIGHT / 2 + 125 + 62.5: obj
(5).lenBase
= 500 * sqr2d2: obj
(5).rotDegrees
= 135obj(5).colr = &HFF880000
drawObj 5
obj
(6).typ
= 2: obj
(6).cx
= _WIDTH / 2 + 125: obj
(6).cy
= _HEIGHT / 2: obj
(6).lenBase
= 250 * sqr2d2: obj
(6).rotDegrees
= 0obj(6).colr = &HFFFFFF00
drawObj 6
obj
(7).typ
= 3: obj
(7).cx
= _WIDTH / 2 - 62.5: obj
(7).cy
= _HEIGHT / 2 + 125 + 62.5: obj
(7).lenBase
= 250: obj
(7).rotDegrees
= 0obj(7).colr = &HFF0000FF
drawObj 7
FOR i
= 1 TO 7 'make a copy of settings in case a handle gets stuck on another copy(i) = obj(i)
obj(i) = copy(i)
IF _HYPOT(obj
(i
).cx
- mx
, obj
(i
).cy
- my
) < 20 THEN ' mouse is down near a piece center IF mb
THEN obj
(i
).cx
= mx: obj
(i
).cy
= my
IF mw
THEN obj
(i
).rotDegrees
= obj
(i
).rotDegrees
+ mw
drawObj i
tri45 obj(i).cx, obj(i).cy, obj(i).lenBase, obj(i).rotDegrees, obj(i).colr
square obj(i).cx, obj(i).cy, obj(i).lenBase, obj(i).rotDegrees, obj(i).colr
parallel obj(i).cx, obj(i).cy, obj(i).lenBase, obj(i).rotDegrees, obj(i).colr
CIRCLE (obj
(i
).cx
, obj
(i
).cy
), 2, &HFF000000 CIRCLE (obj
(i
).cx
, obj
(i
).cy
), 3, &HFFFFFFFF
rotRad
= _D2R(rotDegrees
) bx
= cX
+ .25 * lenBase
* COS(_PI(.5) + rotRad
) by
= cY
+ .25 * lenBase
* SIN(_PI(.5) + rotRad
) x1
= bx
+ .5 * lenBase
* COS(_PI + rotRad
) y1
= by
+ .5 * lenBase
* SIN(_PI + rotRad
) x2
= bx
+ .5 * lenBase
* COS(rotRad
) y2
= by
+ .5 * lenBase
* SIN(rotRad
) x3
= cX
+ .25 * lenBase
* COS(_PI(1.5) + rotRad
) y3
= cY
+ .25 * lenBase
* SIN(_PI(1.5) + rotRad
) ftri x1, y1, x2, y2, x3, y3, colr
rotRad
= _D2R(rotDegrees
) xx
(i
) = centerX
+ lenSide
* sqr2d2
* COS(_PI / 2 * i
+ rotRad
) yy
(i
) = centerY
+ lenSide
* sqr2d2
* SIN(_PI / 2 * i
+ rotRad
) ftri xx(0), yy(0), xx(1), yy(1), xx(2), yy(2), colr
ftri xx(2), yy(2), xx(3), yy(3), xx(0), yy(0), colr
rotRad
= _D2R(rotDegrees
) arm = .5 * lenBase * sqr2d2
x1
= centerX
+ arm
* COS(_PI(1.25) + rotRad
) y1
= centerY
+ arm
* SIN(_PI(1.25) + rotRad
) x2
= x1
+ lenBase
* COS(0 + rotRad
) y2
= y1
+ lenBase
* SIN(0 + rotRad
) x3
= centerX
+ arm
* COS(_PI(.25) + rotRad
) y3
= centerY
+ arm
* SIN(_PI(.25) + rotRad
) x4
= x3
+ lenBase
* COS(_PI + rotRad
) y4
= y3
+ lenBase
* SIN(_PI + rotRad
) ftri x1, y1, x2, y2, x3, y3, colr
ftri x3, y3, x4, y4, x1, y1, colr
_BLEND a&
'<<<< new 2019-12-16 fix