Created
July 25, 2017 22:18
-
-
Save maximvl/f43ac42a83e1347c08da1758f91126b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [ | |
author: { Maxim Velesyuk } | |
description: { | |
colors palette showcase | |
} | |
] | |
sys-words: words-of system/words | |
colors: copy [] | |
forall sys-words [ | |
word: sys-words/1 | |
error: error? value: try [ get word ] | |
if all [ | |
not error | |
tuple? :value | |
value/1 < 255 | |
value/2 < 255 | |
value/3 < 255 | |
] [ | |
append colors word | |
] | |
] | |
tile-size: 4x3 * 30 | |
rows: 1 + to-integer round/ceiling sqrt length? colors | |
cols: to-integer (length? colors) / rows | |
color-complement: func [color /local c] [ | |
to-tuple reduce [255 - color/1 255 - color/2 255 - color/3] | |
] | |
size: to-pair reduce [tile-size/x * rows tile-size/y * cols] | |
draw-block: collect/into [ | |
repeat r rows [ | |
repeat c cols [ | |
index: r * cols + c | |
if index <= length? colors [ | |
tile-coords: tile-size * to-pair reduce [r - 1 c - 1] | |
color: pick colors index | |
keep compose [ | |
fill-pen (color) | |
box (tile-coords) | |
(tile-coords + tile-size) | |
pen (reverse get color) | |
text (tile-coords + 10) (to-string color) | |
pen (color-complement get color) | |
text (tile-coords + 10x30) (to-string color) | |
] | |
] | |
] | |
] | |
] copy [] | |
view compose [ | |
title "Colors showcase" | |
base (size) draw draw-block | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is /local c doing in color-complement function?
The bounds test are useless, tuple is 0 to 255 anyway, you will notice some extra colors too ;-)
(You can also decide to sort alphabetically.)
Make an extra color that will probably visible in case color = reverse color
and add also