Skip to content

Instantly share code, notes, and snippets.

@toomasv
toomasv / flatten.red
Created August 28, 2017 19:58
Flatten up to certain level
flatten: func [tree [block!] /level lvl /local rule l][
(l: -1)
rule: [(l: l + 1) some [
ahead block! if (any [not level l < lvl]) into rule (l: l - 1)
| keep skip
| none
]]
parse tree [collect rule]
]
@toomasv
toomasv / info.red
Last active April 20, 2021 06:13
To get info about any function
Red []
context [
get-function: function [path] [
if path? path [
path: copy path
while [
not any [
tail? path
any-function? attempt [get/any either last? path [path/1] [path]]
]
@toomasv
toomasv / matrix.red
Last active October 6, 2017 10:52
Little matrix DSL
Red [
Author: "Toomas Vooglaid"
Date: 7-9-2017
Last-update: 4-10-2017
]
mx: context [
ctx: self
mtx: object [
rows: cols: data: none
get-col: func [col][extract at data col cols]
@toomasv
toomasv / chatbot.red
Last active September 12, 2017 08:39
Red [
Original: "Gregg Irwin"
Source: https://gitter.im/red/help?at=59b3040566c1c7c4772d4172
Purpose: "Toy chatbot about Red functions"
Needs: "info.red (https://gist.github.com/toomasv/eaac3829ac5e745f43121aa60b555d68)"
]
; See: http://www.red-lang.org/2016/03/060-red-gui-system.html blog entry
; Lots of name choices to consider.
@toomasv
toomasv / swap*.red
Last active September 19, 2017 18:13
Adds `/skip` to `swap`
Red []
swap*: func [a b /part length /local tmp] [
either part [
tmp: copy/part a length
change/part a copy/part b length length
change/part b tmp length
head a
][
swap a b
]
@toomasv
toomasv / l-system.red
Last active February 21, 2019 12:11
Experiments with L-System
Red [
Author: "Toomas Vooglaid"
Date: 25-9-2017
Description: {Experiments with L-System}
Last-update: 26-9-2017
Uses: {%models.red https://gist.github.com/toomasv/313e1d8583fb159428222651b76926cd}
Repo: https://github.com/toomasv/l-system
]
context [
ctx: self
@toomasv
toomasv / models.red
Created September 26, 2017 16:12
Some models for `l-system`
#(
title: "Blocky 1"
language: [#"L" "L+L-L-LL+L+L-L"]
initial: "L+L+L+L"
iterations: 3
options: [angle 90 length 0x100 scale 1.0 origin 200x470 anti-aliasing? (false)]
)
#(
title: "Blocky 2"
language: [#"L" "LL+L-L+L+LL"] ; FF-F+F-F-FF
@toomasv
toomasv / game-of-life
Last active October 6, 2017 10:57
Small game-of-life board
Red [
Author: "Toomas Vooglaid"
Started: 2-10-2017
Uses: {%matrix.red (https://github.com/toomasv/matrix)}
Last-update: 6-10-2017
]
do https://tinyurl.com/ybvyqxcu
cx: context [
m: size: cell: _Img: _Cyc: cyc: steps: real-size: data: i: sz: go: _Size: _Cell: d: o: offset: none
history: copy []
Red []
context [
cases: copy []
x: sum: probabilities: none
set 'pick-random func [items /size num /init probs /local out][
x: random 100%
if init [
probabilities: probs
cases: copy []
sum: 0%
@toomasv
toomasv / hanoi.red
Last active October 26, 2017 17:48
Red [
Author: "Toomas Vooglaid"
Date: 2017-10-24
Needs: View
]
context [
system/view/auto-sync?: dragable?: off-the-post?: no
offset: pos-x: post: current-post: post1: post2: post3: disc: disc1: disc2: disc3: disc4: steps: thickness: none
post1-narrow: charset [ 48 - 52]
post2-narrow: charset [148 - 152]