Skip to content

Instantly share code, notes, and snippets.

View tic-tac-toe.red
Red [
Description: "Tic-Tac-Toe"
Date: 2021-02-26
]
wins: [[1 2 3][4 5 6][7 8 9][1 4 7][2 5 8][3 6 9][1 5 9][3 5 7]]
check: func [move][
foreach win wins [
if 3 = length? intersect win state/:move [return win]
]
@toomasv
toomasv / clock-states.red
Created Feb 12, 2021
Harel's Citizen Quartz Multi-Alarm III statechart emulation for DiaGrammar
View clock-states.red
DiaGrammar [
Options: [
grammar-only?: false
ruleset: true
hovering: true
string-input: true
case-parsing: false
live-edit?: true
iterate-times: 1
max-iterate: 5
@toomasv
toomasv / merry.red
Created Dec 29, 2020
Fancy message decoration
View merry.red
Red [
Date: 29-Dec-2020
Purpose: "Fancy message decoration"
]
context [
font: [size: 32 style: 'bold]
size: 360x70
text: "Merry Christmas!"
area: make-face 'area [size: 1200x20 font: xfont]
@toomasv
toomasv / transparent.red
Last active Dec 24, 2020
Turn a color in image transparent
View transparent.red
Red [
Description: "Make some color of image transparent"
Date: 23-December-2020
]
context [
smudge: function [b [tuple!]][
a: b - 1 c: b + 1
reduce [
charset reduce [a/1 b/1 c/1]
charset reduce [a/2 b/2 c/2]
@toomasv
toomasv / expression.red
Last active Nov 30, 2020
Parse math string into Red block and optionally evaluate.
View expression.red
context [
expr: [term any [(op: add) enspace [term | (missing: "term") message]]]
term: [
record factor [
some [ahead [var | #"("] insert " * " factor
| (op: mul) enspace [factor | (missing: "factor") message]
] set-parens
| (remove position)
]
]
@toomasv
toomasv / simple-pie.red
Created Nov 14, 2020
Simple pie-chart
View simple-pie.red
Red [
Description: "Simple pie chart"
File: %simple-pie.red
Author: "Toomas Vooglaid"
Original: https://gitter.im/red/help?at=5b4f23adecc1f82e2fc206d6
Date: 18-Jul-2020
Adaptation: 14-Nov-2020
]
start: -90
tx: make-face 'text
@toomasv
toomasv / replace.red
Last active Sep 25, 2020
`replace` extended with `/only` refinement
View replace.red
Red [
Description: "`replace` extended with `/only` refinement"
Date: 24-Sep-2020
]
replace: func ["Replaces values in a series, in place"
series [series!] "The series to be modified"
pattern "Specific value or parse rule pattern to match"
value "New value, replaces pattern in the series"
/all "Replace all occurrences, not just the first"
/deep "Replace pattern in all sub-lists as well"
@toomasv
toomasv / quiz.red
Created Sep 21, 2020
Quiz about capitals
View quiz.red
Red []
page: read-thru/binary https://geographyfieldwork.com/WorldCapitalCities.htm
quiz: does [
capitals: clear []
loop 5 [
list: head page
loop (random 200) - 1 [
l: find list <td height="17"> list: find l </tr>
]
parse to-string copy/part l: find list <td height="17"> list: find l </tr> [
@toomasv
toomasv / hangman.red
Last active Sep 24, 2021
wallysilva's hangman modified
View hangman.red
Red [
Title: "The Hangman Game"
Date: "21-Jul-2020"
Author: Wally Silva
File: %hangman.red
Needs: View
Original: https://github.com/wallysilva/red-hangman
Modified: {toomasv on 31-Jul-2020}
Tab: 4
]
@toomasv
toomasv / draw-table.red
Last active Sep 24, 2021
Experiment with draw-based table
View draw-table.red
Red [
Description: "Simple navigation for draw-based table"
]
recycle/off
len-data: 200'000;0
data: make block! len-data
rows: 30
cols: 11
bx: 100x24
current: none