Skip to content

Instantly share code, notes, and snippets.

@toomasv
Last active January 26, 2018 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toomasv/a9f6ae187484fa6629a3e4756fa3ed8b to your computer and use it in GitHub Desktop.
Save toomasv/a9f6ae187484fa6629a3e4756fa3ed8b to your computer and use it in GitHub Desktop.
Red [
Author: "Toomas Vooglaid"
Date: 2018-01-26
Needs: View
Purpose: {Study of dashed circles}
]
circle-ctx: context [
pat-f: func [c d l s start end][
l: round/to l 1
start: any [start 0]
end: any [end 360]
;probe reduce [c d l s start end]
collect [repeat i end / l [keep reduce ['arc c d (i - 1 * l + start) s 'closed]]]
]
size: 100x100
l: s: none
set 'circle func [c r /dashed /dotted /pattern p /size sz /limits e /format f /local start end l s d][
size: any [sz self/size] ;face/parent/size
if limits [
either block? e
[start: e/1 if 1 < length? e [end: e/2]]
[start: e]
]
if pattern [
either block? p
[l: p/1 if 1 < length? p [s: p/2]]
[l: p]
]
f: any [f [fill-pen black]]
case [
dashed [
l: any [l arcsine 12.0 / r]
s: any [s round/to l / 2 1]
d: as-pair r r
compose/deep [pen pattern (size) [(f) (pat-f c d l s start end)][circle (c) (r)]]
]
dotted [
l: any [l arcsine 4.0 / r]
s: any [s 1]
d: as-pair r r
compose/deep [pen pattern (size) [(f) (pat-f c d l s start end)][circle (c) (r)]]
]
pattern [
d: as-pair r r
compose/deep [pen pattern (size) [(f) (pat-f c d l s start end)][circle (c) (r)]]
]
true [
reduce [(f) 'circle c r]
]
]
]
]
; 2 3 4 5 6 8 9 10 12 15 18 | 20 24 30 36 40 45 60 85 120 180
;view compose/deep [image draw [(circle/dashed 50x50 40) (circle/dotted 70x30 20)]]
;view compose/deep [image draw [line-width 25 (circle/dashed/pattern 50x50 40 120) line-width 40 (circle/dotted/pattern 50x50 20 30)]]
;view compose/deep [image draw [line-width 25 (circle/pattern/format 50x50 40 [120 60][fill-pen off]) line-width 40 (circle/dotted/pattern 50x50 20 30)]]
;view compose/deep [image draw [line-width 25 (circle/dashed/pattern/limits/format 50x50 40 60 [-15 240][pen off fill-pen red]) line-width 40 (circle/pattern/limits/format 50x30 20 [30 5][180 210][pen gold])]]
;view compose/deep [image draw [rotate 0 50x50 [line-width 25 (circle/dashed/pattern/format 50x50 40 60 [pen off fill-pen red])] rotate 0 50x50 [line-width 40 (circle/pattern/format 50x50 20 [30 5][pen gold])]] rate 20 on-time [face/draw/2: 1 + face/draw/2 face/draw/6: face/draw/6 - 1]]
comment {
;Self-portrait
circle-ctx/size: 200x200
view compose/deep [image 200x200 draw [
fill-pen beige
(circle/dashed 100x100 90)
fill-pen off line-width 30
(circle/dotted/pattern/limits/format 100x100 100 10 [-150 120] [pen off fill-pen brown])
line-width 30
(circle/dotted/pattern/limits/format 100x100 100 5 [70 40] [pen off fill-pen brown])
line-width 1 fill-pen white
(circle/dotted 70x70 20)
(circle/dotted 130x70 20)
line-width 10 fill-pen off
(circle/dotted/limits 70x90 40 [-120 60])
(circle/dotted/limits 130x90 40 [-120 60])
pen off fill-pen silver
(circle/pattern 75x75 10 [360 330])
(circle/pattern 125x75 10 [360 330])
fill-pen black
circle 78x78 3
circle 122x78 3
fill-pen tanned
circle 90x120 10
circle 110x120 10
ellipse 87x87 26x46
fill-pen off line-width 20 pen black
(circle/dotted/pattern/limits/format 100x185 50 6 [180 180] [pen brown])
(circle/pattern/limits/format 100x0 170 [4 3] [80 20] [fill-pen white pen black])
line-width 20
(circle/pattern/limits/format 100x200 50 [80 80] [-130 80] [fill-pen papaya pen papaya])
]]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment