5 REM --- COLORIER ---
10 SCREEN 9 : KEY OFF : CLS : COLOR 2
11 ON KEY(10) GOSUB 99 : KEY(10) ON
12 DIM M%(920)
13 P = 0 : Q = 0 'Position de l'image
14 C = 0 'Couleur du pixel avant l'arrivee du curseur
20 FILEI$ = "DESSIN.TXT"
21 OPEN "I",#1,FILEI$
22 FILEI$ = "PALETTE.TXT"
23 OPEN "I",#2,FILEI$
30 GOSUB  800 'Liste des commandes
40 GOSUB  100 'Set up des clefs
50 GoSub 1000 'Remplir l'image
60 GOSUB  300 'Afficher la liste des couleurs
70 GOSUB  500 'Colorier
99 CLOSE #1, #2 : END
100 REM --- Set up des clefs ---
110 ON KEY(11) GOSUB 10100:KEY(11) ON 'Cursor up
120 ON KEY(12) GOSUB 10200:KEY(12) ON 'Cursor left
130 ON KEY(13) GOSUB 10300:KEY(13) ON 'Cursor right
140 ON KEY(14) GOSUB 10400:KEY(14) ON 'Cursor down
199 RETURN
300 REM --- Afficher la liste des couleurs ---
301 LOCATE 3,65 : PRINT "0 -"
302 LOCATE 4,65 : PRINT "1 -"
303 LOCATE 5,65 : PRINT "2 -"
304 LOCATE 6,65 : PRINT "3 -"
305 LOCATE 7,65 : PRINT "4 -"
306 LOCATE 8,65 : PRINT "5 -"
307 LOCATE 9,65 : PRINT "6 -"
308 LOCATE 10,65 : PRINT "7 -"
309 LOCATE 11,65 : PRINT "8 -"
310 LOCATE 12,65 : PRINT "9 -"
311 LOCATE 13,65 : PRINT "A -"
312 LOCATE 14,65 : PRINT "B -"
313 LOCATE 15,65 : PRINT "C -"
314 LOCATE 16,65 : PRINT "D -"
315 LOCATE 17,65 : PRINT "E -"
316 LOCATE 18,65 : PRINT "F -"
320 FOR J = 0 TO 15   
321  LINE (545,J*14+29)-(595,J*14+39),J,BF
322 NEXT J
390 INPUT#2,P$,P1,P2
391 IF P$ = "X" THEN GOTO 399
392 IF P$ = "L" THEN PALETTE P1,P2
393 GOTO 390
399 RETURN
500 REM --- Colorier ---
510 K$ = INKEY$
520 IF K$ = ""       THEN GOTO 510
530 IF K$ = CHR$(27) THEN GOTO 599 'Escape pour terminer
540 GOSUB 600 'Appliquer la couleur
550 GOTO 510
599 RETURN
600 REM --- Appliquer la couleur ---
601 IF K$ = "0" THEN PAINT (P+X,Q+Y),0,0 : C = 0
602 IF K$ = "1" THEN PAINT (P+X,Q+Y),1,0 : C = 1
603 IF K$ = "2" THEN PAINT (P+X,Q+Y),2,0 : C = 2
604 IF K$ = "3" THEN PAINT (P+X,Q+Y),3,0 : C = 3
605 IF K$ = "4" THEN PAINT (P+X,Q+Y),4,0 : C = 4
606 IF K$ = "5" THEN PAINT (P+X,Q+Y),5,0 : C = 5
607 IF K$ = "6" THEN PAINT (P+X,Q+Y),6,0 : C = 6
608 IF K$ = "7" THEN PAINT (P+X,Q+Y),7,0 : C = 7
609 IF K$ = "8" THEN PAINT (P+X,Q+Y),8,0 : C = 8
610 IF K$ = "9" THEN PAINT (P+X,Q+Y),9,0 : C = 9
611 IF K$ = "a" THEN PAINT (P+X,Q+Y),10,0 : C = 10
612 IF K$ = "b" THEN PAINT (P+X,Q+Y),11,0 : C = 11
613 IF K$ = "c" THEN PAINT (P+X,Q+Y),12,0 : C = 12
614 IF K$ = "d" THEN PAINT (P+X,Q+Y),13,0 : C = 13
615 IF K$ = "e" THEN PAINT (P+X,Q+Y),14,0 : C = 14
616 IF K$ = "f" THEN PAINT (P+X,Q+Y),15,0 : C = 15
699 RETURN
800 REM --- Liste des commandes ---
810 PRINT " "
811 PRINT " Peser Escape pour terminer
812 PRINT " "
813 PRINT " Les 4 clefs pour diriger le curseur"
814 PRINT " "
815 PRINT " Peser de 1 a F pour le choix de la couleur"
816 PRINT " "
821 PRINT " Tappez F10 pour sortir d'un loop"
824 PRINT " "
830 PRINT " Pesez ENTER"
850 O$=INPUT$(1)
899 CLS : RETURN
1000 REM --- Recollage du dessin ---
1010 FOR J = 0 TO 300 STEP 50
1020  FOR I = 0 TO 576 STEP 64
1030    GOSUB 1100 : PUT (P+I,Q+J),M%,PSET
1040  NEXT I
1050 NEXT J
1099 RETURN
1100 REM --- Lire les donnees du dessin a partir d'un fichier ---
1110 FOR K = 0 TO 920
1120  INPUT#1,M%(K)
1130 NEXT K
1199 RETURN
10100 REM --- CURSOR UP ---
10110 KEY(11) STOP:KEY(12) STOP:KEY(13) STOP:KEY(14) STOP
10120 PSET (P+X,Q+Y),C
10121 Y = Y - 1
10122 C = POINT (P+X,Q+Y)
10123 PSET (P+X,Q+Y),4
10130 LOCATE 1,65 : PRINT X;Y
10190 KEY(11) ON:KEY(12) ON:KEY(13) ON:KEY(14) ON
10199 RETURN
10200 REM --- CURSOR LEFT ---
10210 KEY(11) STOP:KEY(12) STOP:KEY(13) STOP:KEY(14) STOP
10220 PSET (P+X,Q+Y),C
10221 X = X - 1
10222 C = POINT (P+X,Q+Y)
10223 PSET (P+X,Q+Y),4
10230 LOCATE 1,65 : PRINT X;Y
10290 KEY(11) ON:KEY(12) ON:KEY(13) ON:KEY(14) ON
10299 RETURN
10300 REM --- CURSOR RICHT ---
10310 KEY(11) STOP:KEY(12) STOP:KEY(13) STOP:KEY(14) STOP
10320 PSET (P+X,Q+Y),C
10321 X = X + 1
10322 C = POINT (P+X,Q+Y)
10323 PSET (P+X,Q+Y),4
10330 LOCATE 1,65 : PRINT X;Y
10390 KEY(11) ON:KEY(12) ON:KEY(13) ON:KEY(14) ON
10399 RETURN
10400 REM --- CURSOR DOWN ---
10410 KEY(11) STOP:KEY(12) STOP:KEY(13) STOP:KEY(14) STOP
10420 PSET (P+X,Q+Y),C
10421 Y = Y + 1
10422 C = POINT (P+X,Q+Y)
10423 PSET (P+X,Q+Y),4
10430 LOCATE 1,65 : PRINT X;Y
10490 KEY(11) ON:KEY(12) ON:KEY(13) ON:KEY(14) ON
10499 RETURN
