Skip to content

Instantly share code, notes, and snippets.

@maximvl
Created July 25, 2017 22:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maximvl/f43ac42a83e1347c08da1758f91126b2 to your computer and use it in GitHub Desktop.
Save maximvl/f43ac42a83e1347c08da1758f91126b2 to your computer and use it in GitHub Desktop.
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
]
@iArnold
Copy link

iArnold commented Jul 26, 2017

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

color-shift: function [color][
    to-tuple reduce [(color/1 + 128) // 256 (color/2 + 128) // 256 (color/3 + 128) // 256]
]

and add also

               pen (color-shift get color)
               text (tile-coords + 10x60) (to-string color)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment