#program nas10
  10 REM ==== NEXT-A-SKETCH ====
  20 REM J.Waterman 16-19 Jan'23
  30 REM An original Next not-a-
  40 REM   game for the CSSCGC!
  50 REM =======================
  51 REM 
  54 RUN AT 3
  55 v$="v1.0": z$="                                ": %p=182: %i=0: %t=173: %w=47: %e=255: px=128: py=96: mx=px: my=py
  56 DIM a$(8,2): DIM b$(4,2): PROC arrays()
  60 BORDER 2: LAYER 2,1: LAYER OVER 0: PROC paperpalette()
  64 REM ======== Initial screen
  65 LAYER 1,1: INK 0: BANK 5 ERASE 0,6144,255: BANK 5 ERASE 6144,768,%p 
  66 LAYER 2: PALETTE OVER %e: PAPER 182: INK 0: CLS 
  80 PROC titlescreen()
 100 POKE 23658,0: REPEAT :k$= INKEY$ : REPEAT UNTIL k$<>""
 110 IF k$="c" THEN PROC colours(): GO TO 64
 112 CLS 
 115 LAYER 1,1: INK 0: BANK 5 ERASE 0,6144,255: BANK 5 ERASE 6144,768,%p 
 120 LAYER 2: PALETTE OVER %t: PAPER %t: INK %i: CLS : %e=0: PLOT px,py
 128 REM ==== Let's go, Brandon!
 130 POKE 23658,0: REPEAT :k$= INKEY$ : REPEAT UNTIL k$<>""
 140 IF k$="q" OR k$="w" OR k$="e" OR k$="a" OR k$="d" OR k$="z" OR k$="x" OR k$="c" OR k$= CHR$ 8 OR k$= CHR$ 9 OR k$= CHR$ 10 OR k$= CHR$ 11 THEN PROC moveit()
 150 IF k$="i" THEN PROC inknum()
 160 IF k$="j" THEN PROC inkbits()
 170 IF k$="p" THEN PROC papernum()
 180 IF k$="l" THEN PROC paperbits()
 190 IF k$="0" OR k$="o" THEN PROC eraser()
 200 IF k$="s" THEN PROC viewxy()
 210 IF k$="m" THEN PROC movexy()
 220 IF k$="k" THEN PROC centrexy()
 230 IF k$="f" THEN PROC storexy()
 240 IF k$="r" THEN PROC recallxy()
 250 IF k$="v" THEN PROC wipe()
 260 IF k$="h" THEN PROC dcircle()
 270 IF k$="y" THEN PROC dsquare()
 280 IF k$="u" THEN PROC drectangle()
 290 IF k$="t" THEN PROC dtriangle()
 300 IF k$="b" THEN PROC dstar()
 310 IF k$="n" THEN PROC dcross()
 320 IF k$="g" THEN PROC dhexagon()
 330 IF k$="2" THEN PROC dline()
 340 IF k$="3" THEN PROC darc2()
 350 IF k$="4" THEN PROC text()
 360 IF k$="9" THEN PROC savescreen()
 370 IF k$="1" THEN PROC instruct()
 990 GO TO 128
 999 STOP 
