Skip to content

Instantly share code, notes, and snippets.

@dockimbel
Forked from maximvl/haiku.red
Created December 29, 2016 14:32
Show Gist options
  • Save dockimbel/da0bba1a9616e979e5bcd7a794204e2f to your computer and use it in GitHub Desktop.
Save dockimbel/da0bba1a9616e979e5bcd7a794204e2f to your computer and use it in GitHub Desktop.
Red [
description: {
Attempt to copy Haiku Editor
(http://forthsalon.appspot.com/haiku-editor)
}
]
map: func [s 'word body] [
bind body 'word
forall s [
set word s/1
s/1: do body
]
head s
]
; runs forth code and returns dot
run-forth: function [x x-scaled y y-scaled code] [
colors: copy [0.5 0 0]
; rules: []
; upd: parse code rules
; change colors copy/part upd 3
make-dot x y colors
]
; generates draw code for each dot
make-dot: func [x y colors] [
colors: to-tuple map copy colors c [ to-integer (c * 255) ]
compose [
fill-pen (colors)
pen off
box (to-pair reduce [x y])
(to-pair reduce [x + 1 y + 1])
]
]
; generates panel and draw code
generate: function [text] [
to-draw: copy [
; box 100x100 110x110
]
pane-size: 50x50
x-scale: 1.0 / pane-size/x
y-scale: 1.0 / pane-size/y
code: load text
x: y: 0
loop pane-size/y [
y-scaled: y * y-scale
x: 0
loop pane-size/x [
x-scaled: x * x-scale
append to-draw run-forth x x-scaled y y-scaled code
x: x + 1
]
y: y + 1
]
; probe to-draw
compose/deep [base (pane-size) draw [(to-draw)]]
]
demo: {
}
view [
title "Demo"
backdrop #2C3339
across
source: area #13181E 410x300 no-border demo font [
name: "Consolas"
size: 9
color: hex-to-rgb #9EBACB
]
panel 200x300 #2C3339 react [
attempt/safer [face/pane: layout/tight/only generate source/text]
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment