[ALLY] View Docs - draw
[1/2] from: pejay::upnaway::com at: 8-Apr-2001 13:31
Hi Allies,
View Docs refer to Draw Dialect document for information on Draw ....
Can anyone point me in the direction of how to use the drawing routines??
Can you draw into images??
Cheers Phil
[2/2] from: allenk:powerup:au at: 10-Apr-2001 19:31
Hi Phil,
Not sure if this is uptodate or not for the View version, but it should get
you started.
Docs copyright RT etc...
Cheers,
Allen K
DRAW Dialect for REBOL Faces
----------------------------
Updated: 20-Jan-2001/19:24
NOTE: Add your own short/interesting/insightful examples to the tail of
this document.
The DRAW dialect is part of the EFFECTS block of a face. For example:
view layout [
box black 100x100 effect [
draw [
pen red
line 30x30 50x20 70x70 40x50
pen blue
box 20x20 80x80
fill-pen leaf
box 20x60 40x80
polygon 10x10 40x40 40x80 10x0
pen white
text 8x25 "Example"
fill-pen gold
flood 2x2
]
]
]
The DRAW dialect accepts the following keywords, followed by their
optional arguments.
Arguments of different datatypes can appear in alternate order.
For example, text can be specified as:
text 8x25 "Example"
or:
text "Example" 8x25
Draw Attribute Words:
---------------------
pen [foreground-color [tuple! none!]] [background-color [tuple! none!]]
Set the current foreground color and background color for outline
rendering (line, circle, polygon, box). A color of none is equivalent
to transparent. The defaults are: foreground: inverse of face color,
background: none. (Note: instead of a tuple or none this function should
also accept the words 'inverse and 'reverse, with 'inverse meaning
"rendering by complementing the image", i.e. without a given color,
and with 'reverse meaning "reverse the meaning of foreground and
background" -- to be implemented).
fill-pen [foreground-color [tuple! none!]] [background-color [tuple! none!]]
Set the current foreground color and background color for area filling
(circle, box, flood, to be implemented: polygon). A color of none is
equivalent to transparent. (Note: area fill patterns are not supported
yet, so the background color is not used at this time). The defaults
are none. (Note: 'inverse and 'reverse to be added. See above).
line-pattern [len1 [integer!]] [len2 [integer!]] ... [lenn [integer!]]
Set the line pattern. Each len parameter defines the length of a
set (foreground) or unset (background) segment of the line, Set and
unset segments alternate. For instance "line-patten 1 5" defines a
dotted line, with dots 5 pixels apart, "line-pattern 8 8" defines a
dashed line, "line-pattern 1 4 4 4" defines a morse-code-style line
(alternating between dotted and dashed). Up to 8 segments can be
defined.
An empty line-pattern call (without parameters following) resets to
the default: a solid line.
font [textfont [object!]]
Set the font to be used in subsequent text calls. The default is the
font used by the face. (Note: this function should probably accept other
types of parameters as well, e.g. a font name or size, and clone the
current face font object, if necessary -- to be implemented).
Draw Object Words:
------------------
line [point1 [pair!]] [point2 [pair!]] ... [pointn [pair!]]
Draw a line from point1 to point2, from point 2 to point 3, ... to point
n.
Points n and 1 are NOT connected by an additional line. The current pen
colors and line pattern are observed.
polygon [point1 [pair!]] [point2 [pair!]] ... [pointn [pair!]]
Similar to line, except that points n and 1 are connected afterwards, to
create a closed polygon. (Note that simply adding point1 at the end of
a call to line does NOT create the same effect, because then point1
would
be rendered twice, which causes undesired effects in some rendering
modes).
If the fill-pen is different from none then the polygon is filled in the
specified color.
circle [center [pair!]] [radius [integer!]]
Draw a circle at the given point, with the given radius. Both the
outline pen colors and the fill colors are observed. The line pattern
is NOT observed.
box [point1 [pair!]] [point2 [pair!]]
Draw a rectangle, parallel to the x/y axes, through the two diagonal
endpoints specified. Both the outline pen colors and the fill colors
are observed. The line pattern is observed for the box outline.
text [point [pair!]] [text [string!]]
Renders the specified text at the specified position, using the current
font setting, foreground and background color.
image [[point [pair!]] image [image!]] [transp-color [tuple!]]
Renders the specified image at the specified position. If
transp-color is specified then this color (in the image) is
considered to be transparent.
Draw Function Words:
--------------------
flood [point [pair!]] [border-color [tuple!]]
Flood-fills the area around the specified point with the current
foreground fill color. If border-color is not specified then any
pixel with a color different from the color of the starting point
is considered to be part of the border. Otherwise all pixels with
a color of border-color define the border.
Examples:
---------
Draw a single red line into a face and display it:
view/new make face [
size: 200x200
effect: [draw [pen 200.0.0 line 20x20 180x180]]
]
Draw a few connected red lines and a blue box:
view make face [
size: 200x200
effect: [
draw [
pen 200.0.0
line 50x50 150x150 50x150 150x50 50x50
pen 0.0.200
box 20x20 180x180
]
]
]
Draw a circle:
view/new make face [
size: 200x200
effect: [
draw [
pen 200.0.0
circle 100x100 50
]
]
]
Draw a filled circle:
view make face [
size: 200x200
effect: [
draw [
pen 200.0.0
fill-pen 50.50.100
circle 100x100 50
]
]
]
Draw a box and a circle, then use a flood fill:
view make face [
size: 200x200
color: black
effect: [
draw [
pen white
box 20x20 180x180
pen red
circle 100x100 100
fill-pen blue
flood 100x100
]
]
]
Draws text in a maroon color:
view make face [
size: 200x200
effect: [
draw [
pen maroon
text "Hello" 20x20
]
]
]
Using other fonts for text:
italic-font: make face/font [
size: 10
style: 'italic
name: font-serif
]
view layout [
image 150x150 gold effect [
draw [
pen blue
text 0x20 "Default Font"
font italic-font
text 0x40 "Small Times Italic Font"
]
]
]
Other face effects can be done before the DRAW operation. This
example draws 100 random lines in random colors on a gradient
backdrop effect:
fx: [gradient 1x1 0.150.0 0.0.150 draw []]
lines: select fx 'draw
loop 100 [
repend lines [
'pen random 250.50.50
'line random 200x200 random 200x200
]
]
view make face [size: 200x200 effect: fx]
Other face effects can follow the DRAW operation. This example
draws a line and a box then inverts and blurs them:
view make face [
size: 200x200
effect: [
draw [
pen 200.0.0
line 50x50 150x150 50x150 150x50 50x50
pen 0.0.200
box 20x20 180x180
]
invert blur
]
]
Perform a pre-effect and a post-effect. A gradient is created,
then 100 random circles are drawn, then the result is color
differenced with an image bitmap.
fx: [gradient 1x1 0.150.0 0.0.150 draw []]
lines: select fx 'draw
loop 100 [
repend lines [
'pen random 250.50.50
'circle random 200x200 random 100
]
]
repend fx ['difference load link-root/apps/demos/bay.jpg]
view make face [size: 200x200 effect: fx]
Draw an image twice. The first includes all of its colors. The
second makes one of its colors transparent.
i: load link-root/desktop/ico_console.gif
view make face [
size: 200x200
effect: [
draw [
image i 20x20
image i 80x80 174.154.122
]
]
]
Draws lines when you hold the mouse button down and move it.
f: make face [
size: 400x400
effect: copy/deep [draw [pen black line]]
line: second effect
feel: make feel [
engage: func [f a e] [
if find [down over] a [
append f/line e/offset
show f
]
if a = 'up [append f/line 'line]
]
]
]
view make face [size: f/size pane: f]
Draws filled circles as the mouse is moved with the button down:
f: make face [
size: 400x400
effect: copy/deep [draw [pen black]]
line: second effect
feel: make feel [
engage: func [f a e] [
if find [down over] a [
repend f/line [
'fill-pen random 0.255.0
'circle e/offset 20
]
show f
]
]
]
]
view make face [size: f/size pane: f]