_TITLE "Tangram 1 by Bplus" 'b+ 2020-11-09 & 10 _SCREENMOVE 70, 5 'sorry this works for my screen, yours is likely different
' ============================= 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.
CONST True
= -1, False
= 0, X
= 1, Y
= 2, Escape
= 27, Space
= 32, Rmax
= 114, Rmin
= 82 CONST Normal
= 1, MapTriangle
= 2, Opengl
= 3, White
= _RGB32(255), Up
= 18432, Down
= 20480
' vo(number of object, cohordinate, value of vertex with 5 as center cohordinate) ' TdB
Initialize
info
message "Tangram 1 Normal mode: press space to change graphic", 0, 0
IF GrActive
< Opengl
THEN GrActive
= GrActive
+ 1 ELSE GrActive
= Normal
' TdB mode = "Tangram 1 Normal mode: press space to change graphic"
mode = "Tangram 1 MapTriangle mode: press space to change graphic"
mode = "Tangram 1 OpenGl mode: press space to change graphic"
GrActive = 5
' infoscreen
message mode, 0, 0
IF GrActive
= 5 THEN GrActive
= 3 IF Kb
= Rmax
OR Kb
= Rmin
THEN 'reset or fix 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
_LIMIT 10 'peharps we must change this fps to 30
'-------------SUBs/Functions area-------------------
message "Do you really quit? Y/N", 0, 0
message "TANGRAM 1 by Bplus", 0, 5
message " Usage: press r or R reset, press spacebar to change graphic mode", -1, 11
message " use Left Mouse Button to drag and drop the pieces by circles", -1, 12
message " use Mouse Wheel to rotate the pieces while mouse points to circles", -1, 13
message "Press a key to continue...", 0, 18
Xt = 1
Yt = 1
tri45 i
square i
parallel i
VertObj(i, X, 5) = obj(i).cx ' TdB
VertObj(i, Y, 5) = obj(i).cy ' TdB
CIRCLE (VertObj
(i
, X
, 5), VertObj
(i
, Y
, 5)), 2, &HFF000000 ' here it draws the little circle CIRCLE (VertObj
(i
, X
, 5), VertObj
(i
, Y
, 5)), 3, &HFFFFFFFF ' so we can use _GL_POINTS
rotRad
= _D2R(obj
(i
).rotDegrees
) bx
= obj
(i
).cx
+ .25 * obj
(i
).lenBase
* COS(_PI(.5) + rotRad
) by
= obj
(i
).cy
+ .25 * obj
(i
).lenBase
* SIN(_PI(.5) + rotRad
) VertObj
(i
, X
, 1) = bx
+ .5 * obj
(i
).lenBase
* COS(_PI + rotRad
) VertObj
(i
, Y
, 1) = by
+ .5 * obj
(i
).lenBase
* SIN(_PI + rotRad
) VertObj
(i
, X
, 2) = bx
+ .5 * obj
(i
).lenBase
* COS(rotRad
) VertObj
(i
, Y
, 2) = by
+ .5 * obj
(i
).lenBase
* SIN(rotRad
) VertObj
(i
, X
, 3) = obj
(i
).cx
+ .25 * obj
(i
).lenBase
* COS(_PI(1.5) + rotRad
) VertObj
(i
, Y
, 3) = obj
(i
).cy
+ .25 * obj
(i
).lenBase
* SIN(_PI(1.5) + rotRad
)
ntri VertObj(i, X, 1), VertObj(i, Y, 1), VertObj(i, X, 2), VertObj(i, Y, 2), VertObj(i, X, 3), VertObj(i, Y, 3), obj(i).colr ' here we must use _GL_TRIANGLES
ftri VertObj(i, X, 1), VertObj(i, Y, 1), VertObj(i, X, 2), VertObj(i, Y, 2), VertObj(i, X, 3), VertObj(i, Y, 3), obj(i).colr ' here we must use _GL_TRIANGLES
rotRad
= _D2R(obj
(i
).rotDegrees
) VertObj
(i
, X
, in
) = obj
(i
).cx
+ obj
(i
).lenBase
* sqr2d2
* COS(_PI / 2 * in
+ rotRad
) VertObj
(i
, Y
, in
) = obj
(i
).cy
+ obj
(i
).lenBase
* sqr2d2
* SIN(_PI / 2 * in
+ rotRad
)
ftri VertObj(i, X, 1), VertObj(i, Y, 1), VertObj(i, X, 2), VertObj(i, Y, 2), VertObj(i, X, 3), VertObj(i, Y, 3), obj(i).colr ' here we must use _GL_QUADS
ftri VertObj(i, X, 3), VertObj(i, Y, 3), VertObj(i, X, 4), VertObj(i, Y, 4), VertObj(i, X, 1), VertObj(i, Y, 1), obj(i).colr
rotRad
= _D2R(obj
(i
).rotDegrees
) arm = .5 * obj(i).lenBase * sqr2d2
VertObj
(i
, X
, 1) = obj
(i
).cx
+ arm
* COS(_PI(1.25) + rotRad
) VertObj
(i
, Y
, 1) = obj
(i
).cy
+ arm
* SIN(_PI(1.25) + rotRad
) VertObj
(i
, X
, 2) = VertObj
(i
, X
, 1) + obj
(i
).lenBase
* COS(0 + rotRad
) VertObj
(i
, Y
, 2) = VertObj
(i
, Y
, 1) + obj
(i
).lenBase
* SIN(0 + rotRad
) VertObj
(i
, X
, 3) = obj
(i
).cx
+ arm
* COS(_PI(.25) + rotRad
) VertObj
(i
, Y
, 3) = obj
(i
).cy
+ arm
* SIN(_PI(.25) + rotRad
) VertObj
(i
, X
, 4) = VertObj
(i
, X
, 3) + obj
(i
).lenBase
* COS(_PI + rotRad
) VertObj
(i
, Y
, 4) = VertObj
(i
, Y
, 3) + obj
(i
).lenBase
* SIN(_PI + rotRad
)
ftri VertObj(i, X, 1), VertObj(i, Y, 1), VertObj(i, X, 2), VertObj(i, Y, 2), VertObj(i, X, 3), VertObj(i, Y, 3), obj(i).colr 'here we must use _GL_QUADS
ftri VertObj(i, X, 3), VertObj(i, Y, 3), VertObj(i, X, 4), VertObj(i, Y, 4), VertObj(i, X, 1), VertObj(i, Y, 1), obj(i).colr
_BLEND a&
'<<<< new 2019-12-16 fix
LINE (x1
, y1
)-(x2
, y2
), K
LINE (x2
, y2
)-(x3
, y3
), K
LINE (x3
, y3
)-(x1
, y1
), K
PAINT ((x1
+ x2
+ x3
) / 3, (y1
+ y2
+ y3
) / 3), K
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
= &HFFFF8800 drawObj 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
= &HFF008800 drawObj 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
= &HFF000066 drawObj 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
= &HFF00DDDD drawObj 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
= 135 obj(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
= 0 obj(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
= 0 obj(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)
GlInit = True ' TdB
GrActive = Normal ' TdB
'---------------OpenGL AREA---------------------------
' here it draws GL objects
drawObj i
GLTri45 i
GLQuadr i
GLParall i
glRc = Proportion(0, 255, 0, 1, sRc)
glGc = Proportion(0, 255, 0, 1, sGc)
glBc = Proportion(0, 255, 0, 1, sBc)
glAc = Proportion(0, 255, 0, 1, sAc)
_glVertex2f Proportion
(0, 1280, -1, 1, VertObj
(i
, X
, 5)), Proportion
(0, 740, 1, -1, VertObj
(i
, Y
, 5))
glRc = Proportion(0, 255, 0, 1, sRc)
glGc = Proportion(0, 255, 0, 1, sGc)
glBc = Proportion(0, 255, 0, 1, sBc)
glAc = Proportion(0, 255, 0, 1, sAc)
_glVertex2f Proportion
(0, 1280, -1, 1, VertObj
(i
, X
, a
)), Proportion
(0, 740, 1, -1, VertObj
(i
, Y
, a
))
glRc = Proportion(0, 255, 0, 1, sRc)
glGc = Proportion(0, 255, 0, 1, sGc)
glBc = Proportion(0, 255, 0, 1, sBc)
glAc = Proportion(0, 255, 0, 1, sAc)
_glVertex2f Proportion
(0, 1280, -1, 1, VertObj
(i
, X
, a
)), Proportion
(0, 740, 1, -1, VertObj
(i
, Y
, a
))
glRc = Proportion(0, 255, 0, 1, sRc)
glGc = Proportion(0, 255, 0, 1, sGc)
glBc = Proportion(0, 255, 0, 1, sBc)
glAc = Proportion(0, 255, 0, 1, sAc)
_glVertex2f Proportion
(0, 1280, -1, 1, VertObj
(i
, X
, a
)), Proportion
(0, 740, 1, -1, VertObj
(i
, Y
, a
))
FUNCTION Proportion
(min1
, max1
, min2
, max2
, value
) ' min1: max1 = min2:max2= value: X
' (max1-min1): Value = (max2-min2) : X
' X = ((max2-min2) * value)/ (max1-min1)
Proportion = (((max2 - min2) * value) / (max1 - min1)) + min2