From 1ea31ed8cb683771a7ac1655a94a7c8d89c6a687 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Fri, 22 Feb 2002 13:42:49 +0000 Subject: *** empty log message *** --- sandbox/local.pl | 4 +- sandbox/testbezier.pl | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 sandbox/testbezier.pl (limited to 'sandbox') diff --git a/sandbox/local.pl b/sandbox/local.pl index 5f96fc2..2e2e9df 100644 --- a/sandbox/local.pl +++ b/sandbox/local.pl @@ -98,8 +98,8 @@ $mp2 = $zinc->add('curve', $view, [0, 320, 80, 470, 200, 470], -fillcolor => 'wheat', # -fillpattern => 'AlphaStipple8', # -tile => $papier, - -marker => '', - -markercolor => 'red'); + -marker => 'AtcSymbol6', + -markercolor => 'black'); $mp3 = $zinc->add('curve', $view, [20, 280, 100, 430, 200, 430], -linewidth => 9, -closed => 0, diff --git a/sandbox/testbezier.pl b/sandbox/testbezier.pl new file mode 100644 index 0000000..9ad39d2 --- /dev/null +++ b/sandbox/testbezier.pl @@ -0,0 +1,176 @@ +#!/usr/bin/perl -w + + +use Tk; +use Tk::Zinc; +use Controls; +use Tk::Photo; +require Tk::PNG; + + +$top = 1; +$lw = 8; +$arrow = [8, 10, 6]; + +# +# Cap, Filled, Border, Relief, Title +# +@show = ( + ['round', 0, 1, 'flat', 'CapRound'], + ['butt', 0, 1, 'flat', 'CapButt'], + ['projecting', 0, 1, 'flat', 'CapProjecting'], + ['round', 0, 1, 'sunken', 'Sunken'], + ['round', 0, 1, 'raised', 'Raised'], + ['round', 0, 1, 'groove', 'Groove'], + ['round', 0, 1, 'ridge', 'Ridge'], + ['round', 1, 1, 'sunken', 'FilledSunken'], + ['round', 1, 1, 'raised', 'FilledRaised'], + ['round', 1, 1, 'groove', 'FilledGroove'], + ['round', 1, 1, 'ridge', 'FilledRidge'], + ['round', 1, 0, 'flat', 'Fill'], + ['round', 1, 1, 'flat', 'FillBorder']); + +$mw = MainWindow->new(); +#$logo = $mw->Photo(-file => "logo.gif"); +$papier = $mw->Photo(-file => "texture-paper.xpm"); + +$zinc = $mw->Zinc(-render => 1, + -borderwidth => 0, + -highlightthickness => 0, + -relief => 'sunken', + -takefocus => 1, + -tile => $papier + ); +$zinc->pack(-expand => 1, -fill => 'both'); +$zinc->configure(-width => 500, -height => 500); +$zinc->scale($top, 1, -1); + +$view = $zinc->add('group', $top, + -tags => 'controls'); +$clipbez = $zinc->add('bezier', $view, [20, -20, + 890, -20, + 890, -900, + 20, -400], + -linewidth => 0, + -filled => 1, + -fillcolor => 'tan'); +#$zinc->itemconfigure($view, +# -clip => $clipbez); + +# +# Create the model +# +$model = $zinc->add('group', $view); +$mp = $zinc->add('bezier', $model, [50, -150, + 100, -50, + 270, -130, + 220, -200, + 200, -180, + 180, -300, + 140, -160, + 70, -300], + -linecolor => 'yellow', + -fillcolor => 'tan:50', + -tags => 'bezier', + -linewidth =>$lw); +#$zinc->add('rectangle', $model, [50, -150, 100, -50]); +@bbox = $zinc->bbox($mp); +@bbox = $zinc->transform($model, \@bbox); +$x = ($bbox[2] + $bbox[0]) / 2; +$y = $bbox[1] + 5; +$zinc->add('text', $model, + -text => 'CapRound', + -color => 'blue', + -alignment => 'center', + -anchor => 's', + -tags => 'title', + -position => [$x, $y]); + +# +# Now clone for each variation on the polygon +# +$col = 0; +$row = 0; +foreach $current (@show) { + ($cap, $filled, $border, $relief, $title) = @{$current}; + $grp = $zinc->clone($model); + $zinc->translate($grp, $col * 240, $row * (-290 - (2 * $lw))); + $zinc->itemconfigure($zinc->find('withtag', 'bezier', $grp), + -capstyle => $cap, + -filled => $filled, + -linewidth => $border ? $lw : 0, + -relief => $relief); + $zinc->itemconfigure($zinc->find('withtag', 'title', $grp), + -text => $title); + $col++; + if ($col >= 4) { + $col = 0; + $row++; + } +} + +# +# Suppress the model +# +$zinc->remove($model); + + +# +# Some optional graphic features +$closed = 0; +#set smooth 0 +$arrows = 'none'; + +sub toggle_arrows { + if ($arrows eq 'none') { + $arrows = 'first'; + $f = $arrow; + $l = ''; + } + elsif ($arrows eq 'first') { + $arrows = 'last'; + $f = ''; + $l = $arrow; + } + elsif ($arrows eq 'last') { + $arrows = 'both'; + $f = $arrow; + $l = $arrow; + } + elsif ($arrows eq 'both') { + $arrows = 'none'; + $f = ''; + $l = ''; + } + $zinc->itemconfigure('bezier', + -firstend => $f, + -lastend => $l) +} + + +sub toggle_closed { + $closed = !$closed; + foreach $ curve ($zinc->find('withtag', 'bezier')) { + if ($closed) { + @coords = $zinc->coords($curve, 0, 0); + $zinc->coords($curve, 'add', \@coords); + } + else { + $zinc->coords($curve, 'remove', -1) + } + } +} + +$zinc->Tk::focus(); + +$zinc->Tk::bind('', \&toggle_arrows); +$zinc->Tk::bind('', \&toggle_closed); + +$zinc->Tk::bind('', + sub {my $ev = $zinc->XEvent(); + my $it = $zinc->find('closest', $ev->x, $ev->y); + print "$it ", $zinc->verticeat($it, $ev->x, $ev->y), "\n"}); +$zinc->Tk::bind('', sub {Tk::break}); + +new Controls($zinc); +MainLoop(); -- cgit v1.1