|
From: <arj...@us...> - 2008-08-19 16:13:26
|
Revision: 8680
http://plplot.svn.sourceforge.net/plplot/?rev=8680&view=rev
Author: arjenmarkus
Date: 2008-08-19 16:13:34 +0000 (Tue, 19 Aug 2008)
Log Message:
-----------
Added example 27 for Tcl
Modified Paths:
--------------
trunk/examples/tcl/CMakeLists.txt
Added Paths:
-----------
trunk/examples/tcl/x27
trunk/examples/tcl/x27.tcl
Modified: trunk/examples/tcl/CMakeLists.txt
===================================================================
--- trunk/examples/tcl/CMakeLists.txt 2008-08-19 15:26:30 UTC (rev 8679)
+++ trunk/examples/tcl/CMakeLists.txt 2008-08-19 16:13:34 UTC (rev 8680)
@@ -52,6 +52,7 @@
"24"
"25"
"26"
+"27"
)
set(tcl_SCRIPTS)
@@ -63,7 +64,7 @@
install(FILES ${tcl_FILES} DESTINATION ${DATA_DIR}/examples/tcl)
install(PROGRAMS ${tcl_SCRIPTS} DESTINATION ${DATA_DIR}/examples/tcl)
-# Copy file and scripts to the binary directory if different to the
+# Copy file and scripts to the binary directory if different to the
# source directory. Needed for ctest, but also so the tclIndex file
# is generated in the binary tree not the source tree.
if(NOT CMAKE_CURRENT_BINARY_DIR STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
Added: trunk/examples/tcl/x27
===================================================================
--- trunk/examples/tcl/x27 (rev 0)
+++ trunk/examples/tcl/x27 2008-08-19 16:13:34 UTC (rev 8680)
@@ -0,0 +1,19 @@
+#!/bin/sh
+#--------------------------------*- Tcl -*------------------------------------#
+# $Id$
+#
+# Arjen Markus
+# 08/18/08
+#
+# A front-end to x26.tcl for running directly from the command line, locating
+# pltcl via PATH.
+# Handles all usual plplot command arguments. See "pltcl -h" for info.
+#-----------------------------------------------------------------------------#
+#\
+exec pltcl -f "$0" ${1+"$@"}
+
+source x27.tcl
+
+plinit
+x27
+plend
Property changes on: trunk/examples/tcl/x27
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/examples/tcl/x27.tcl
===================================================================
--- trunk/examples/tcl/x27.tcl (rev 0)
+++ trunk/examples/tcl/x27.tcl 2008-08-19 16:13:34 UTC (rev 8680)
@@ -0,0 +1,136 @@
+# $Id$
+#
+# Drawing "spirograph" curves - epitrochoids, cycolids, roulettes
+#
+# Copyright (C) 2007 Arjen Markus
+# Copyright (C) 2008 Andrew Ross
+#
+# This file is part of PLplot.
+#
+# PLplot is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Library Public License as published
+# by the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# PLplot is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public License
+# along with PLplot; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+#
+
+# --------------------------------------------------------------------------
+# main
+#
+# Generates two kinds of plots:
+# - construction of a cycloid (animated)
+# - series of epitrochoids and hypotrochoids
+# --------------------------------------------------------------------------
+
+proc x27 {{w loopback}} {
+
+ # R, r, p, N
+ set params {
+ { 21.0 7.0 7.0 3.0 }
+ { 21.0 7.0 10.0 3.0 }
+ { 21.0 -7.0 10.0 3.0 }
+ { 20.0 3.0 7.0 20.0 }
+ { 20.0 3.0 10.0 20.0 }
+ { 20.0 -3.0 10.0 20.0 }
+ { 20.0 13.0 7.0 20.0 }
+ { 20.0 13.0 20.0 20.0 }
+ { 20.0 -13.0 20.0 20.0 }}
+
+ # Illustrate the construction of a cycloid
+
+ cycloid $w
+
+ # Loop over the various curves
+ # First an overview, then all curves one by one
+
+ $w cmd plssub 3 3
+
+ for { set i 0 } { $i < 9 } { incr i } {
+ $w cmd pladv 0
+ $w cmd plvpor 0.0 1.0 0.0 1.0
+ spiro $w [lindex $params $i]
+ }
+ $w cmd pladv 0
+ $w cmd plssub 1 1
+
+ for { set i 0 } { $i < 9 } { incr i } {
+ $w cmd pladv 0
+ $w cmd plvpor 0.0 1.0 0.0 1.0
+ spiro $w [lindex $params $i]
+ }
+ # Don't forget to $w cmd plend() to finish off!
+
+ $w cmd plend
+
+}
+
+# ===============================================================
+
+proc cycloid {w} {
+
+ # TODO
+
+}
+
+# ===============================================================
+
+proc spiro {w params} {
+
+ foreach {param1 param2 param3 param4} $params {break}
+
+ set NPNT 20000
+
+ matrix xcoord f [expr {$NPNT+1}]
+ matrix ycoord f [expr {$NPNT+1}]
+
+ # Fill the coordinates
+
+ set windings [expr {int($param4)}]
+ set steps [expr {$NPNT/$windings}]
+ set dphi [expr {8.0*acos(-1.0)/double($steps)}]
+
+ # This initialisation is safe!
+ set xmin 0.0
+ set xmax 0.0
+ set ymin 0.0
+ set ymax 0.0
+
+ set n [expr {$windings*$steps+1}]
+
+ for { set i 0 } { $i < $n } { incr i } {
+ set phi [expr {double($i) * $dphi}]
+ set phiw [expr {($param1-$param2)/$param2*$phi}]
+ xcoord $i = [expr {($param1-$param2)*cos($phi)+$param3*cos($phiw)}]
+ ycoord $i = [expr {($param1-$param2)*sin($phi)-$param3*sin($phiw)}]
+
+ if { $xmin > [xcoord $i] } { set xmin [xcoord $i] }
+ if { $xmax < [xcoord $i] } { set xmax [xcoord $i] }
+ if { $ymin > [ycoord $i] } { set ymin [ycoord $i] }
+ if { $ymax < [ycoord $i] } { set ymax [ycoord $i] }
+ }
+
+ if { $xmax-$xmin > $ymax-$ymin } {
+ set scale [expr {$xmax - $xmin}]
+ } else {
+ set scale [expr {$ymax - $ymin}]
+ }
+ set xmin [expr {- 0.65 * $scale}]
+ set xmax [expr { 0.65 * $scale}]
+ set ymin [expr {- 0.65 * $scale}]
+ set ymax [expr { 0.65 * $scale}]
+
+ $w cmd plwind $xmin $xmax $ymin $ymax
+
+ $w cmd plcol0 1
+ $w cmd plline [expr {$n-1}] xcoord ycoord
+
+}
Property changes on: trunk/examples/tcl/x27.tcl
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|