Skip to content

Instantly share code, notes, and snippets.

View greggirwin's full-sized avatar

Gregg Irwin greggirwin

  • Redlake Technologies
View GitHub Profile
@greggirwin
greggirwin / crosshair.red
Created June 23, 2016 04:37
Interactive crosshairs in 15 LOC
Red [Author: "Gregg Irwin"]
view [
text bold "Crosshairs" text "Move the mouse"
return
base 640x480 water all-over
draw [pen black h-line: line 0x0 0x0 v-line: line 0x0 0x0]
on-over [
h-line/2: as-pair 0 event/offset/y
h-line/3: as-pair 640 event/offset/y
@greggirwin
greggirwin / wumpus.red
Created June 25, 2016 15:53
Hunt the Red Wumpus
Red [
Title: "Hunt the Wumpus"
;Date: 25-Jun-2016
Author: "Gregg Irwin"
Version: 1.0.2
Comment: {
2001 Notes:
I found an old version, in C (by Eric Raymond), which was adapted from
an even older version, in BASIC (by Magnus Olsson), that had been found
in a SIMTEL archive. It's got lineage.
@greggirwin
greggirwin / view-hanoi.red
Last active December 14, 2016 05:51
Graphical Red Towers of Hanoi
Red [
File: %view-hanoi.red
Author: "Gregg Irwin"
Date: "4-Oct-2001 — 26-Jun-2016"
Needs: View
]
num-disks: 5 ; Have to set this here until it gets into the UI.
disk-height: 15
disk-cell-width: 20 ; Smallest disk is 1 cell wide
@greggirwin
greggirwin / move-face.red
Created June 26, 2016 14:19
Show how easy it is to move a face dynamically in Red layout.
Red [
Title: "Move a face"
Author: "Gregg Irwin"
File: %move-face.red
Tabs: 4
Needs: View
Purpose: {Show how just changing a face's offset moves it.}
]
diff: 1
@greggirwin
greggirwin / move-face-spring.red
Created June 26, 2016 14:41
Move a face in a layout dynamically, and with variable speed.
Red [
Title: "Move a face, like a spring"
Author: "Gregg Irwin"
File: %move-face-spring.red
Tabs: 4
Needs: View
Purpose: {
- Show how changing a face's offset moves it.
- Adjust the speed to make it more interesting.
}
@greggirwin
greggirwin / vector-balls.red
Last active July 8, 2016 09:29
Red Vector Balls
Red [
Title: "Vector Balls Demo"
Author: ["Nenad Rakocevic" "Gregg Irwin"]
Date: "[2-feb-2001 15-jun-2016]"
File: %vector-balls.red
Version: 0.4
History: {[
0.2 12-jun-2000 "First version released."
0.3 02-feb-2001 "Speed field added"
0.4 26-jun-2016 "Ported to Red by Gregg"
@greggirwin
greggirwin / invalid-utf8.red
Created July 7, 2016 23:38
Red invalid-utf8? function
invalid-utf?: function [
; https://robots.thoughtbot.com/fight-back-utf-8-invalid-byte-sequences
"Checks UTF encoding; if correct, returns none else position of error."
binary [binary!]
][
bad: [
#{C0} | #{C1} | #{F5} | #{F6} | #{F7} | #{F8} | #{F9} | #{FA}
| #{FB} | #{FC} | #{FD} | #{FE} | #{FF}
]
if parse binary [any [[mark: bad (return mark)] | skip]] [none]
@greggirwin
greggirwin / collect-values.red
Last active February 11, 2018 04:59
Red collect-values and collect-words functions
collect-values: function [
"Collect values in a block, by type or custom parse rule"
block [block!]
rule "Datatype, prototype value, or parse rule"
/deep "Include nested blocks"
/local v
][
rule: switch/default type?/word rule [
datatype! [reduce [rule]] ; Turn a plain datatype into a parse rule for that type.
block! typeset! [:rule] ; Blocks and typesets (e.g. any-word!) work directly as rules.
@greggirwin
greggirwin / vid-pico-sheet.red
Last active August 19, 2017 15:13
VID version of Nenad's Native Red PicoSheet
Red [
Title: "Tiny VID Spreadsheet"
Author: ["Gregg Irwin" "based on Nenad's Native PicoSheet"]
Needs: View
]
sheet-size: 8x8
cell-size: 100x24
L: charset "ABCDEFGHIabcdefghi"
@greggirwin
greggirwin / arity-of.red
Last active April 12, 2021 17:47
Red arity-of function
; We have other reflective functions (words-of, body-of, etc.), but
; this is a little higher level, sounded fun to do, and may prove
; useful as we write more Red tools. It also shows how to make your
; own typesets and use them when parsing.
arity-of: function [
"Returns the fixed-part arity of a function spec"
spec [any-function! block!]
/with refs [refinement! block!] "Count one or more refinements, and add their arity"
][