Author Topic: Colour Sorting  (Read 1886 times)

0 Members and 1 Guest are viewing this topic.

Offline bikemadness

  • Amiga 1200
  • ****
  • Posts: 322
  • Karma: 25
  • Hard players don't go home.
    • View Profile
Colour Sorting
« on: November 02, 2021 »
A selection of colours sorted by various orders.

D-Pad L/R to select order.

D-Pad U/D to move highlight.

Code: [Select]
open window 640,512
restore rainbow
read paint
dim Rcol(paint)
dim Gcol(paint)
dim Bcol(paint)
dim num(paint)
dim Col$(paint)
dim order$(paint)

for a=1 to paint
read Rcol(a)
read Gcol(a)
read Bcol(a)
read num(a)
read Col$(a)
next a

sel=1
col=1

repeat
setdispbuf vm
vm=1-vm
setdrawbuf vm
clear window
c=peek("port1")

if and(c,16)<>0 up=1
if up=1 U=U+1
if U>2 U=2
if U=2 up=0
if and(c,16)=0 U=0

if and(c,64)<>0 down=1
if down=1 D=D+1
if D>2 D=2
if D=2 down=0
if and(c,64)=0 D=0

if up=1 sel=sel-1
if down=1 sel=sel+1
if sel<1 sel=1
if sel>paint sel=paint

if and(c,128)<>0 left=1
if left=1 L=L+1
if L>2 L=2
if L=2 left=0
if and(c,128)=0 L=0

if and(c,32)<>0 right=1
if right=1 R=R+1
if R>2 R=2
if R=2 right=0
if and(c,32)=0 R=0

if left=1 col=col-1
if right=1 col=col+1
if col<1 col=1
if col>5 col=5

if col=1 text 400,250,"alphabetical order"
if col=2 text 400,250,"word size order"
if col=3 text 400,250,"numerical by red"
if col=4 text 400,250,"numerical by green"
if col=5 text 400,250,"numerical by blue"

setrgb 1,200,200,200
fill rectangle 65,4 to 210,507

for a=1 to paint
if col=1 order$(a)=Col$(a)
if col=2 order$(a)=str$(num(a))
if col=3 order$(a)=str$(Rcol(a)+100)
if col=4 order$(a)=str$(Gcol(a)+100)
if col=5 order$(a)=str$(Bcol(a)+100)
next a

for K=1 to paint-1
for J=1 to paint-K

if order$(J)>order$(J+1) then

temp=Rcol(J)
Rcol(J)=Rcol(J+1)
Rcol(J+1)=temp

temp=Gcol(J)
Gcol(J)=Gcol(J+1)
Gcol(J+1)=temp

temp=Bcol(J)
Bcol(J)=Bcol(J+1)
Bcol(J+1)=temp

temp=num(J)
num(J)=num(J+1)
num(J+1)=temp

temp$=Col$(J)
Col$(J)=Col$(J+1)
Col$(J+1)=temp$

temp$=order$(J)
order$(J)=order$(J+1)
order$(J+1)=temp$

endif

next J
next K

for a=1 to paint
setrgb 1,56,56,56
text 160-(len(Col$(a))*10),a*14.7+3,Col$(a)
setrgb 1,Rcol(a),Gcol(a),Bcol(a)
fill rectangle 170,14.7*a+5 to 200,14.7*a-5
next a
setrgb 1,256,256,256

for a=1 to paint
if sel=a then
setrgb 1,0,256,0
else
setrgb 1,256,256,256
endif
text 240,a*14.7+3,str$(Rcol(a))
text 280,a*14.7+3,str$(Gcol(a))
text 320,a*14.7+3,str$(Bcol(a))
next a

until (1=0)

label rainbow
data 34
data 256,000,000,3,"red"
data 256,104,031,6,"orange"
data 256,256,000,6,"yellow"
data 000,256,000,5,"green"
data 000,000,256,4,"blue"
data 079,105,198,6,"indigo"
data 036,010,064,6,"violet"
data 255,192,203,4,"pink"
data 000,000,000,5,"black"
data 256,256,256,5,"white"
data 235,147,115,7,"apricot"
data 049,091,161,5,"azure"
data 063,033,009,6,"bronze"
data 150,075,000,5,"brown"
data 224,192,149,6,"calico"
data 118,215,234,8,"sky blue"
data 002,164,211,8,"cerulean"
data 256,203,164,5,"flesh"
data 255,215,000,4,"gold"
data 128,128,128,4,"grey"
data 000,168,107,4,"jade"
data 240,230,140,5,"khaki"
data 191,256,000,4,"lime"
data 200,162,200,5,"lilac"
data 181,126,220,8,"lavender"
data 128,000,000,6,"maroon"
data 128,128,000,5,"olive"
data 204,119,034,5,"ochre"
data 102,000,153,6,"purple"
data 256,036,000,7,"scarlet"
data 112,066,020,5,"sepia"
data 210,180,140,3,"tan"
data 000,128,128,4,"teal"
data 048,213,200,9,"turquoise"

Have a Yahappy day.
I don't know what is wrong with the world - but I know how to fix it.