Skip to content

Instantly share code, notes, and snippets.

@toomasv
toomasv / zooming.red
Last active September 5, 2019 16:32
Zooming function
Red [
Date: 4-Sep-2019
Description: {Mouse sensitive zooming function}
Author: "Toomas Vooglaid"
Licence: "Public domain"
]
zooming: function [face event][
;face's draw-block needs to have matrix defined
mx: face/draw/matrix
@toomasv
toomasv / gen-hack2.red
Last active August 17, 2019 03:27
(de)randomize argument
Red [
Date: 16-Aug-2019
See: {[August 15, 2019 9:56 PM](https://gitter.im/red/red?at=5d55aacd4e17537f5239de0c) forward}
Description: {Combined from @grggirwin's and @dockimbel's with some spice}
]
gen-hack2: function [
{Generates randomly suffled copy of the argument and the seed to get it stright}
secret [any-string! any-block! binary!]
][
random/seed stats
@toomasv
toomasv / shooting.red
Last active August 14, 2019 19:58
Parametrized curve
Red [
Title: "Shooting"
Description: "Exercise with parametrized curve"
Date: 2019-08-10
Author: "Toomas Vooglaid"
Licence: "Public domain"
Usage: {
To load and orient the weapon - drag point.
To relocate the target - drag target.
To relocate weapon - ctrl-drag it (cannon relocates horizontally on dragging).
@toomasv
toomasv / prisoners.red
Last active August 4, 2019 16:51
Prisoner's dilemma tournament
Red [
Description: "Prisoner's dilemma tournament"
Date: 3-Aug-2019
Author: "Toomas Vooglaid"
Licence: "Public domain"
]
;set [R P T S] [-1 -3 0 -6] ; One turn (original)
set [R P T S] [3 1 5 0]
choose: func [A B][reduce case [
all [A B] [[R R]] ;A and B [[R R]]
@toomasv
toomasv / fly.red
Last active August 28, 2019 08:53
Spider and fly
Red [
Date: 28-July-2019
Notes: {Click on window to add flies}
]
bb: [] fc: target: none
web: load %web.png
set-step: func [face][as-pair
face/extra/speed * (cosine face/extra/dir)
face/extra/speed * (sine face/extra/dir)
]
@toomasv
toomasv / rays.red
Last active August 2, 2019 19:22
Ray-casting exercise
Red [
Description: {Ray casting exercise}
Needs: View
Date: 25-July-2019
Inspiration: https://github.com/krisajenkins/elm-rays
Tutorial: https://ncase.me/sight-and-light/
Redporter: "Toomas Vooglaid"
Licence: "Public domain"
]
; To change into plain light instead of radial
@toomasv
toomasv / drag-to-panel.red
Created July 14, 2019 08:45
Drag and drop base into panel, dbl-click to get it out
Red [
Description: {Dragn'drop into panel}
Date: 14-July-2019
]
context [
hop: false
pan: pane: ofs: none
view [
base loose
on-down [move find pane: face/parent/pane face tail pane]
@toomasv
toomasv / array-diagram
Last active July 10, 2019 08:12
diagram-style tryout
Red [
Title: "Array func diagram"
Date: 9-Jul-2019
Needs: View
Author: "Toomas Vooglaid"
Uses: https://github.com/toomasv/diagram/blob/master/diagram-style.red
]
do %diagram-style.red
view dia [
title "Gregg's array func"
@toomasv
toomasv / includes.red
Created July 6, 2019 04:45
Check containment in series
Red [
Date: 2019-07-06
Author: "Toomas Vooglaid"
Motivation: https://gitter.im/red/help?at=5d20178fc5f3c329aef31f43
]
includes?: func [
"Check if first argument contains any of second argument"
a [series!]
b [any-type!]
][
@toomasv
toomasv / mget.red
Last active June 26, 2019 03:18
@GiuseppeChillemi's path dialect
Red [
Description: {Attempt to implement @GiuseppeChillemi's "path dialect"}
Date: 22-Jun-2019
Author: "Toomas Vooglaid"
]
system/lexer/pre-load: func [src][
chr: complement charset {/[ "#}
path: [some chr #"/" some chr]
mpath: [path change #"[" "/(" to #"]" change skip #")" any [#"/" mpath]]