pix 0.7: Reference Manual

examplesTop, Main, Index

blur.tclTop, Main, Index

# From Pixie examples folder (https://github.com/treeform/pixie/tree/master/examples)
# ported to Tcl for package pix.

# 02-Jun-2024 : v1.0 : Initial example
# 04-Jun-2024 : v2.0 : bad definition mask.
# 22-Jun-2024 : v3.0 : rename proc 'pix::img::read' by 'pix::img::readImage'.

package require pix

set file [file join [file dirname [info script]] data trees.png]

set trees [pix::img::readImage $file]
set blur  [pix::img::copy $trees]
set image [pix::img::new {200 200}]

pix::img::fill $image "white"

set path [pix::path::new]
pix::path::polygon $path {100 100} 70 6

set mask [pix::img::new {200 200}]
pix::img::fillPath $mask $path "rgba(255,255,255,1)"

pix::img::blur $blur 20

pix::img::draw $blur $mask "MaskBlend"

pix::img::draw $image $trees
pix::img::draw $image $blur

set p [image create photo]
pix::drawSurface $image $p

alt img

gradient.tclTop, Main, Index

# From Pixie examples folder (https://github.com/treeform/pixie/tree/master/examples)
# ported to Tcl for package pix.

# 02-Jun-2024 : v1.0 : Initial example
# 22-Jun-2024 : v2.0 : pass <paint> options to configure proc

package require pix

set image [pix::img::new {200 200}]
pix::img::fill $image "rgba(255, 255, 255, 1)"

set paint [pix::paint::new "RadialGradientPaint"]
pix::paint::configure $paint {
    gradientHandlePositions {{100 100} {200 100} {100 200}}
    gradientStops {{{1 0 0 1} 0} {{1 0 0 0.15625} 1}}
}

set svg {
    M 20 60
    A 40 40 90 0 1 100 60
    A 40 40 90 0 1 180 60
    Q 180 120 100 180
    Q 20 120 20 60
    z
}

pix::img::fillPath $image $svg $paint

set p [image create photo]
pix::drawSurface $image $p

alt img

heart.tclTop, Main, Index

# From Pixie examples folder (https://github.com/treeform/pixie/tree/master/examples)
# ported to Tcl for package pix.

# 02-Jun-2024 : v1.0 : Initial example

package require pix

set image [pix::img::new {200 200}]
pix::img::fill $image "white"

set svg {
    M 20 60
    A 40 40 90 0 1 100 60
    A 40 40 90 0 1 180 60
    Q 180 120 100 180
    Q 20 120 20 60
    z
}

pix::img::fillPath $image $svg "#FC427B"

set p [image create photo]
pix::drawSurface $image $p

alt img

image_tiled.tclTop, Main, Index

# From Pixie examples folder (https://github.com/treeform/pixie/tree/master/examples)
# ported to Tcl for package pix.

# 02-Jun-2024 : v1.0 : Initial example
# 22-Jun-2024 : v2.0 : - Rename proc 'pix::img::read' by 'pix::img::readImage'.
#                      - Pass <paint> options to 'pix::paint::configure' proc.               

package require pix

set file [file join [file dirname [info script]] data mandrill.png]

set image [pix::img::new {200 200}]
pix::img::fill $image "white"

set path [pix::path::new]
pix::path::polygon $path {100 100} 70 8

set paint [pix::paint::new "TiledImagePaint"]
set f [pix::img::readImage $file]

set mat3 {
    0.08 0.0 0.0
    0.0 0.08 0.0
    0.0 0.0 1.0
}

pix::paint::configure $paint [list image $f imageMat $mat3]
pix::img::fillPath $image $path $paint

set p [image create photo]
pix::drawSurface $image $p

alt img

line.tclTop, Main, Index

# From Pixie examples folder (https://github.com/treeform/pixie/tree/master/examples)
# ported to Tcl for package pix.

# 02-Jun-2024 : v1.0 : Initial example

package require pix

set ctx [pix::ctx::new {200 200} "white"]
pix::ctx::strokeStyle $ctx "#FF5C00"
pix::ctx::lineWidth $ctx 10
pix::ctx::strokeSegment $ctx {25 25} {175 175}

set p [image create photo]
pix::drawSurface $ctx $p

alt img

masking.tclTop, Main, Index

# From Pixie examples folder (https://github.com/treeform/pixie/tree/master/examples)
# ported to Tcl for package pix.

# 02-Jun-2024 : v1.0 : Initial example

package require pix

set image [pix::img::new {200 200}]
set lines [pix::img::new {200 200}]
set mask  [pix::img::new {200 200}]

pix::img::fill $lines #FC427B
pix::img::fill $image "white"

set ctx [pix::ctx::new $lines]
pix::ctx::strokeStyle $ctx "#F8D1DD"
pix::ctx::lineWidth $ctx 30

pix::ctx::strokeSegment $ctx {25 25} {175 175}
pix::ctx::strokeSegment $ctx {25 175} {175 25}

set svg {
    M 20 60
    A 40 40 90 0 1 100 60
    A 40 40 90 0 1 180 60
    Q 180 120 100 180
    Q 20 120 20 60
    z
}

pix::img::fillPath $mask $svg "red"
pix::img::draw $lines $mask "MaskBlend"
pix::img::draw $image $lines

set p [image create photo]
pix::drawSurface $image $p