1000 REM 
1010 DEFPROC winon()
1012 BANK 11 COPY TO %w: BANK 11 ERASE 0,16384,255: PAPER 255: INK 0
1014 ENDPROC 
1015 DEFPROC winoff()
1016 BANK %w COPY TO 11: PAPER %p: INK %i
1018 ENDPROC 
1020 DEFPROC stron()
1022 BANK 11 COPY TO %w: PAPER 255: INK 0: PRINT AT 22,0;z$;z$;
1025 ENDPROC 
1052 DEFPROC colours()
1054 LOCAL %q,e,p,i,t
1055 PRINT AT 17,0; PAPER 182;z$;z$;z$;z$;z$;z$;z$;
1060 REPEAT : INPUT AT 18,1;"Input paper colour:        ";%q: REPEAT UNTIL %q<=255: %p=%q: PRINT AT 18,28;%p;"   "
1062 REPEAT : INPUT AT 20,1;"Input ink colour:          ";%q: REPEAT UNTIL %q<=255: %i=%q: PRINT AT 20,28;%i;"   "
1065 REPEAT : INPUT AT 22,1;"Input transparency:        ";%q: REPEAT UNTIL %q<=255: %t=%q: PRINT AT 22,28;%t;"   "
1070 IF %t=p THEN PROC colourclash(): GO TO 1055
1072 e=%e: p=%p: i=%i: t=%t
1075 IF e=p OR e=i OR e=t THEN REPEAT : e= INT ( RND *256): REPEAT UNTIL (e<>p AND e<>i AND e<>t)
1080 %e=e
1099 ENDPROC 
1100 DEFPROC moveit()
1105 LOCAL dx,dy
1106 dx=0: dy=0
1110 dx=dx+((k$="e" OR k$="d" OR k$="c" OR k$= CHR$ 9) AND px<255)-((k$="q" OR k$="a" OR k$="z" OR k$= CHR$ 8) AND px>0)
1120 dy=dy+((k$="z" OR k$="x" OR k$="c" OR k$= CHR$ 10) AND py<191)-((k$="q" OR k$="w" OR k$="e" OR k$= CHR$ 11) AND py>0)
1130 px=px+dx: py=py+dy
1135 IF ( ABS dx+ ABS dy)>0 THEN PLOT px,py: BEEP .01,12
1140 ENDPROC 
1150 DEFPROC inknum()
1155 LOCAL %a
1160 PROC stron()
1170 REPEAT : PRINT POINT 0,180;z$;: INPUT POINT 16,180;"New INK colour (0-255): ";%a: REPEAT UNTIL %a<256
1175 %i=%a: INK %i: %e=0: PROC winoff()
1180 PLOT px,py: BEEP .01,12
1181 ENDPROC 
1182 DEFPROC inkbits()
1183 LOCAL r,g,b,%a
1184 PROC winon()
1185 PRINT AT 17,0;"New INK colour by levels:"
1186 REPEAT : INPUT AT 19,0; INK 0;"New "; INK 224;"RED"; INK 0;" level   (0-7): ";r: r= INT r: REPEAT UNTIL r<8: PRINT AT 19,27;"= #";a$(r+1)
1188 REPEAT : INPUT AT 20,0; INK 0;"New "; INK 16;"GREEN"; INK 0;" level (0-7): ";g: g= INT g: REPEAT UNTIL g<8: PRINT AT 20,27;"= #";a$(g+1)
1190 REPEAT : INPUT AT 21,0; INK 0;"New "; INK 3;"BLUE"; INK 0;" level  (0-3): ";b:b= INT b: REPEAT UNTIL b<4: PRINT AT 21,27;"= #";b$(b+1)
1192 %a=32*r+4*g+b
1195 PRINT AT 23,0;"New INK colour = ";%a;" (#";a$(r+1);a$(g+1);b$(b+1);")": PAUSE 100
1200 %i=%a: INK %i: %e=0: PROC winoff()
1202 PLOT px,py: BEEP .01,12
1203 ENDPROC 
1204 DEFPROC papernum()
1205 LOCAL %a
1210 PROC stron()
1220 REPEAT : PRINT POINT 0,180;z$;: INPUT POINT 8,180;"New PAPER colour (0-255): ";%a: REPEAT UNTIL %a<256
1225 IF %a=t THEN PROC colourclash(): PRINT AT 22,0;z$;z$;: GO TO 1220
1230 %p=%a: BANK 5 ERASE 6144,768,%p: PROC winoff()
1240 ENDPROC 
1250 DEFPROC paperbits()
1260 LOCAL r,g,b,%a
1284 PROC winon()
1285 PRINT AT 17,0;"New PAPER colour by levels:"
1286 REPEAT : INPUT AT 19,0; INK 0;"New "; INK 224;"RED"; INK 0;" level   (0-7): ";r: r= INT r: REPEAT UNTIL r<8: PRINT AT 19,27;"= #";a$(r+1)
1288 REPEAT : INPUT AT 20,0; INK 0;"New "; INK 16;"GREEN"; INK 0;" level (0-7): ";g: g= INT g: REPEAT UNTIL g<8: PRINT AT 20,27;"= #";a$(g+1)
1290 REPEAT : INPUT AT 21,0; INK 0;"New "; INK 3;"BLUE"; INK 0;" level  (0-3): ";b:b= INT b: REPEAT UNTIL b<4: PRINT AT 21,27;"= #";b$(b+1)
1292 %a=32*r+4*g+b
1295 IF %a=t THEN PRINT AT 17,0;z$;: PROC colourclash(): PRINT AT 18,0;z$;z$;z$;z$;z$;: GO TO 1285
1300 PRINT AT 23,0;"New PAPER colour = ";%a;" (#";a$(r+1);a$(g+1);b$(b+1);")": PAUSE 100
1302 %p=%a: BANK 5 ERASE 6144,768,%p: PROC winoff()
1305 ENDPROC 
1310 DEFPROC transnum()
1355 LOCAL %a
1360 PROC winon()
1370 REPEAT : INPUT AT 18,0;"New transparency (0-255): ";%a: REPEAT UNTIL %a<256
1380 %t=%a: PALETTE OVER %t: PROC winoff()
1381 ENDPROC 
1382 DEFPROC transbits()
1383 LOCAL r,g,b,%a
1384 PROC winon()
1385 PRINT AT 17,0;"New transparency by levels:"
1386 REPEAT : INPUT AT 19,0; INK 0;"New "; INK 224;"RED"; INK 0;" level   (0-7): ";r: r= INT r: REPEAT UNTIL r<8: PRINT AT 19,27;"= #";a$(r+1)
1388 REPEAT : INPUT AT 20,0; INK 0;"New "; INK 16;"GREEN"; INK 0;" level (0-7): ";g: g= INT g: REPEAT UNTIL g<8: PRINT AT 20,27;"= #";a$(g+1)
1390 REPEAT : INPUT AT 21,0; INK 0;"New "; INK 3;"BLUE"; INK 0;" level  (0-3): ";b:b= INT b: REPEAT UNTIL b<4: PRINT AT 21,27;"= #";b$(b+1)
1392 %a=32*r+4*g+b
1395 PRINT AT 23,0;"New transparency = ";%a;" (#";a$(r+1);a$(g+1);b$(b+1);")": PAUSE 100
1402 %t=%a: PALETTE OVER %t: PROC winoff()
1405 ENDPROC 
1410 DEFPROC eraser()
1420 PROC stron()
1430 IF %e=0 THEN PRINT POINT 60,180;"Ink eradicator ON"
1440 IF %e=1 THEN PRINT POINT 56,180;"Ink eradicator OFF"
1450 REPEAT : REPEAT UNTIL INKEY$ =""
1460 PAUSE 1: PAUSE 50: : PROC winoff()
1470 IF %e=0 THEN INK %t
1475 IF %e=1 THEN INK %i
1480 PLOT px,py: BEEP .01,12: %e=%e+1: IF %e=2 THEN %e=0
1488 ENDPROC 
1500 DEFPROC viewxy()
1510 PROC stron()
1520 PRINT POINT 48,176;"Current coordinates:"; POINT 60,184;"x = ";px; POINT 156-8*(py>9)-8*(py>99),184;"y = ";py
1530 PAUSE 1: PAUSE 66: PROC winoff()
1540 ENDPROC 
1550 DEFPROC movexy()
1555 LOCAL %x,%y
1560 PROC winon()
1570 PRINT POINT 48,136;"Current coordinates:"; POINT 60,144;"x = ";px; POINT 156-8*(py>9)-8*(py>99),144;"y = ";py
1580 PRINT AT 20,5;"Input new coordinates:"
1590 REPEAT : PRINT AT 21,9;"x (0-255):     ": INPUT AT 21,20;%x: REPEAT UNTIL %x<256 
1600 REPEAT : PRINT AT 22,9;"y (0-191):     ": INPUT AT 22,20;%y: REPEAT UNTIL %y<192 
1610 PAUSE 50: px=%x: py=%y: PROC winoff()
1615 PLOT px,py: BEEP .01,12
1620 ENDPROC 
1650 DEFPROC centrexy()
1660 PROC stron()
1665 px=128: py=96
1670 PRINT POINT 36,176;"Coordinates centred at:"; POINT 60,184;"x = ";px; POINT 156-8*(py>9)-8*(py>99),184;"y = ";py
1680 PAUSE 1: PAUSE 66: PROC winoff()
1685 PLOT px,py: BEEP .01,12
1690 ENDPROC 
1700 DEFPROC storexy()
1710 PROC stron()
1715 mx=px: my=py
1720 PRINT POINT 52,176;"Coordinates stored:"; POINT 60,184;"x = ";px; POINT 156-8*(py>9)-8*(py>99),184;"y = ";py
1730 PAUSE 1: PAUSE 66: PROC winoff()
1740 ENDPROC 
1750 DEFPROC recallxy()
1760 PROC stron()
1765 px=mx: py=my
1770 PRINT POINT 8,176;"Moved to recalled coordinates:"; POINT 60,184;"x = ";px; POINT 156-8*(py>9)-8*(py>99),184;"y = ";py
1780 PAUSE 1: PAUSE 66: PROC winoff()
1785 PLOT px,py: BEEP .01,12
1790 ENDPROC 
1800 DEFPROC wipe()
1805 LOCAL %n,k$
1808 PROC winon()
1810 PRINT POINT 12,144; PAPER 96; INK 240;" CLEAR SCREEN: ARE YOU SURE? ": FOR %n=1 TO 3: BEEP 2,-40: PAUSE 2: NEXT %n
1820 PRINT POINT 44,160;"Press "; INVERSE 1;"Y"; INVERSE 0;" to proceed or"'"   any other key to cancel..."
1830 REPEAT :k$= INKEY$ : REPEAT UNTIL k$<>""
1840 IF k$<>"y" THEN PROC winoff(): ENDPROC 
1850 FOR %n=9 TO 11: BANK %n ERASE 0,16384,%t: NEXT %n
1860 px=128: py=96: INK %i: PLOT px,py: BEEP .01,12
1870 ENDPROC 
2000 DEFPROC dcircle()
2010 LOCAL %x,%y,%q,%m,%r
2020 PROC winon()
2030 PRINT POINT 84,136;"DRAW CIRCLE"; POINT 28,152;"Input centre coordinates:"
2040 REPEAT : PRINT AT 20,1;"x (1-254):     ": INPUT AT 20,12;%x: REPEAT UNTIL %(x<255 AND x>0) 
2045 REPEAT : PRINT AT 20,17;"y (1-190):     ": INPUT AT 20,28;%y: REPEAT UNTIL %(y<191 AND y>0)
2050 IF %x<=y THEN %m=%x: ELSE %m=%y
2052 %q=%255-x: IF %q<m THEN %m=%q
2054 %q=%191-y: IF %q<m THEN %m=%q
2060 REPEAT : PRINT AT 22,2;"Input radius (max. ";%m;"):      ": INPUT AT 22,26;%r: REPEAT UNTIL %r<=m
2065 PROC winoff()
2070 PLOT %x-r,%y: BEEP .01,12: DRAW %2*r,0, PI 
2075 PLOT %x-r,%y: BEEP .01,12: DRAW %2*r,0, - PI : BEEP .01,12
2090 ENDPROC 
2100 DEFPROC dsquare()
2110 LOCAL %x,%y,%m,%q,%s
2120 PROC winon()
2130 PRINT POINT 84,136;"DRAW SQUARE"; POINT 20,152;"Input top left coordinates:"
2140 REPEAT : PRINT AT 20,1;"x (0-254):     ": INPUT AT 20,12;%x: REPEAT UNTIL %x<255 
2145 REPEAT : PRINT AT 20,17;"y (0-190):     ": INPUT AT 20,28;%y: REPEAT UNTIL %y<191
2150 %m=%256-x: %q=%192-y: IF %q<m THEN %m=%q
2160 REPEAT : PRINT AT 22,5;"Input side length:    "; POINT %68-(4*(m>9))-(4*(m>99)),184;"(min. 2, max. ";%m;")": INPUT AT 22,24;%s: REPEAT UNTIL %s<=m
2162 IF %s<2 THEN GO TO 2160
2165 PROC winoff()
2170 %s=%s-1: PLOT %x,%y: DRAW %s,0: DRAW 0,%s: DRAW % SGN {-s},0: DRAW 0,% SGN {-s}
2190 ENDPROC 
2200 DEFPROC drectangle()
2205 LOCAL %x,%y,%m,%q,%s,%h
2210 PROC winon()
2220 PRINT POINT 72,136;"DRAW RECTANGLE"; POINT 20,152;"Input top left coordinates:"
2230 REPEAT : PRINT AT 20,1;"x (0-254):     ": INPUT AT 20,12;%x: REPEAT UNTIL %x<255
2235 REPEAT : PRINT AT 20,17;"y (0-190):     ": INPUT AT 20,28;%y: REPEAT UNTIL %y<191
2240 %m=%256-x: %q=%192-y
2250 REPEAT : PRINT AT 21,8;"Input width:      "; POINT %68-(4*(m>9))-(4*(m>99)),176;"(min. 2, max. ";%m;")": INPUT AT 21,22;%s: REPEAT UNTIL %s<=m
2255 IF %s<2 THEN GO TO 2250
2260 REPEAT : PRINT AT 22,8;"Input height:      "; POINT %68-(4*(m>9))-(4*(m>99)),184;"(min. 2, max. ";%q;")": INPUT AT 22,22;%h: REPEAT UNTIL %h<=q
2262 IF %h<2 THEN GO TO 2260
2265 PROC winoff()
2270 %s=%s-1: %h=%h-1: PLOT %x,%y: DRAW %s,0: DRAW 0,%h: DRAW % SGN {-s},0: DRAW 0,% SGN {-h}
2290 ENDPROC 
2300 DEFPROC dtriangle()
2310 LOCAL k,%x,%y,%m,maxx,maxy,%s,dx,dy
2315 k=0.5* SQR 3
2320 PROC winon()
2330 PRINT POINT 28,136;"DRAW EQUILATERAL TRIANGLE"; POINT 36,152;"Input peak coordinates:"
2340 REPEAT : PRINT AT 20,1;"x (1-254):     ": INPUT AT 20,12;%x: REPEAT UNTIL %(x<255 AND x>0)
2345 REPEAT : PRINT AT 20,17;"y (0-190):     ": INPUT AT 20,28;%y: REPEAT UNTIL %y<191
2350 %m=%255-x: IF %x<=m THEN %m=%x
2355 maxx=%(2*m)+1
2360 maxy=%(192-y):maxy= INT (maxy/k)
2365 %m=maxx: IF maxy<maxx THEN %m=maxy
2370 REPEAT : PRINT AT 22,5;"Input side length:    "; POINT %68-(4*(m>9))-(4*(m>99)),184;"(min. 3, max. ";%m;")": INPUT AT 22,24;%s: REPEAT UNTIL %s<=m
2375 IF %s<3 THEN GO TO 2370
2380 dy=%s:dy= INT (0.5+(dy*k))
2390 PROC winoff()
2400 IF %m MOD 2=1 THEN dx=%s-1:dx=dx/2: PLOT %x,%y: BEEP .01,12: DRAW -dx,dy: BEEP .01,12: DRAW %s-1,0: BEEP .01,12: PLOT %x,%y: DRAW dx,dy: BEEP .01,12
2410 IF %m MOD 2=0 THEN dx=%s:dx=dx/2: PLOT %x,%y: BEEP .01,12: DRAW -dx,dy: BEEP .01,12: DRAW %s,0: BEEP .01,12: PLOT %x+1,%y: DRAW dx,dy: BEEP .01,12
2420 ENDPROC 
2430 DEFPROC dstar()
2440 LOCAL %x,%y,my,mx,lx,ly,%m,%s,x,y,l,dx1,dy1,dx2,dy2,fy
2450 PROC winon()
2460 PRINT POINT 40,136;"DRAW FIVE-POINTED STAR"; POINT 36,152;"Input peak coordinates:"
2470 REPEAT : PRINT AT 20,1;"x (2-253):     ": INPUT AT 20,12;%x: REPEAT UNTIL %(x<254 AND x>0)
2472 IF %x<2 THEN GO TO 2470
2475 REPEAT : PRINT AT 20,17;"y (0-189):     ": INPUT AT 20,28;%y: REPEAT UNTIL %y<190
2480 my=%191-y:mx=%x: IF %255-x<x THEN mx=%255-x
2490 lx=mx/(1+ COS (0.4* PI )): ly=my/(2* SIN (0.4* PI )+ SIN (0.2* PI ))
2500 %m=% INT {lx}: IF ly<lx THEN %m=% INT {ly}
2510 REPEAT : PRINT AT 22,5;"Input side length:    "; POINT %68-(4*(m>9))-(4*(m>99)),184;"(min. 2, max. ";%m;")": INPUT AT 22,24;%s: REPEAT UNTIL %s<=m
2515 IF %s<2 THEN GO TO 2510
2520 l=%s: l=l-.5: dx1=l* COS (0.4* PI ): dy1=l* SIN (0.4* PI ): dx2=l* COS (0.2* PI ): dy2=l* SIN (0.2* PI ): x=%x: y=%y: fx=%x: fy=%y: fy=fy+2*dy1
2530 PROC winoff()
2540 PLOT x,y: BEEP .01,12: DRAW -dx1,dy1: BEEP .01,12
2550 x=x-dx1: y=y+dy1: PLOT x,y: DRAW 0.5-l,0: BEEP .01,12: DRAW dx2,dy2: BEEP .01,12
2560 x=x+0.5-l+dx2: y=y+dy2: PLOT x,y: DRAW -dx1,dy1: BEEP .01,12
2570 x=x-dx1: y=y+dy1: PLOT x,y: DRAW fx-x,fy-y: BEEP .01,12
2580 x=%x: y=%y: PLOT x,y: DRAW dx1,dy1: BEEP .01,12
2590 x=x+dx1: y=y+dy1: PLOT x,y: DRAW l-0.5,0: BEEP .01,12: DRAW -dx2,dy2: BEEP .01,12
2600 x=x+l-0.5-dx2: y=y+dy2: PLOT x,y: DRAW dx1,dy1: BEEP .01,12
2610 x=x+dx1: y=y+dy1: PLOT x,y: DRAW fx-x,fy-y: BEEP .01,12
2690 ENDPROC 
2700 DEFPROC dcross()
2705 LOCAL %x,%y,%m,%q,%s,%n
2710 PROC winon()
2720 PRINT AT 17,4;"DRAW REGULAR GREEK CROSS"; POINT 8,148;"Input starting coordinates >": PLOT 217,152: DRAW 11,0
2725 %s=8: PLOT 232,152: DRAW %s,0: DRAW 0,%s: DRAW %s,0: DRAW 0,%s: DRAW % SGN {-s},0: DRAW 0,%s: DRAW % SGN {-s},0: DRAW 0,% SGN {-s}: DRAW % SGN {-s},0: DRAW 0,% SGN {-s}: DRAW %s,0: DRAW 0,% SGN {-s}: PLOT INK 224;232,152
2730 REPEAT : PRINT POINT 8,156;"x (1-253):     ": INPUT POINT 96,156;%x: REPEAT UNTIL %x<254 
2732 IF %x<1 THEN GO TO 2730
2735 REPEAT : PRINT POINT 8,164;"y (0-188):     ": INPUT POINT 96,164;%y: REPEAT UNTIL %y<189
2740 %m=%x+1: IF %(128-(x>>1))<m THEN %m=%128-(x>>1)
2745 %q=%64-(z/3): IF %q<m THEN %m=%q
2750 REPEAT : PRINT AT 22,5;"Input side length:    "; POINT %68-(4*(m>9))-(4*(m>99)),184;"(min. 2, max. ";%m;")": INPUT AT 22,24;%s: REPEAT UNTIL %s<=m
2755 IF %s<2 THEN GO TO 2750
2760 PROC winoff()
2770 %s=%s-1: PLOT %x,%y: BEEP .01,12: FOR %n=1 TO 2: DRAW %s,0: BEEP .01,12: DRAW 0,%s: BEEP .01,12: NEXT %n
2775 DRAW % SGN {-s},0: BEEP .01,12: DRAW 0,%s: BEEP .01,12: DRAW % SGN {-s},0: BEEP .01,12: DRAW 0,% SGN {-s}: BEEP .01,12
2780 DRAW % SGN {-s},0: BEEP .01,12: DRAW 0,% SGN {-s}: BEEP .01,12: DRAW %s,0: BEEP .01,12: DRAW 0,% SGN {-s}: BEEP .01,12
2790 ENDPROC 
2900 DEFPROC dhexagon()
2905 LOCAL sl,cl,%x,%y,%m,maxx,maxy,%s,l,dx,dy
2910 sl= SIN ( PI /3): cl= COS ( PI /3): PROC winon()
2920 PRINT POINT 48,136;"DRAW REGULAR HEXAGON"; POINT 36,152;"Input peak coordinates:"
2930 REPEAT : PRINT AT 20,1;"x (1-254):     ": INPUT AT 20,12;%x: REPEAT UNTIL %(x<255 AND x>0)
2935 REPEAT : PRINT AT 20,17;"y (0-188):     ": INPUT AT 20,28;%y: REPEAT UNTIL %y<189
2940 %m=%255-x: IF %x<=m THEN %m=%x
2945 maxx=%m: maxx=maxx/sl
2950 maxy=%(192-y):maxy=maxy/(1+2*cl)
2955 %m=maxx: IF maxy<maxx THEN %m=maxy
2956 IF %m<2 THEN %m=2
2960 REPEAT : PRINT AT 22,5;"Input side length:    "; POINT %68-(4*(m>9))-(4*(m>99)),184;"(min. 2, max. ";%m;")": INPUT AT 22,24;%s: REPEAT UNTIL %s<=m
2965 IF %s<2 THEN GO TO 2960
2970 l=%s: l=l-0: dx= INT (l*sl): dy= INT (l*cl)
2975 PROC winoff()
2980 PLOT %x,%y: BEEP .01,12: DRAW -dx,dy: BEEP .01,12: DRAW 0,%s-1: BEEP .01,12: DRAW dx,dy: BEEP .01,12
2985 PLOT %x,%y: DRAW dx,dy: BEEP .01,12: DRAW 0,%s-1: BEEP .01,12: DRAW -dx,dy: BEEP .01,12
2990 ENDPROC 
3000 DEFPROC dline()
3005 LOCAL %x,%y,%u,%v
3010 PROC winon()
3020 PRINT POINT 92,136;"DRAW LINE"; POINT 32,152;"Input start coordinates:"
3030 REPEAT : PRINT AT 20,1;"x (0-255):     ": INPUT AT 20,12;%x: REPEAT UNTIL %x<256
3035 REPEAT : PRINT AT 20,17;"y (0-191):     ": INPUT AT 20,28;%y: REPEAT UNTIL %y<192
3040 PRINT POINT 40,168;"Input end coordinates:"
3050 REPEAT : PRINT AT 22,1;"x (0-255):     ": INPUT AT 22,12;%u: REPEAT UNTIL %u<256
3055 REPEAT : PRINT AT 22,17;"y (0-191):     ": INPUT AT 22,28;%v: REPEAT UNTIL %v<192
3060 PROC winoff()
3070 PLOT %x,%y: BEEP .01,12: DRAW %u-x,%v-y: BEEP .01,12
3080 ENDPROC 
3100 DEFPROC darc()
3105 LOCAL %x,%y,%u,%v,q,q$,%a,d,r
3110 PROC winon()
3120 PRINT POINT 96,136;"DRAW ARC"; POINT 32,152;"Input start coordinates:"
3130 REPEAT : PRINT AT 20,1;"x (0-255):     ": INPUT AT 20,12;%x: REPEAT UNTIL %x<256
3135 REPEAT : PRINT AT 20,17;"y (0-191):     ": INPUT AT 20,28;%y: REPEAT UNTIL %y<192
3140 PRINT POINT 40,168;"Input end coordinates:"
3150 REPEAT : PRINT AT 22,1;"x (0-255):     ": INPUT AT 22,12;%u: REPEAT UNTIL %u<256
3155 REPEAT : PRINT AT 22,17;"y (0-191):     ": INPUT AT 22,28;%v: REPEAT UNTIL %v<192
3160 q=%x: q$="("+ STR$ q: q=%y: q$=q$+","+ STR$ q: q=%u: q$=q$+") - ("+ STR$ q: q=%v:q$=q$+","+ STR$ q+")": %a= LEN q$
3170 PRINT AT 19,0;z$;z$;z$;z$; POINT %128-(a<<2),144;q$; AT 20,0;"Input degrees of curvature: "'"   (positive = clockwise,"'"    negative = anticlockwise)"
3175 REPEAT : PRINT AT 20,27;"     ": INPUT AT 20,28;d: REPEAT UNTIL (d>=-360 AND d<=360)
3180 PROC winoff()
3185 r= PI *(d/180): PLOT %x,%y: BEEP .01,12: DRAW %u-x,%v-y,r: BEEP .01,12
3190 ENDPROC 
3200 DEFPROC darc2()
3205 LOCAL x,%x,y,%y,%f,xr,dx,yr,dy,%m,%r,r,q$,ad,ar,ax,ay,as,af,a1,a2,xs,ys,xf,yf,a3
3210 PROC winon()
3220 PRINT POINT 96,136;"DRAW ARC"; POINT 32,152;"Input centre coordinates:"
3230 REPEAT : PRINT AT 20,1;"x (0-255):     ": INPUT AT 20,12;%x: REPEAT UNTIL x<256: x=%x 
3235 REPEAT : PRINT AT 20,17;"y (0-191):     ": INPUT AT 20,28;%y: REPEAT UNTIL %y<191: y=%y
3240 xr=255-x: dx=xr: IF x>xr THEN xr=x 
3245 yr=191-y: dy=yr: IF y>yr THEN yr=y 
3250 %m=xr: IF yr>xr THEN %m=yr
3260 REPEAT : PRINT AT 22,2;"Input radius (max. ";%m;"):      ": INPUT AT 22,27;%r: REPEAT UNTIL %r<=m: r=%r
3265 PRINT AT 18,0;z$;z$;z$;z$;z$;z$;: q$="Centre: ("+ STR$ x+","+ STR$ y+")  Radius: "+ STR$ r: PRINT POINT 128-4* LEN q$,144;q$
3270 IF (r<x AND r<dx AND r<y AND r<dy) THEN as=0: af=360: GO TO 3600 
3280 PRINT POINT 20,160;"Calculating angle limits..."
3290 IF x>127 THEN GO TO 3410
3310 ad=-1: REPEAT : ad=ad+1: ar=(ad* PI )/180: ax=x+r* COS ar: ay=y-r* SIN ar: REPEAT UNTIL (ax<0 OR ax>256 OR ay<0 OR ay>191): as=90-ad
3320 ad=-1: REPEAT : ad=ad+1: ar=(ad* PI )/180: ax=x+r* COS ar: ay=y+r* SIN ar: REPEAT UNTIL (ax<0 OR ax>256 OR ay<0 OR ay>191): af=90+ad
3335 IF af<0 THEN af=af+360
3399 GO TO 3600
3410 ad=-1: REPEAT : ad=ad+1: ar=(ad* PI )/180: ax=x-r* COS ar: ay=y+r* SIN ar: REPEAT UNTIL (ax<0 OR ax>256 OR ay<0 OR ay>191): as=270-ad
3420 ad=-1: REPEAT : ad=ad+1: ar=(ad* PI )/180: ax=x-r* COS ar: ay=y-r* SIN ar: REPEAT UNTIL (ax<0 OR ax>256 OR ay<0 OR ay>191): af=270+ad
3500 REPEAT 
3510 IF as<0 THEN as=as+360
3520 IF af<0 THEN af=af+360
3530 IF as>=360 THEN as=as-360
3540 IF af>=360 THEN af=af-360
3550 REPEAT UNTIL (as>=0 AND as<360 AND af>=0 AND af<360) 
3600 PRINT AT 20,0;z$; POINT 40,156;"Available angle range:"; POINT 36-4*((as>9)+(as>99)+(af>9)+(af>99)),164;"clockwise from ";as;" to ";af;""
3610 PRINT AT 22,5;"Input start angle:     ": INPUT AT 22,24;a1
3620 IF af<as THEN IF (a1<0 OR (a1>af AND a1<as) OR a1>359) THEN GO TO 3610
3630 IF af>as THEN IF (a1<as OR a1>af) THEN GO TO 3610
3640 PRINT AT 23,5;"Input final angle:     ": INPUT AT 23,24;a2
3650 IF af<as THEN IF (a2<0 OR (a2>af AND a2<as) OR a2>359) THEN GO TO 3640
3660 IF af>as THEN IF (a2<as OR a2>af) THEN GO TO 3640
3670 IF a2<a1 THEN a2=a2+360
3680 a1=(a1* PI )/180: a2=(a2* PI )/180
3700 xs=x+r* SIN a1: ys=y-r* COS a1: xf=x+r* SIN a2: yf=y-r* COS a2: a3=a2-a1
3710 PROC winoff()
3720 PLOT xs,ys: BEEP .01,12: DRAW xf-xs,yf-ys,a3: BEEP .01,12
3730 ENDPROC 
3800 DEFPROC text()
3805 LOCAL t$,t,cmax,%c,ci,ch,cw,%q,%x,%y
3810 PROC winon()
3820 REPEAT : PRINT AT 17,0;z$;z$;z$;z$;z$;z$;z$; AT 17,0;"Enter text (max. 85 characters):"
3830 INPUT AT 18,0; LINE t$: t= LEN t$: REPEAT UNTIL t<=85
3840 cmax=8: cmax=cmax-(t>32)-(t>36)-(t>42)-(t>51)-(t>64)
3845 PRINT AT 17,0;z$;z$;z$;z$;z$;z$;z$;
3850 IF cmax>3 THEN REPEAT : PRINT AT 17,0;z$; AT 17,1;"Input character width (3-";cmax;"): ": INPUT AT 17,30;%c: ci=%c: REPEAT UNTIL (ci>2 AND ci<=cmax): ELSE ci=3
3855 REPEAT : PRINT AT 18,0;z$;z$;z$; POINT 24,148;"Input character height:"'"    (1 = single, 2 = double)": INPUT POINT 224,148;%c: ch=%c: REPEAT UNTIL (ch>0 AND ch<3)
3860 cw=ci*t: PRINT AT 21,0;z$;z$; AT 21,4;"Input POINT coordinates:"
3865 %q=256-cw: REPEAT : PRINT AT 22,1;"x (0-";%q;"):     ": INPUT AT 22,12;%x: REPEAT UNTIL %x<=q 
3870 %q=184-8*(ch=2): REPEAT : PRINT AT 22,17;"y (0-";%q;"):     ": INPUT AT 22,28;%y: REPEAT UNTIL %y<=q
3875 PROC winoff()
3880 ch=ch-1: PRINT CHR$ 30; CHR$ ci; CHR$ 29; CHR$ ch; POINT %x,%y; PAPER %t;t$; CHR$ 30; CHR$ 8; CHR$ 29; CHR$ 0;
3890 ENDPROC 
4000 DEFPROC savescreen()
4005 LOCAL %n,k$,%y,%a
4010 FOR %n=9 TO 11: BANK %n COPY TO %(n+31): BANK %n COPY TO %(n+34): NEXT %n
4020 PROC winon()
4030 PRINT POINT 84,136;"SAVE SCREEN"; POINT 16,148;"It will take "; PAPER 96; INK 240;"FIVE MINUTES"; INK 0; PAPER 255;" to"; POINT 4,156;"merge the layers before saving!"; AT 21,5;"Press "; INVERSE 1;"Y"; INVERSE 0;" to go ahead or"'"    any other key to cancel."
4040 POKE 23658,0: REPEAT : k$= INKEY$ : REPEAT UNTIL k$<>""
4050 IF k$<>"y" THEN PAUSE 1: GO TO 4330
4100 PRINT AT 17,0;z$;z$;z$;z$;z$;z$;z$; AT 17,8;"Input file name:"
4110 POKE 23658,8: REPEAT : PRINT AT 18,8;"""        ""  .SL2";z$;: INPUT AT 18,9; LINE k$: REPEAT UNTIL LEN k$<=8: POKE 23658,0: k$=k$+".SL2" 
4200 FOR %n=9 TO 11
4210 %y=%n+34
4220 PRINT AT %n+11,1;"BANK ";%n; AT %n+11,9;"bytes remaining: "
4230 FOR %a=16383 TO 0 STEP -1
4240 IF % BANK y PEEK a=t THEN BANK %y POKE %a,%p
4250 PRINT AT %n+11,26;%a;" ";
4260 NEXT %a: NEXT %n
4270 PROC winoff()
4280 FOR %n=9 TO 11: BANK %(n+34) COPY TO %n: NEXT %n
4290 SAVE k$ LAYER 
4300 FOR %n=9 TO 11: BANK %(n+31) COPY TO %n: NEXT %n
4310 PROC stron()
4320 PRINT POINT 92-4* LEN k$,180;k$;" saved OK": PAUSE 1: PAUSE 66
4330 PROC winoff()
4390 ENDPROC 
6000 DEFPROC instruct()
6005 LOCAL q$,n,%r,%c
6030 LAYER OVER 2: LAYER 1,2: PALETTE CLEAR : CLS 
6040 PRINT INVERSE 1; AT 0,0;z$;z$; AT 5,0;z$;z$; AT 10,0;z$;z$; AT 15,0;z$;z$; AT 20,0;z$;z$;
6050 PRINT INVERSE 1; AT 0,0;"DIRECTIONAL CONTROLS"; AT 5,0;"COLOUR CONTROLS"; AT 10,0;"POSITION CONTROLS"; AT 15,0;"GEOMETRIC SHAPES"; AT 20,0;"ANYTHING ELSE";
6060 PRINT AT 1,12;"Use the eight keys around S to draw in the eight"' TAB 12;"compass directions. The cursor keys will also draw"' TAB 12;"in the four straight directions."
6070 PRINT AT 6,2;"= input new INK as a direct value, or   by RGB levels."'"  = input new PAPER as a direct value, or   by RGB levels."'"  or   = switch ink eradicator on or off."
6080 PRINT AT 11,2;"= view current coordinates.       = move to new coordinates."'"  = store current coordinates.      = recall stored coordinates."'"  = move to the centre of the screen."
6090 PRINT AT 16,2;"= draw circle.      = draw square.      = draw rectangle."'"  = draw equilateral triangle.      = draw five-pointed star."'"  = draw cross.       = draw regular hexagon."
6100 PRINT AT 21,2;"= draw a line.          = draw an arc."'"  = save the screen.      = clear the screen."'"  = view these instructions.";
6110 q$="QWEADZXCIJPLO0SMFRKHYUTBNG239V1": RESTORE 6130
6120 FOR n=1 TO 31: READ %r,%c: PRINT AT %r,%c; INVERSE 1;q$(n);: NEXT n
6130 DATA 1,0,1,4,1,8,2,0,2,8,3,0,3,4,3,8
6131 DATA 6,0,6,40,7,0,7,42,8,0,8,5
6132 DATA 11,0,11,34,12,0,12,34,13,0
6133 DATA 16,0,16,20,16,40,17,0,17,34,18,0,18,20
6134 DATA 21,0,21,24,22,0,22,24,23,0
6160 PRINT AT 23,41; INVERSE 1;" PRESS ENTER TO RETURN ";
6170 PAUSE 1: REPEAT : REPEAT UNTIL INKEY$ <>""
6180 PROC paperpalette()
6190 LAYER OVER 0: LAYER 1,1: BANK 5 ERASE 0,6144,255: BANK 5 ERASE 6144,768,%p
6200 LAYER 2: PALETTE OVER %t
6290 ENDPROC 
7000 DEFPROC titlescreen()
7010 LOCAL %r,r,%g,g,%b,b,%a,p$,i$,t$
7020 PRINT PAPER 240; AT 0,0; PAPER 240;z$;z$; CHR$ 29; CHR$ 1; POINT 76,0;"NEXT-A-SKETCH"; CHR$ 29; CHR$ 0; CHR$ 30; CHR$ 5; AT 1,47;v$; CHR$ 30; CHR$ 8;
7030 PRINT POINT 72,33;"______________"; AT 4,9;"Default values"; AT 7,4;"PAPER = "; AT 7,18;"INK = "; AT 14,4;"Transparency = ";%t; POINT 24,136;"NOTE that the transparency"; POINT 28,144;"is fixed when the program"; POINT 32,152;"starts, so get it right!"
7040 PRINT AT 7,%14-(p>9)-(p>99);%p; AT 7,%26-(i>9)-(i>99);%i
7050 %r=%p>>5: %g=%(p&28)>>2: %b=%p&3: r=%r: g=%g: b=%b: PRINT AT 8,5;"(#";a$(r+1);a$(g+1);b$(b+1);")"
7060 %r=%i>>5: %g=%(i&28)>>2: %b=%i&3: r=%r: g=%g: b=%b: PRINT AT 8,18;"(#";a$(r+1);a$(g+1);b$(b+1);")"
7070 %r=%t>>5: %g=%(t&28)>>2: %b=%t&3: r=%r: g=%g: b=%b: PRINT AT 15,14;"(#";a$(r+1);a$(g+1);b$(b+1);")"
7080 y$=z$( TO 11): PRINT PAPER %p; AT 10,4;y$; AT 11,4;y$; PAPER %i; AT 10,17;y$; AT 11,17;y$; PAPER %t; AT 14,24;"    "; AT 15,24;"    "
7090 PLOT 31,79: DRAW 89,0: DRAW 0,17: DRAW -89,0: DRAW 0,-17
7100 PLOT 135,79: DRAW 89,0: DRAW 0,17: DRAW -89,0: DRAW 0,-17
7110 PLOT 191,111: DRAW 33,0: DRAW 0,17: DRAW -33,0: DRAW 0,-17
7120 PRINT PAPER 240; AT 21,0;z$;z$;z$; POINT 8,172;"Press "; INVERSE 1;"C"; INVERSE 0;" to change these values"; POINT 28,180;"or any other key to start"
7130 ENDPROC 
7190 DEFPROC colourclash()
7200 PRINT AT 18,0;z$;z$;z$;z$;z$; AT 18,12; PAPER 96; INK 240;" ERROR! ": BEEP 8/3,-40
7210 PRINT AT 20,3;"The transparency cannot be"; POINT 12,168;"the same as the paper colour."; AT 22,11;"Try again!": PAUSE 100
7290 ENDPROC 
8010 DEFPROC paperpalette()
8015 LOCAL %n
8020 FOR %n=0 TO 255: BANK 46 POKE %n,%n: NEXT %n
8030 LAYER 1,1: PALETTE DIM 8: LAYER PALETTE 0 BANK 46,0: PALETTE FORMAT 255: REG 74,160
8040 ENDPROC 
8050 DEFPROC arrays()
8060 LOCAL n,%q
8070 RESTORE 8100
8080 FOR n=1 TO 8: READ a$(n): NEXT n
8090 FOR n=1 TO 4: READ b$(n): NEXT n
8100 DATA "00","24","49","6D","92","B6","DB","FF","00","6D","B6","FF"
8110 FOR n=0 TO 7: READ %q: POKE USR "o"+n,%q: NEXT n 
8120 DATA 48,72,72,48,0,0,0,0
8190 ENDPROC 
9000 DEFPROC message()
9010 PRINT AT 0,0;"SCHWING!"
9020 ENDPROC 
