More Functional Color Chart
Author |
Message |
Euphoracle
|
Posted: Tue Jan 12, 2010 8:47 pm Post subject: More Functional Color Chart |
|
|
Turing: | setscreen ("graphics:800;400")
setscreen ("offscreenonly")
proc drawthickbox
(x1, y1, x2, y2, thickness, c : int)
for i : 0 .. thickness - 1
drawbox
(x1 - i,
y1 + i,
x2 + i,
y2 - i,
c )
end for
end drawthickbox
proc drawcolorchart
(ox, oy,
size, max_x : int)
var per_row := max_x div size
for i : 1 .. 255
var x := ox + ((i mod per_row )) * size
var y := oy - ((i div per_row ) + 1) * size
drawfillbox (x, y, x + size, y + size, i )
end for
drawthickbox
(ox,
oy,
ox + (per_row * size ),
oy - (ceil (255 / per_row ) * size ),
3,
black)
end drawcolorchart
fcn getcolornumber (ox, oy, size, max_x, x_, y_ : int) : int
var x := x_ - ox
var y := oy - y_
var per_row := max_x div size
var c :=
(per_row * (y div size )) +
(x div size )
result c
end getcolornumber
var mx, my, mb := 0
var c := 0
var s := ""
var font := Font.New ("Tahoma:16")
drawcolorchart (8, maxy - 8, 32, maxx - 8)
View.Update
loop
locate (maxrow - 5, 1)
Mouse.Where (mx, my, mb )
c := getcolornumber (8, maxy - 8, 32, maxx - 8, mx, my )
if (c < 0 or c > 255) then
s := "invalid"
else
s := intstr (c )
end if
drawfillbox(0, 0, maxx, 32, white)
Font.Draw ("Color Number: " + s, 8, 8, font, black)
Time.DelaySinceLast (20)
View.UpdateArea (0, 0, maxx, 32)
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
mirhagk
|
Posted: Mon Jan 18, 2010 10:32 am Post subject: RE:More Functional Color Chart |
|
|
nice piece of code. Personally I just use the much shorter versions cuz it's not that big of a deal, but I like the mouse hover over colour idea. Maybe you could make it put the colour number at the mouse position (like windows help things). I remember using a shorter version of this code to select a colour in a paint program I made, I can't find the code though. |
|
|
|
|
|
|
|