Popular Tcl recipes tagged "graphics"http://code.activestate.com/recipes/langs/tcl/tags/graphics/2005-06-19T23:51:07-07:00ActiveState Code RecipesShellsort (Tcl) 2005-06-19T23:51:07-07:00Alexander Kruzlikhttp://code.activestate.com/recipes/users/2489967/http://code.activestate.com/recipes/426106-shellsort/ <p style="color: grey"> Tcl recipe 426106 by <a href="/recipes/users/2489967/">Alexander Kruzlik</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>Below is the basic shell sort algorithm.</p> Generating random intergers within a range of max & min. (Tcl) 2003-03-04T09:58:21-08:00Dom Lamhttp://code.activestate.com/recipes/users/1023440/http://code.activestate.com/recipes/186512-generating-random-intergers-within-a-range-of-max-/ <p style="color: grey"> Tcl recipe 186512 by <a href="/recipes/users/1023440/">Dom Lam</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>Here's an example on how to generate a random number between 2 numbers Based on C code, algorithm = randomNumber % ((max + 1) - min) + min Here's the tcl version using rand(): *note Change 100 to 1000 if you want a random number that goes into thousands. etc.. Also the rand() function generates a number between 0 &amp; 1. That's why one would multiply by 10 or 100 or 1000, etc..</p> Inserts thousand separators into a number (Tcl) 2002-08-22T15:58:31-07:00andreas kuprieshttp://code.activestate.com/recipes/users/117230/http://code.activestate.com/recipes/146220-inserts-thousand-separators-into-a-number/ <p style="color: grey"> Tcl recipe 146220 by <a href="/recipes/users/117230/">andreas kupries</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>This piece of code inserts a thousandth separator into a decimal number, i.e. every 3 digits the separator character is inserted. courtesy Jeff Hobbs's bag of utilities.</p> Normally Distributed Random Numbers (Tcl) 2002-08-06T15:34:35-07:00William Kappelehttp://code.activestate.com/recipes/users/257378/http://code.activestate.com/recipes/143083-normally-distributed-random-numbers/ <p style="color: grey"> Tcl recipe 143083 by <a href="/recipes/users/257378/">William Kappele</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>This recipe produces random numbers from a normal (bell-shaped) distribution. (The rand() command in Tcl produces uniformly distributed random numbers.)</p> Largest int supported by a platform, and the number of bits per int (Tcl) 2002-08-21T16:24:52-07:00andreas kuprieshttp://code.activestate.com/recipes/users/117230/http://code.activestate.com/recipes/146035-largest-int-supported-by-a-platform-and-the-number/ <p style="color: grey"> Tcl recipe 146035 by <a href="/recipes/users/117230/">andreas kupries</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>Two procedures from the bag of utilities used by Jeff Hobbs. The first computes the largest integer supported by Tcl on the platform it is run on. The second computes the number of bits in that integer.</p> Find smallest square to fit input. (Tcl) 2002-08-21T16:29:28-07:00andreas kuprieshttp://code.activestate.com/recipes/users/117230/http://code.activestate.com/recipes/146036-find-smallest-square-to-fit-input/ <p style="color: grey"> Tcl recipe 146036 by <a href="/recipes/users/117230/">andreas kupries</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>A procedure from the bag of utilities used by Jeff Hobbs. Given an integer number it finds the smallest square greater than the input. A possible application for this is when a discrete number of items have to be displayed in a table. Using this returns the number of columns/rows for the table to fit all items.</p> Adding numbers in arbitrary bases. (Tcl) 2002-08-22T16:16:22-07:00andreas kuprieshttp://code.activestate.com/recipes/users/117230/http://code.activestate.com/recipes/146222-adding-numbers-in-arbitrary-bases/ <p style="color: grey"> Tcl recipe 146222 by <a href="/recipes/users/117230/">andreas kupries</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>The command adds two numbers in any base that can be expressed as a string of unique symbols. From Jeff Hobbs's bag of utilities, original author is John Ellson &lt;ellson@lucent.com&gt;.</p> Convert HSV colorspace to RGB (Tcl) 2002-06-17T16:08:36-07:00andreas kuprieshttp://code.activestate.com/recipes/users/117230/http://code.activestate.com/recipes/133527-convert-hsv-colorspace-to-rgb/ <p style="color: grey"> Tcl recipe 133527 by <a href="/recipes/users/117230/">andreas kupries</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>Author: Jeff Hobbs.</p> <p>Converts a color specified as Hue, Saturation and Value into an RGB triple. The result can be processed by "dec2rgb" (See recipe "Color Manipulation").</p> Functional imaging (Tcl) 2002-06-17T15:00:37-07:00andreas kuprieshttp://code.activestate.com/recipes/users/117230/http://code.activestate.com/recipes/133502-functional-imaging/ <p style="color: grey"> Tcl recipe 133502 by <a href="/recipes/users/117230/">andreas kupries</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>Origin: <a href="http://wiki.tcl.tk/3523" rel="nofollow">http://wiki.tcl.tk/3523</a> Author: Richard Suchenwirth</p> <p>Cameron Laird pointed me to Conal Elliott's Pan project ("Functional Image Synthesis", [http://research.microsoft.com/~conal/papers/bridges2001/]), where images (of arbitrary size and resolution) are produced and manipulated in an elegant functional way. Functions written in Haskell (see Playing Haskell) are applied, mostly in functional composition, to pixels to return their color value. FAQ: "Can we have that in Tcl too?" As the funimj demo below shows, in principle yes; but it takes some patience (or a very fast CPU) - for a 200x200 image the function is called 40000 times, which takes 9..48 seconds on my P200 box. Still, the output often is worth waiting for... and the time used to write this code was negligible, as the Haskell original could with few modifications be represented in Tcl. Functional composition had to be rewritten to Tcl's Polish notation - Haskell's</p> <p>foo 1 o bar 2 o grill</p> <p>(where "o" is the composition operator) would in Tcl look like o {foo 1} {bar 2} grill</p> <p>As the example shows, additional arguments can be specified; only the last argument is passed through the generated "function nest": proc f {x} {foo 1 [bar 2 [grill $x]]}</p> <p>But the name of the generated function is much nicer than "f": namely, the complete call to "o" is used, so the example proc has the name "o {foo 1} {bar 2} grill"</p> <p>which is pretty self-documenting ;-)</p> Color Manipulation (Tcl) 2002-06-17T16:12:16-07:00andreas kuprieshttp://code.activestate.com/recipes/users/117230/http://code.activestate.com/recipes/133529-color-manipulation/ <p style="color: grey"> Tcl recipe 133529 by <a href="/recipes/users/117230/">andreas kupries</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>Author: Jeff Hobbs</p> <p>A number of routines to convert and manipluate colors.</p> Dragon Curve (Tcl) 2002-06-11T15:39:26-07:00andreas kuprieshttp://code.activestate.com/recipes/users/117230/http://code.activestate.com/recipes/132605-dragon-curve/ <p style="color: grey"> Tcl recipe 132605 by <a href="/recipes/users/117230/">andreas kupries</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>Origin: <a href="http://wiki.tcl.tk/3349" rel="nofollow">http://wiki.tcl.tk/3349</a> Author: Keith Vetter</p> <p>Here's a quick and dirty rendering of the Dragon Curve or Paper Folding fractal. What happens if you repeatedly fold a piece of paper in half numerous times then unfold it once 90 degrees, then again 90 degrees and so on. You get a fractal curve which has several interesting properties. For example, you can combine 4 of these curves and not only will they not overlap but they fill the plane. For more details see <a href="http://www.math.okstate.edu/mathdept/dynamics/lecnotes/node17.html" rel="nofollow">http://www.math.okstate.edu/mathdept/dynamics/lecnotes/node17.html</a></p> Convert HLS colorspace to RGB (Tcl) 2002-06-17T16:10:13-07:00andreas kuprieshttp://code.activestate.com/recipes/users/117230/http://code.activestate.com/recipes/133528-convert-hls-colorspace-to-rgb/ <p style="color: grey"> Tcl recipe 133528 by <a href="/recipes/users/117230/">andreas kupries</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>Author: Frederic Bonnet</p> <p>Converts a color in HLS to a RGB triple. The triple can be processed by "dec2rgb" (See recipe "Color Manipulation").</p> Octabug, 3D to 2D transformation (Tcl) 2002-06-17T15:37:20-07:00andreas kuprieshttp://code.activestate.com/recipes/users/117230/http://code.activestate.com/recipes/133526-octabug-3d-to-2d-transformation/ <p style="color: grey"> Tcl recipe 133526 by <a href="/recipes/users/117230/">andreas kupries</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>Origin: <a href="http://wiki.tcl.tk/3494" rel="nofollow">http://wiki.tcl.tk/3494</a> Author: Keith Vetter</p> <p>This is a fun little graphical animation which morphs an octahedron into an open cuboctahedron and back. Hidden within this code is actually a simple 3-d to 2-d transformation package.</p> Converting numbers from arbitrary bases (Tcl) 2002-06-17T15:12:58-07:00andreas kuprieshttp://code.activestate.com/recipes/users/117230/http://code.activestate.com/recipes/133524-converting-numbers-from-arbitrary-bases/ <p style="color: grey"> Tcl recipe 133524 by <a href="/recipes/users/117230/">andreas kupries</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>Origin: <a href="http://wiki.tcl.tk/1067" rel="nofollow">http://wiki.tcl.tk/1067</a> Author: Michael A. Cleverly</p> <p>The other day someone on <a href="http://OpenACS.org" rel="nofollow">OpenACS.org</a> asked [http://openacs.org/bboard/q-and-a-fetch-msg.tcl?msg_id=0000k2&amp;topic_id=11&amp;topic=OpenACS] for a Tcl proc that would convert a base-62 number into a base-10 integer. I replied with a version I'd written. Here is a slightly expanded one. convert_number employs some Salt and Sugar which I quite like.</p> <p>(One caveat is that base_n_to_decimal will either return an incorrect answer or generate an error for really large numbers that are &gt; than 2147483647.)</p> Conversion to Roman Numerals (Tcl) 2001-09-10T19:05:52-07:00George Jemptyhttp://code.activestate.com/recipes/users/129941/http://code.activestate.com/recipes/68379-conversion-to-roman-numerals/ <p style="color: grey"> Tcl recipe 68379 by <a href="/recipes/users/129941/">George Jempty</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). Revision 5. </p> <p>Takes an integer between 1 and 3999 and converts it to Roman Numerals</p> Random number in a range (Tcl) 2001-09-10T11:25:18-07:00Jeff Hobbshttp://code.activestate.com/recipes/users/98167/http://code.activestate.com/recipes/68391-random-number-in-a-range/ <p style="color: grey"> Tcl recipe 68391 by <a href="/recipes/users/98167/">Jeff Hobbs</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>Tcl 8.0 added the rand() expr function. Here's a simple way to return the random number in a range.</p> CanvasToImg (Tcl) 2001-09-12T14:50:33-07:00Paul Obermeierhttp://code.activestate.com/recipes/users/130521/http://code.activestate.com/recipes/68411-canvastoimg/ <p style="color: grey"> Tcl recipe 68411 by <a href="/recipes/users/130521/">Paul Obermeier</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>Save the contents of a canvas to an image file.</p> Convert (La)TeX math expressions to Tk Images on the fly (Tcl) 2001-09-11T05:24:09-07:00Donal Fellowshttp://code.activestate.com/recipes/users/99497/http://code.activestate.com/recipes/68398-convert-latex-math-expressions-to-tk-images-on-the/ <p style="color: grey"> Tcl recipe 68398 by <a href="/recipes/users/99497/">Donal Fellows</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>This code takes a TeX or LaTeX math expression and converts it into a Tk image suitable for placing in any suitable widget. This technique is ideal for complex documentation where you don't want to maintain a separate set of image files, but is not really fast enough for interactive use (unless your machine is much faster than mine.)</p>