'RING-PUZZLE-TRINKET
DIM col&
(20) 'marble colors DIM LMAP
(30) 'Full marble layout DIM KMAP
(2, 20) 'Solution layout DIM RINGMAP
(2, 20) 'RING layout
'///////////SOUNDS////////////////////////////////
snda&
= _SNDOPEN("SFX/rotate.wav", "sync")sndb&
= _SNDOPEN("SFX/final.wav", "sync")sndc&
= _SNDOPEN("SFX/correct.wav", "sync")sndd&
= _SNDOPEN("SFX/iMAC.wav", "sync")snde&
= _SNDOPEN("SFX/error.wav", "sync")
'///////////CONSTANTS/////////////////////////////
r = 140 'ring radius
mr = 15 'marble radius
n = 6 'number of marbles PER RING *!make this even
q
= (_PI(1) / n
) 'half angle between marblesd
= r
* COS(q
) 'ring center offset from CENTRIXCENTRIX = 350 'x axis center of RING SYSTEM
CENTRIY = 200 'y axis center of RING SYSTEM
mt = (2 * n) - 2 'marble total
WHT&
= _RGB(255, 255, 255)
'//////////ASSIGN COLOR TO MARBLES////////////////
w = (i / mt) - (1 / mt)
GOSUB w_rainbow
'Linear Rainbow mixer using "w" input col&(i) = colr& 'color of marble ID
LMAP(i) = i 'Initialize MARBLE ID LOCATIONS
'SET SOLUTION KMAP AS INITIAL LAYOUT
KMAP(1, i) = i
KMAP(2, i) = RINGMAP(2, i)
'/////////SCRAMBLE via RANDOM OPERATIONS///////
DIFFICULTY = 5 'minimum number of moves needed to solve
'try 10,20,50,100!!!
FOR k
= 1 TO DIFFICULTY
'DIFFICULTY OF SCRAMBLE
'//////////////INITIAL DISPLAY///////////////////////
CIRCLE (CENTRIX
- d
, CENTRIY
), r
, _RGB(50, 100, 100) CIRCLE (CENTRIX
+ d
, CENTRIY
), r
, _RGB(150, 100, 100)
FOR i
= 1 TO n
'number of marbles per ring u
= 0 - (_PI(1) * (i
) / (.5 * n
)) + q
'////////////////DRAW MARBLES//////////////////////
CIRCLE (CENTRIX
- dd
+ marblex
, CENTRIY
+ marbley
), mr
, col&
(RINGMAP
(k
, i
)) PAINT (CENTRIX
- dd
+ marblex
, CENTRIY
+ marbley
), col&
(RINGMAP
(k
, i
)) CIRCLE (CENTRIX
- dd
+ marblex
, CENTRIY
+ marbley
), mr
, WHT&
'////////////////DRAW ARCS/////////////////////////
CIRCLE (CENTRIX
- dd
+ (marblex
* .3), CENTRIY
+ (marbley
* .3)), (mr
* 3) + s
, col&
(KMAP
(k
, i
)), ABS(u
+ .3), ABS(u
- .3), 1
COLOR BLK&
, col&
(RINGMAP
(k
, i
))
PRINT "LEFT CLICK : counter-clockwise" PRINT "RIGHT CLICK: clockwise"
'MOUSE CAPTURE LOOP
IF RSWIRL
THEN dir
= -.015: A
= 0: B
= -1 IF LSWIRL
THEN dir
= .015: A
= 0: B
= 1
'//////////////////////ZOLVED///////////////////////////
win = 0 'count ON LEDS
IF RINGMAP
(k
, i
) = KMAP
(k
, i
) THEN win
= win
+ 1
LOADA:
FOR i
= 1 TO n
'load marbles onto RING A RINGMAP(1, i) = LMAP(i)
LOADB:
FOR i
= 1 TO n
- 1 'load marbles onto RING B j = i + (n / 2) 'n MUST BE EVEN! for this part to work
RINGMAP(2, j) = LMAP(n + i - 1)
RINGMAP(2, (n / 2)) = LMAP(1)
DRAWLEDS:
IF RINGMAP
(k
, i
) = KMAP
(k
, i
) THEN 'DRAW ON CIRCLE (CENTRIX
- dd
+ (marblex
* .5), CENTRIY
+ (marbley
* .5)), mr
* .5, col&
(KMAP
(k
, i
)), , , 1 PAINT (CENTRIX
- dd
+ (marblex
* .5), CENTRIY
+ (marbley
* .5)), col&
(KMAP
(k
, i
)) CIRCLE (CENTRIX
- dd
+ (marblex
* .5), CENTRIY
+ (marbley
* .5)), mr
* .5, WHT&
, , , 1 CIRCLE (CENTRIX
- dd
+ (marblex
* .5), CENTRIY
+ (marbley
* .5)), mr
* .5, BLK&
, , , 1 PAINT (CENTRIX
- dd
+ (marblex
* .5), CENTRIY
+ (marbley
* .5)), BLK&
CIRCLE (CENTRIX
- dd
+ (marblex
* .5), CENTRIY
+ (marbley
* .5)), mr
* .5, col&
(KMAP
(k
, i
)), , , 1
SHOWMAP: 'Just shows LEDS actually
u
= 0 - (_PI(1) * (i
) / (.5 * n
)) + q
'///////////////RING ROTATION ANIMATION////////////////////////////
rotate:
FOR i
= 1 TO n
'// erase former marble positions LINE (CENTRIX
- dd
+ marblex
(i
) - mr
- 2, CENTRIY
+ marbley
(i
) - mr
- 2)-(CENTRIX
- dd
+ marblex
(i
) + mr
+ 2, CENTRIY
+ marbley
(i
) + mr
+ 2), BLK&
, BF
t = u * 2 * q 'update radian of rotation
CIRCLE (CENTRIX
- dd
, CENTRIY
), r
, _RGB(100 - dd
, 100, 100) FOR i
= 1 TO n
'// draw marbles marblex
(i
) = r
* COS(t
- (_PI(1) * i
/ (.5 * n
)) + q
) marbley
(i
) = r
* SIN(t
- (_PI(1) * i
/ (.5 * n
)) + q
)
COLOR BLK&
, col&
(RINGMAP
(RINGID
, i
)) CIRCLE (CENTRIX
- dd
+ marblex
(i
), CENTRIY
+ marbley
(i
)), mr
, col&
(RINGMAP
(RINGID
, i
)) PAINT (CENTRIX
- dd
+ marblex
(i
), CENTRIY
+ marbley
(i
)), col&
(RINGMAP
(RINGID
, i
))
CIRCLE (CENTRIX
- dd
+ marblex
(i
), CENTRIY
+ marbley
(i
)), mr
, WHT&
NEXT u
'animation complete
'INDEX ROTATION OPERATION SELECTION
'///////////////FINAL ANIMATION////////////////////////////
final:
IF k
= 1 THEN dd
= d: tt
= tq: l
= 2 IF k
= 2 THEN dd
= -d: tt
= -tq: l
= -2
CIRCLE (CENTRIX
- dd
- tt
, CENTRIY
), r
, BLK&
FOR i
= 1 TO n
'// erase former marble positions marblex
(i
) = r
* COS((l
* t
) - (_PI(1) * i
/ (.5 * n
)) + q
) marbley
(i
) = r
* SIN((l
* t
) - (_PI(1) * i
/ (.5 * n
)) + q
) LINE (CENTRIX
- dd
+ marblex
(i
) - mr
- 2 - tt
, CENTRIY
+ marbley
(i
) - mr
- 2)-(CENTRIX
- dd
+ marblex
(i
) + mr
+ 2 - tt
, CENTRIY
+ marbley
(i
) + mr
+ 2), BLK&
, BF
LINE (CENTRIX
- dd
+ (marblex
(i
) * .5) - (mr
* .6) - tt
, CENTRIY
+ (marbley
(i
) * .5) - (mr
* .6))-(CENTRIX
- dd
+ (marblex
(i
) * .5) + (mr
* .6) - tt
, CENTRIY
+ (marbley
(i
) * .5) + (mr
* .6)), BLK&
, BF
tq = tq + 1.3 'horizontal motion
t = -u * 2 * q 'update radian of rotation
IF k
= 1 THEN dd
= d: tt
= tq: l
= 2 IF k
= 2 THEN dd
= -d: tt
= -tq: l
= -2
CIRCLE (CENTRIX
- dd
- tt
, CENTRIY
), r
, _RGB(100 - dd
, 100, 100) FOR i
= 1 TO n
'// draw marbles marblex
(i
) = r
* COS((l
* t
) - (_PI(1) * i
/ (.5 * n
)) + q
) marbley
(i
) = r
* SIN((l
* t
) - (_PI(1) * i
/ (.5 * n
)) + q
)
COLOR BLK&
, col&
(KMAP
(k
, i
)) CIRCLE (CENTRIX
- dd
+ marblex
(i
) - tt
, CENTRIY
+ marbley
(i
)), mr
, col&
(KMAP
(k
, i
)) PAINT (CENTRIX
- dd
+ marblex
(i
) - tt
, CENTRIY
+ marbley
(i
)), col&
(KMAP
(k
, i
))
CIRCLE (CENTRIX
- dd
+ marblex
(i
) - tt
, CENTRIY
+ marbley
(i
)), mr
, WHT&
'////LEDS
CIRCLE (CENTRIX
- dd
+ (marblex
(i
) * .5) - tt
, CENTRIY
+ (marbley
(i
) * .5)), mr
* .5, col&
(KMAP
(k
, i
)), , , 1 PAINT (CENTRIX
- dd
+ (marblex
(i
) * .5) - tt
, CENTRIY
+ (marbley
(i
) * .5)), col&
(KMAP
(k
, i
)) CIRCLE (CENTRIX
- dd
+ (marblex
(i
) * .5) - tt
, CENTRIY
+ (marbley
(i
) * .5)), mr
* .5, WHT&
, , , 1
_PRINTSTRING (CENTRIX
- (6 * 8) - 3, CENTRIY
), "DISCS SYNCED!"
'====================================================
'==========- SOLUTION FOUND END -==================
'====================================================
'////////////////////////////////////////////////////
'///// INDEX ROTATION OPERATIONS /////
'////////////////////////////////////////////////////
'ROTATION OPERATION on LMAP SEGMENTS
ARSWIRL: 'CLOCKWISE on RING A
temp = LMAP(n)
LMAP(i) = LMAP(i - 1)
LMAP(1) = temp
RSWIRL = 0
ALSWIRL: 'COUNTER-CLOCKWISE on RING A
temp = LMAP(1)
LMAP(i) = LMAP(i + 1)
LMAP(n) = temp
LSWIRL = 0
BRSWIRL: 'CLOCKWISE on RING B
temp = LMAP(mt)
LMAP(i) = LMAP(i - 1)
LMAP(n) = LMAP(1)
LMAP(1) = temp
RSWIRL = 0
BLSWIRL: 'COUNTER-CLOCKWISE on RING B
temp = LMAP(n)
LMAP(i) = LMAP(i + 1)
LMAP(mt) = LMAP(1)
LMAP(1) = temp
LSWIRL = 0
'/////////////////////LINEAR RAINBOW////////////////////////////////////////////
w_rainbow: 'converts single variable ru=(0 to 1) into a mixture blending from R to G to B
t.col
= INT(w
* 1530) ' converts ru=(0,1) TO (0,1530)colr&
= _RGB(0, 0, 0) 'default if ru out of rangeIF t.col
>= (0 * 255) AND t.col
< (1 * 255) THEN colr&
= _RGB(255, t.col
- (0 * 255), 0) 'R*/G-phase 0 = RED IF t.col
>= (1 * 255) AND t.col
< (2 * 255) THEN colr&
= _RGB(t.col
- (255 * 1), 255, 0) 'G*\R-phase 255 = RG IF t.col
>= (2 * 255) AND t.col
< (3 * 255) THEN colr&
= _RGB(0, 255, t.col
- (2 * 255)) 'G*/B-phase 510 = GREEN IF t.col
>= (3 * 255) AND t.col
< (4 * 255) THEN colr&
= _RGB(0, (4 * 255) - t.col
, 255) 'B*\G-phase 765 = GB IF t.col
>= (4 * 255) AND t.col
< (5 * 255) THEN colr&
= _RGB(t.col
- (4 * 255), 0, 255) 'B*/R-phase 1020= BLUE IF t.col
>= (5 * 255) AND t.col
<= (6 * 255) THEN colr&
= _RGB(255, 0, (6 * 255) - t.col
) 'R*\B-phase 1275= BR