alt img

rounded_rectangle.tclTop, Main, Index

# From Pixie examples folder (https://github.com/treeform/pixie/tree/master/examples)
# ported to Tcl for package pix.

# 02-Jun-2024 : v1.0 : Initial example

package require pix

set ctx [pix::ctx::new {200 200} "white"]
pix::ctx::fillStyle $ctx "#00ff00"

pix::ctx::fillRoundedRect $ctx {50 50} {100 100} 25

set p [image create photo]
pix::drawSurface $ctx $p

alt img

shadow.tclTop, Main, Index

# From Pixie examples folder (https://github.com/treeform/pixie/tree/master/examples)
# ported to Tcl for package pix.

# 02-Jun-2024 : v1.0 : Initial example

package require pix

set image [pix::img::new {200 200}]
pix::img::fill $image "white"

set path [pix::path::new]
pix::path::polygon $path {100 100} 70 8

set polygonImage [pix::img::new {200 200}]
pix::img::fillPath $polygonImage $path "white"

set shadow [pix::img::shadow $polygonImage {offset {2 2} spread 2 blur 10 color "rgba(0,0,0,0.85)"}]

pix::img::draw $image $shadow
pix::img::draw $image $polygonImage

set p [image create photo]
pix::drawSurface $image $p

alt img

square.tclTop, Main, Index

# From Pixie examples folder (https://github.com/treeform/pixie/tree/master/examples)
# ported to Tcl for package pix.

# 02-Jun-2024 : v1.0 : Initial example

package require pix

set ctx [pix::ctx::new {200 200} "white"]

pix::ctx::fillStyle $ctx "rgba(255, 0, 0, 1)"
pix::ctx::fillRect $ctx {50 50} {100 100}

set p [image create photo]
pix::drawSurface $ctx $p

alt img

text_spans.tclTop, Main, Index

# From Pixie examples folder (https://github.com/treeform/pixie/tree/master/examples)
# ported to Tcl for package pix.

# 22-Jun-2024 : v1.0 : Initial example

proc newFont {typeface size color} {
    set font [pix::font::newFont $typeface]

    pix::font::configure $font [list  size  $size  color $color  ]

    return $font
}

package require pix

set image [pix::img::new {200 200}]
pix::img::fill $image "rgba(255, 255, 255, 255)"

set file [file join [file dirname [info script]] data Ubuntu-Regular_1.ttf]
set typeface [pix::font::readTypeface $file]

lappend spans [pix::font::newSpan [newFont $typeface 12 {0.78125 0.78125 0.78125 1}] "verb \[with object\] "]
lappend spans [pix::font::newSpan [newFont $typeface 36 {0 0 0 1}] "strallow\n"]
lappend spans [pix::font::newSpan [newFont $typeface 13 {0 0.5 0.953125 1}] "\nstral·low\n"]
lappend spans [pix::font::newSpan [newFont $typeface 14 {0.3125 0.3125 0.3125 1}] "\n1. free (something) from restrictive restrictions \"the regulations are intended to strallow changes in public policy\" "]

set typeset [pix::font::typeset $spans {bounds {180 180}}]
pix::img::fillText $image $typeset {1 0 0 0 1 0 10 10 1}

set p [image create photo]
pix::drawSurface $image $p

alt img

text.tclTop, Main, Index

# From Pixie examples folder (https://github.com/treeform/pixie/tree/master/examples)
# ported to Tcl for package pix.

# 02-Jun-2024 : v1.0 : Initial example
# 22-Jun-2024 : v2.0 : - Rename proc 'pix::font::read' by 'pix::font::readFont'.
#                      - Use dict options instead of parameters for 'pix::font::typeset' proc. 

package require pix

set image [pix::img::new {200 200}]
pix::img::fill $image "white"

set font [pix::font::readFont [file join [file dirname [info script]] data Roboto-Regular_1.ttf]]
pix::font::size $font 20
pix::font::color $font "rgb(255,0,0)"

set text "Typesetting is the arrangement and composition of text in graphic design and publishing in both digital and traditional medias."
set arrangement [pix::font::typeset $font $text {
        bounds {180 180} hAlign "LeftAlign" vAlign "TopAlign" wrap "true"
    }
]

set mat3 {
    1.0 0.0 0.0
    0.0 1.0 0.0
    10.0 10.0 1.0
}

pix::img::fillText $image $arrangement $mat3

set p [image create photo]
pix::drawSurface $image $p

alt img

tiger.tclTop, Main, Index

# From Pixie examples folder (https://github.com/treeform/pixie/tree/master/examples)
# ported to Tcl for package pix.

# 02-Jun-2024 : v1.0 : Initial example
# 22-Jun-2024 : v2.0 : rename proc 'pix::img::read' by 'pix::img::readImage'.
# 01-Apr-2025 : v3.0 : Use new `matrix` procedures instead of plain list.

package require pix

set image [pix::img::new {200 200}]
pix::img::fill $image "rgba(255, 255, 255, 1)"

set tiger [pix::img::readImage [file join [file dirname [info script]] data tiger.svg]]
pix::img::draw $image $tiger [pix::mulMatrix  [pix::transMatrix {100 100}]  [pix::scaleMatrix {0.2 0.2}]  [pix::transMatrix {-450 -450}]  ]

set p [image create photo]
pix::drawSurface $image $p

alt img