-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodulo-plot.red
47 lines (43 loc) · 1.33 KB
/
modulo-plot.red
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Red [
title: "MODULO compliance plots"
purpose: "Visually compare modulo implementation with Wikipedia"
author: @hiiamboris
license: 'BSD-3
note: https://en.wikipedia.org/wiki/Modulo_operation
]
#include %modulo.red
~offset: 20x0
~size: 400x250
make-plot: func [flavor sign color shift /local ps] [
ps: collect [
i: -6.0 while [i <= 6.0][
keep as-pair (~size/x / 12) * i (~size/x / 12) * do compose [(flavor) i 3 * sign]
i: i + 0.05
]
]
compose/deep [
pen (color) line-width 1.5
text (~offset: ~offset + 0x20) (rejoin [form flavor ", " either sign < 0 ["negative"]["positive"] " divisor"])
translate (~size / 2 + shift) [scale 1 -1 [shape [line (ps) move (first ps)]]]
]
]
view compose/deep [
across
base coal (~size) draw [
pen white line (~size / 2 * 0x1) (~size / 1x2) line (~size / 2 * 1x0) (~size / 2x1)
(make-plot [modulo/floor] 1 green 0x0)
(make-plot [modulo/floor] -1 red 0x2)
]
(~offset: 20x0 [])
base coal (~size) draw [
pen white line (~size / 2 * 0x1) (~size / 1x2) line (~size / 2 * 1x0) (~size / 2x1)
(make-plot [modulo/trunc] 1 green 0x0)
(make-plot [modulo/trunc] -1 red 0x2)
]
(~offset: 20x0 [])
base coal (~size) draw [
pen white line (~size / 2 * 0x1) (~size / 1x2) line (~size / 2 * 1x0) (~size / 2x1)
(make-plot [modulo] 1 green 0x0)
(make-plot [modulo] -1 red 0x2)
]
]