Skip to content

Instantly share code, notes, and snippets.

@rebolek
Created April 10, 2019 04:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rebolek/8f7520f01d3297507d724e6e2c99b6f2 to your computer and use it in GitHub Desktop.
Save rebolek/8f7520f01d3297507d724e6e2c99b6f2 to your computer and use it in GitHub Desktop.
Red[]
dist-to-color: func [dist][
to tuple! reduce [dist * 256 dist * 256 dist * 256]
]
distance: func [start end /local diff][
diff: end - start
absolute square-root diff/x * diff/x + (diff/y * diff/y)
]
map: func ['word series code][
; Leaks :word, but foreach leaks to
collect [
foreach :word series [
keep do code
]
]
]
get-distances: func [point points maximal][
sort collect [
foreach p points [keep (distance point p) / maximal]
]
]
make-image: func [][
size: 200x200
max-distance: 0.1 * distance 0x0 size
map: make image! size
peaks: collect [loop 100 [keep random size]]
repeat x size/x [
repeat y size/y [
diff: first get-distances as-pair x y peaks max-distance
map/(as-pair x y): dist-to-color max 0 1.0 - diff * 0.5
]
]
map
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment