March 22, 2008
Coping Calculator Upgrade
I've added a couple of tweaks to my world famous
coping calculator which helps you cut a round tube to fit another round tube. It now uses vectors in the pdf version of the pattern, which should print and scale a little better than before.
And there's also another version that
attempts to make the page big enough to put a large pattern on it. It's here:
http://metalgeek.com/static/cope_custom.pcgi
The operation is a little flaky, but it may help somebody.
Posted by Hal Eckhart at
10:15 PM
|
Comments (0)
May 27, 2006
Cut List Formatter
A few years ago, I wrote an
article for Evolt about how to make fractions in a PHP script. Several times since then, I've gone back and pasted an ugly pile of numbers into a version of the script to produce a proper cut list. It would seem like the kind of thing that would be easy enough to do in Excel, but it doesn't really give me a nice looking list, and it just takes too damn many steps anyway. This script took me way too much time to create, but I learned a few more things about PHP in the process.
So here's the form. It will take a random stack of decimal numbers and output a collated, sorted list; rounded to the nearest fraction (1/2 through 1/64). More instructions and source code included.
Cut List Formatter
Posted by Hal Eckhart at
07:05 PM
|
Comments (0)
|
TrackBack
May 07, 2006
Dan Hopper's TUBEFIT Program
About once a month someone asks me for a standalone version of my
Coping Calculator, so they can run it on their computer out in their garage where there are no
internets. Since the script relies heavily on the power of
PHP,
ImageMagick, and
GD, it's not really something that can be easily translated into a separate program. At least not one that I could create.
However,
Dan Hopper has written this little standalone program that's vaguely similar to the
Coping Calculator, but without all the bells and whistles. It runs in a terminal window and sends a postscript file directly to the printer via DOS. I really don't know how to set up a printer in DOS, so I had to find the spooled file (which went to LPT1, but that might just be my problem) and then drag it over to my USB printer. If anybody knows a better method, just
let me know and I'll post your tip.
Dan's coping method differs from mine in that he's designed it to cut the tube with two passes of a power hacksaw, and then grind off the excess. However, the pattern looks very close to mine. For all I know, his math is better. He certainly
explains it better anyway.
Unzip
this file and put the contents wherever you want. The OVL file needs to be in the same folder as the EXE for it to work. It seemed to work for me, but there are no guarantees or promises from either Dan or me that it won't blow something up. Obviously, that's not the intent, but consider yourself warned.
TUBEFIT.zip
(updated 5/19/06)
Derivation of Dan Hopper's TUBEFIT Algorithm
A brief bio of Dan
Posted by Hal Eckhart at
11:05 AM
|
Comments (0)
|
TrackBack
March 13, 2006
DropScript
One of the grooviest things about running a Mac is getting to play with its
Unixy core, because there are
scads of free tools that do scads of cool and useful things. Strangely enough, Apple has never bothered to include one of the coolest tools available in their download list. It's called
DropScript (follow the "DropScript" link for the disk image).
DropScript packages a
shell script into a handy little
droplet that lets you drop a file on it and then passes the filename and the script to the
shell to let it work some magic. Or even
magick.
The DropScript droplets I use the most are ones that convert the ginormous digital photos that I take into reasonable sized ones for emailing clients and friends.
The first one below is a favorite of mine. It resizes any image (or any bunch of images, but not a folder) you drop on it to an 800 pixel maximum width or height, and also swaps any spaces in the filename to underscores and makes it lower case. The image you drop
will be replaced, so use this on a copy of your image, not the original, or
you'll be sorry. The second version does the same thing, but also creates a separate thumbnail.
There are plenty of variations possible just by tweaking these scripts. Just read the linked
man pages for the commands in the scripts. There is likely some clumsiness in my use (or misuse) of the commands in the scripts. I'm not a shell script expert by any stretch of the imagination.
For the following shell script to work, you'll need to have
ImageMagick properly installed. The easiest way to do this is to use Marc Liyanage's ImageMagick
package. Trust me, it's a heck of a lot easier than trying to do it yourself.
Caveats:
This works well if your droplet and the images are in the same place. It can also work between any two folders on your hard drive, but if there are spaces in any of the folder names in the path between the droplet and the images, the renaming won't work. I'm not sure what the mechanics of this are. And if I was smarter, I might be able to figure out how to pass folders of images as well. Perhaps someone could
enlighten me.
Dropscript itself works as a droplet. Save either of the following two sections (starting with
#!/bin/sh and ending with "done") as a plain text file (typically filename.sh), and then just drop it on the DropScript app.
----------------------------------------------------
#!/bin/sh
##
# Converts an image to 800 pixel max size.
# Destroys the original image.
# Changes filenames to lowercase and replaces spaces with "_".
##
for file; do
/usr/local/bin/convert -scale 800x800 -quality 50 "$file" "$file";
mv "$file" `echo "$file" | sed "s/\ /_/g" | tr [:upper:] [:lower:]` ;
done
----------------------------------------------------
#!/bin/sh
##
# Converts an image to 800 pixel max size.
# Destroys the original image.
# Creates a 150 pixel thumbnail with "_tn" appended to its filename.
# Changes filenames to lowercase and replaces spaces with "_".
##
for file; do
/usr/local/bin/convert -scale 800x800 -quality 50 "$file" "$file" ;
/usr/local/bin/convert -scale 150x150 -quality 50 "$file" `echo "$file" | sed "s/\ /_/g" | sed "s/\./_tn./g" | tr [:upper:] [:lower:]` ;
mv "$file" `echo "$file" | sed "s/\ /_/g" | tr [:upper:] [:lower:]` ;
done
----------------------------------------------------
* A
droplet is an old Mac concept that usually refers to an
AppleScript droplet. DropScript isn't Applescript, but it uses the same basic idea.
Posted by Hal Eckhart at
08:12 AM
|
Comments (0)
|
TrackBack
February 26, 2006
How to make the continents on a big metal globe in 10 easy steps
Or maybe not so easy. I had such a hard time figuring this stuff out that I thought somebody else might benefit from my experience. I don't want to drive down business, but a few more big funky metal globes in the world wouldn't be a bad thing. And if you have the wherewithal to do it yourself you probably wouldn't be hiring me anyway.
The following is a rough and incomplete outline of one method of doing this. There are other methods. Easier methods. There are also probably open-source (and free) replacements for Photoshop. I just haven't found one that actually works for this.
Gimp can output the PPMs and convert back to PNG (probably quicker than ImageMagick) but it doesn't create paths and it doesn't open RAW files without a plugin. I couldn't figure out how to make the plugin work, so I gave up. If anybody can really do this (as opposed to saying they know that it should work), just
let me know. I'll try to keep this page updated with anything useful, and you can always add your own notes to the
comments.
This "tutorial" (if you can call it that) assumes that you know your way around the block. I'm too lazy to make this into "The Idiot's Guide for
Globe Construction". However, it should help point you in the right direction or at least give you a few ideas.
Minimum Tool Requirements
Steps
-
Go to the Globe project at NOAA, and get the tiles.
Yes, they are big, but they are free (unless you buy the CDs for $260). One of them is nearly 60 MB, but most are 20 to 30. Better make sure you have either broadband or a whole lot of coffee.
-
Import to PhotoShop and combine the whole thing into one big image.
Lose the irrelevant channels and save the image as a two-color PNG.
Your file will now look sorta like this:
PPM is a very inefficient format, because the file is written as a rectangular grid. A 1.1 MB PNG can become a 667 MB PPM, so make the PNG as few pixels as you can get away with, or the next steps will be really slow.
-
Convert to PPM with ImageMagick like this:
convert in.png out.ppm
And then go have some coffee. Across town. Walk there.
-
Split the PPM into gores with Perl and make_gores.pl
Usage: $0 in.ppm out.ppm number-of-gores
Like this:
perl make_gores.pl in.ppm out.ppm 12
-
Convert back to PNG like this:
convert in.ppm out.png
Your file will now look sorta like this:
-
In Photoshop, create a path by selecting some white, select similar, new path from selection, save path, export path to illustrator, yadda yadda. You may have to screw around with various settings to make it work.
-
Open the path in your CAD program and clean it up. I managed to get the path open with Rhino , but only after saving it with DOS line endings in BBEdit (it doesn't suck™). Otherwise, Rhino wouldn't open it and just crashed.
You will want to be careful to get rid of the tiny islands, or you will have a lot of little dots that you couldn't use even if you could figure out where the heck they go.
You can reduce the detail, but don't get too carried away. Look at Japan and England. They should be more or less recognizable.
Some things may want a little redo. Greenland can generally be one piece, but it gets cut up because it's so close to the North Pole. Either patch it back together in CAD, or go find a map online. It's not hard. And Antarctica. You really don't want 12 or 24 pieces. Find a map and scale it. And then cut maybe 4 darts in it so you can make it spherical.
-
Export to your favorite CAM format and cut it out. I saved the file as a DXF and converted it for my cutter with SheetCam, which is a fantastic cheap 2-1/2D CAM application with G-Code and HPGL output.
-
Hammer your pieces into shape and weld to the globe's frame.
Which might look sorta like this:
This 8 foot CorTen steel globe (to eventually be part of a sculpture in front of my building when I have time) was made with 24 gores. It should have really been more, or perhaps segmented somehow, so that there were more segments near the equator. Oh well. Next time maybe. And maybe thicker material (this was 11 ga.) would have helped. The North America on the wall above the globe was 1/4" stainless (same scale) that I did as a test. It came out remarkably smooth, although it's higher up from the equator, so the width of the pieces was less.
-
There is no step 10. Unless you want to go back to the coffee shop. You don't have to walk this time. You can ride your bike.
Ancient History
The first globe with continents that I was hired to make was a challenge and a bit of a nightmare. It was a large globe (16 feet across and 10 feet tall, to make a little room in a theme restaurant bar), so I thought I could just beat some aluminum into shape and piece it together. After an hour of hammering, I was so frustrated that I was ready to cry. I'd made a huge amount of noise and an unsightly lump in a 4' x 10' sheet, but there was no way it was going to be usable. I didn't have a clue what to try next.
I ending up making 1/12th vertical gores about 4 feet wide with horizontal darts in the edges about every 16 inches. Then, after hammering and welding them into shape, I eyeballed the continents from a 12" globe and cut everything out. It was a ludicrous amount of work, and the result wasn't as smooth as it should have been.
Here it is.
A couple of years later, I got asked to do the same exact thing again. In the interim, I'd built a
CNC plasma cutter, so I imagined I could cut it out easier. Since I couldn't figure out where to find good geographic information, I used the same 12" globe, traced the continents on vellum, and scanned it into the computer. I then had to manually draw all the shorelines, which was another fantastically labor-intensive task. And thus, my lifelong hatred of CorelDraw.
Finding a way to import the basic geographic data without a lot of hand work has been the global holy grail for me. The process isn't perfect yet, but it's a whole hell of a lot better than my first pass.
* Can't I just open the path in Illustrator and save it as a DXF?
Don't bother.
For whatever idiotic reason, Adobe Illustrator has seen fit to export its DXF files with only Macintosh style (\r) line-endings. This is completely insane, because 99% of CAD programs that people actually use run on Windoze, and most of them will only read Windoze (\r\n) or Unix (\n) style line endings. So if you want to open the friggin file, you have to run it through a line-ending converter. Yes, they're easy and available everywhere, but it's not something that the ordinary guy is going to know about. And it's completely avoidable. For Chrissakes, a DXF file is supposed to be "a CAD data file format, developed by Autodesk as their solution for enabling data interoperability between AutoCAD and other programs." Since AutoCAD won't even run on a Mac, what the hell is the point of a DXF with Mac line endings? I don't know what they're smoking, but I want some of it.
To make matters worse, every curve is written as a
spline, which often causes problems with CAD/CAM systems. And the only way to fix this in Illustrator involves turning the whole thing into about a zillion tiny little straight lines. Which will frequently cause other CAD/CAM issues. Sheesh.
However, Illustrator does have some nice features. It can simplify curves and reduce points, which is helpful. If you have it and can deal with the problems, it might be helpful after all.
(This applies to the Mac version of Illustrator CS. I have no idea what the latest version does.)
And finally, if there was a decent CAD program that would just import
SVG files, all of this bitching would likely be irrelevant.
Posted by Hal Eckhart at
10:00 PM
|
Comments (6)
|
TrackBack
February 22, 2006
The Universal Tube Coping Calculator
There's now only one version of my
Tube Coping Calculator. Trying to maintain various versions scattered all over
the internets was too confusing, and it seems that Google doesn't like content that appears to be nearly indentical. It will be interesting to see if it breaks.
Update:
I've hacked it to save your last entered info in a
cookie. Cookie/form/PHP tutorial to follow.
Posted by Hal Eckhart at
10:36 PM
|
Comments (0)
|
TrackBack
January 21, 2006
Dreamhost webhosting
I love Dreamhost. Sometimes. One time was today, when I realized that someone completely unknown to me had followed some link that I totally forgot about and then
signed up for Dreamhost. So I get $97 credited to my account. That's about 5 times more than I've made off the web. Ever. That was when one guy I tried to help out with one of my
goofy scripts forked out $20 via Paypal. Mostly though, what I've earned was not even a thank you when I've tried to help some poor confused soul who doesn't quite get it.

Well screw 'em. I'm going
commercial. Just look at the irritating flashing button above if you doubt it. Like you could avoid it. I want to see if I can pre-pay my webhosting bill through 3006. Now that I'm pushing 50, I need to start thinking about what happens when my arms wear out and I can't swing a
hammer any more.
Before I get accused of trying to con people into
buying one of Dreamhost's plans (and making myself filthy rich) under false pretenses, let's discuss a few of the problems I've had in the past several years with Dreamhost.
The Bad
Occasional hardware failures.
This has led to problems, but usually not more than an hour or two. The only time I recall it being more than that was during a major
DDoS attack (not really hardware related, I suppose), which seemed like it lasted for about a day (where the site and email was intermittent). And then of course, there was the big LA blackout, which killed off almost everybody out there.
Relatively slow/bad/inattentive tech support
It can take 24 hours for them to get back to you. And it can frequently take a couple of tries before someone who really knows whats going on takes charge of the situation. The really cheap plan doesn't have any phone support at all, so if this is a big deal to you, consider the next level, which is still only 16 bucks a month. But I'm still taking my chances at the $8 a month level. Until a few more of you
suckers wise shoppers
take the plunge and I can afford to upgrade.
As always, it's a lot easier to get questions answered by a smart person before you sign up.
Rare but catastrophic dumbass mistakes
This was really the only big problem I've had with these guys. At some point after the big DDoS attack, I started losing email sporadically. After a lot of back and forth with the slow tech support, someone finally delved into it. They discovered that someone had managed to delete the mailq on one of the servers that handled my email. This resulted in the email going straight to the
bit bucket. Because it was received and instantly deleted, the sender didn't even get a bounce. I had several important requests from clients that just disappeared without a trace.
This sort of thing will probably be a dealbreaker for a lot of people, but I think it's just an issue you're going to have to deal when you get webhosting for $100 a year.
The Good
Despite the downsides, it does have a lot of upsides. Lots of diskspace and bandwidth, but big whoopdeedoo. They have great support for
PHP and
MySQL. You can even install your custom versions if you have the patience for that sort of thing. Also, shell accounts,
Ruby,
SSI,
CVS (no, not
Cyclic Vomiting Syndrome), and more. If you really care about the nitty-gritty, just look at
this.
My single favorite geeky thing is being able to execute system commands right from within PHP, so if you want to do something like turn a
postscript file into a PDF, it's as freaky simple as:
$convert_pdf =
` convert $_SERVER[DOCUMENT_ROOT]/$file.ps $_SERVER[DOCUMENT_ROOT]/$file.pdf `;
echo $convert_pdf;
Of course you also have to name your script with a
pcgi extension and make sure the
permissions are right, but you probably already knew that.
Finally
So go ahead and
sign up for Dreamhost. It's a pretty good deal for the money. Probably.
Just don't say I didn't warn you.
Posted by Hal Eckhart at
11:27 AM
|
Comments (1)
|
TrackBack
November 26, 2005
Tube Coping Calculator - the metric version
Updated:
This file now lives here:
Tube Coping Calculator
Posted by Hal Eckhart at
12:52 PM
|
Comments (1)
|
TrackBack
June 05, 2004
Regular Expressions
The interesting part of the little
translator that I just posted is a couple of
regular expressions. As the O'Reilly description says "
Regular expressions are an extremely powerful tool for manipulating text and data." The syntax can a little confusing, but they are amazing useful, and any effort you put into learning them will be richly rewarded.
PHP makes good use of standard
Perl-Compatible Regular Expressions, although there are a few differences in how you feed strings to it, and get results back from it.
So, here's a basic explanation of one cryptic bit of the script; the part in red, below.
preg_match ("/pu *(-?\d+)[ ,]+(-?\d+)/i", $my_text2[$key], $match)
"
/
pu *
(
-?\d+
)
[ ,]+
(-?\d+)
/i"
So preg_match searches $my_text2 for the first two identifiable numbers after "pu" or "PU", and puts the result into $match[1] and $match[2].
Posted by Hal Eckhart at
10:11 AM
|
Comments (0)
|
TrackBack
June 03, 2004
HPGL to G-Code Translator
This script will translate simple HPGL-1 (as exported via CorelDraw) into basic RS274NGC (G-Code). Only pen-up (PU) and pen-down (PD) commands with two numbers separated by a space and then a line break are translated.
For example:
PU0 0;
PD0 22;
PD-1 44;
PD-3 65; and so on.
Posted by Hal Eckhart at
06:06 PM
|
Comments (1)
|
TrackBack
HPGL to G Translator Source
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>HPGL to G-Code Translator</title>
<style type="text/css" media="all">
@import "style1.css";
span.g0 { color: #00b; }
span.g1 { color: #070; }
span.m2 { color: #d00; }
div.text{ width: 6in; }
h1 { font-size: 140%; }
</style>
</head>
<body>
<?php
$uri = $_SERVER["SCRIPT_URI"]; $self = $_SERVER["PHP_SELF"]; $dec = $_POST['dec']; $scale = $_POST['scale']; if ($dec < .1 || $dec > 16) {$dec = 5;} if ($scale < 1) {$scale = 1016; } $uploaded = $_FILES['my_text']['name'];
if (!$uploaded){
echo '
<h1>HPGL to G-Code Translator</h1>
<div class="text">
This script will translate simple HPGL-1 (as exported via CorelDraw) into basic RS274NGC (G-Code). Only pen-up (PU) and pen-down (PD) commands with two numbers separated by a space and then a line break are translated.
<br /><br />
For example:<br /><br />
PU0 0;<br />
PD0 22;<br />
PD-1 44;<br />
PD-3 65; and so on.
<br /><br /></div>
<form enctype="multipart/form-data" action="' . $self . '" method="post">
<div>
input resolution: <input type="text" maxlength="5" size="5" name="scale" value="' . $scale . '" />
<br />
number of decimals: <input type="text" maxlength="2" size="3" name="dec" value="' . $dec . '" />
<br /><br />
<input type="hidden" name="MAX_FILE_SIZE" value="40000" />
<input name="my_text" type="file" />
<br />
<input type="submit" value="Translate" />
</div>
</form>';
}
else
{
echo "<div>( Simple RS274NGC translated from HPGL by $uri )
<br />
( Direct any complaints and suggestions to Hal Eckhart at gff5o6j02@sneakemail.com )
<pre>
";
$dec = "%01." . $dec . "f"; $my_text = @file_get_contents($_FILES['my_text']['tmp_name']) ; $my_text = str_replace ( array ("p", "P"),
array ("\np", "\nP"), $my_text );
$my_text2 = explode ("\n", $my_text); while (!is_null($key = key($my_text2) ) ) {
if (preg_match ("/pu *(-?\d+)[ ,]+(-?\d+)/i", $my_text2[$key], $match)) {
echo "\n<span class=\"g0\">G00 x".sprintf("$dec", $match[1]/$scale)." y".sprintf("$dec", $match[2]/$scale)."</span>\n";
}
elseif (preg_match ("/pd *(-?\d+)[ ,]+(-?\d+)/i", $my_text2[$key], $match)) {
echo "<span class=\"g1\">G01 x".sprintf("$dec", $match[1]/$scale)." y".sprintf("$dec", $match[2]/$scale)."</span>\n";
}
next($my_text2);
}
echo "\n\n<span class=\"m2\">M02</span> </pre></div>";
}
?>
</body>
</html>
Posted by Hal Eckhart at
06:02 PM
|
Comments (0)
|
TrackBack
April 22, 2004
Technorati fault tolerance hack
Technorati seems like a pretty cool idea, but they've been having some growing pains lately. I found that if you use their default javascript method to insert their link, it can hang up loading your blog if Technorati is unavailable.
Here's a PHP way to insert some fault tolerance for any off-site link.
Thoughts?
<?php
$fp = fsockopen("www.technorati.com", 80, $errno, $errstr, 5);
if ($fp) {
echo "<script language=\"javascript\" type=\"text/javascript\"
src=\"http://technorati.com/embed/(your #).js\">
</script>";}
?>
Posted by Hal Eckhart at
05:46 PM
|
Comments (0)
|
TrackBack
April 17, 2004
Crate Cut-List Calculator
Here's something I've been working on intermittently for about 14 years. It's a little script that takes three dimensions and builds a crate to fit them. You can also change the default lumber size, toggle spacing, and a couple of clearance dimensions.
As usual, this probably isn't as interesting for what it does, as for what it illustrates. In addition to calculating and collating a cut list, pictures of the pieces are drawn and dimensioned so you can see what you're asking for. That's also pretty handy when you get to construction.
Some of the terminology comes from building flats for the theater.
Source for Crate Cut-List Calculator
Posted by Hal Eckhart at
11:19 AM
|
Comments (1)
|
TrackBack
April 10, 2004
Pseudo Gear Generator
I was feeling frustrated with trying to draw a gear (of sorts) in a graphics program, so I hacked my
ellipse script to oscillate a specified distance on either side of the diameter. Yah, you betcha. It does actually work.
If anyone actually wants to see the source, just
let me know.
processed 99 lines cutting area - 2.2" by 2.2"
Posted by Hal Eckhart at
12:17 PM
|
Comments (1)
|
TrackBack
April 03, 2004
Tube Coping Calculator (again)
Updated:
This file now lives here:
Tube Coping Calculator
Posted by Hal Eckhart at
06:08 PM
|
Comments (0)
|
TrackBack
March 30, 2004
PHP Pigmentator
The following was tweaked for PHP 5 with
this guy's help.
PHP's
highlight_file function is a quick and dirty way to
basic
syntax coloring, which can make your code a
lot easier to read. The dirty part is its egregious use of icky invalid (at
least for XHTML) font tags.
Some of the user contributed notes explain various methods for fixing this.
I've cobbled together a few of these and tweaked them to get rid of the
non-breaking spaces, which seem to make a mess of copying and pasting the code.
Us lazy people hate to type when we don't have to. The downside is that we have
to use a <pre> tag, so it won't wrap nicely. If you don't like really
wide pages, then you'd better hard wrap your code before you feed it to the
colorizer.
If you feed this beast some code, it will spit it back to you in two versions.
First, colorized and rendered in the browser, and then as raw XHTML in a text
box, ready to be copied and pasted into a page. At the bottom of the page is
the CSS style declaration used to colorize the spans produced by this script.
CSS style declaration
div.phpcode span.html { color: #000; }
div.phpcode span.default { color: #00b; }
div.phpcode span.keyword { color: #070; }
div.phpcode span.string { color: #d00; }
Posted by Hal Eckhart at
04:39 PM
|
Comments (5)
|
TrackBack
PHP Pigmentator source
<?php
$uploaded = $_FILES['my_text']['name'];
if (!$uploaded){
echo '
<div class="phpcode">
PHP\'s <a href="http://www.php.net/manual/en/function.highlight-file.php">
highlight_file </a> function is a quick and dirty way to <span class="comment">
achieve </span> <span class="default"> basic </span> <span class="keyword">
syntax </span><span class="string"> coloring</span>, which can make your code a
lot easier to read. The dirty part is its egregious use of icky invalid (at
least for XHTML) font tags.
<br />
<br />
Some of the user contributed notes explain various methods for fixing this.
I\'ve cobbled together a few of these and tweaked them to get rid of the
non-breaking spaces, which seem to make a mess of copying and pasting the code.
Us lazy people hate to type when we don\'t have to. The downside is that we have
to use a <pre> tag, so it won\'t wrap nicely. If you don\'t like really
wide pages, then you\'d better hard wrap your code before you feed it to the
colorizer.
<br />
<br />
If you feed this beast some code, it will spit it back to you in two versions.
First, colorized and rendered in the browser, and then as raw XHTML in a text
box, ready to be copied and pasted into a page. At the bottom of the page is
the CSS style declaration used to colorize the spans produced by this script.
<br />
<br />
<br />
<form enctype="multipart/form-data" action="';
echo $_SERVER["PHP_SELF"];
echo'" method="post">
<div>
<input type="hidden" name="MAX_FILE_SIZE" value="40000" />
<input name="my_text" type="file" />
<br />
<input type="submit" value="Feed Me!" />
</div>
</form>
</div>';
}
else
{
echo "<h2>highlighted source of: $uploaded </h2> <ins><hr /></ins>";
ini_set('highlight.comment', 'comment');
ini_set('highlight.default', 'default');
ini_set('highlight.keyword', 'keyword');
ini_set('highlight.string', 'string');
ini_set('highlight.html', 'html');
function highlight_php($code, $return = FALSE)
{
ob_start();
highlight_string($code);
$highlighted = ob_get_contents();
ob_end_clean();
$highlighted = '<div class="phpcode">' . str_replace(
array(
'<code>',
'</code>',
'style="color: ',
'<br />',
' '
),
array(
"<pre><code>",
"</code></pre>",
'class="',
"\n",
' '
),
$highlighted
) . '</div>';
if ($return) { return $highlighted; }
else { echo $highlighted; }
}
ob_start();
@highlight_php(join("", file($_FILES['my_text']['tmp_name'])));
$highlighted2 = ob_get_contents();
ob_end_clean();
echo $highlighted2;
if ($uploaded){
echo '<h2>Encoded XHTML:</h2><textarea name="my_text" rows="25" cols="55" id="my_text">';
echo htmlentities($highlighted2);
echo '</textarea>';
}
}
echo '<br /><h2>CSS style declaration</h2>
<div class="phpcode">
<span class="html">div.phpcode span.html { color: #000; }</span><br />
<span class="comment">div.phpcode span.comment { color: #f80; }</span><br />
<span class="default">div.phpcode span.default { color: #00b; }</span><br />
<span class="keyword">div.phpcode span.keyword { color: #070; }</span><br />
<span class="string">div.phpcode span.string { color: #d00; }</span><br />
<br /></div>';
?>
Posted by Hal Eckhart at
03:58 PM
|
Comments (0)
|
TrackBack
March 27, 2004
Ellipse generator
Yet another in my series of
thingies rather crudely copy/pasted from an
old project of mine.
Here's a thing that draws ellipses (or circles, if you do it right) and even outputs paths for cutting them. Use at your own risk. Especially if you have a loose grip on your marbles.
Source:
<div class="deftext">
Here's a thing that draws ellipses (or circles, if you do it right) and even outputs paths for cutting them. Use at your own risk. Especially if you have a loose grip on your marbles.
<br />
<ins><hr /></ins>
</div>
<table border="0" cellpadding="0"><tr><td class="top">
<?php
$dupx = $_POST['dupx']; $dupy = $_POST['dupy']; $rectx = $_POST['rectx']; $recty = $_POST['recty']; $kerf = $_POST['kerf']; $clear = $_POST['clear']; $res = $_POST['res']; $tried = $dupx || $dupy;
if ($tried) {
$dupx=intval($dupx);
$dupy=intval($dupy);
}
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<table class="inputtable">
<tr><th class="red-s">(decimal inches only)</th></tr>
<tr><td>Ellipse width </td><td><input type="text" maxlength="5" size="5" name="rectx" value="<?php if ($rectx<.1){$rectx = 1;echo $rectx; }else {echo $rectx;} ?>" /></td></tr>
<tr><td>Ellipse height </td><td><input type="text" maxlength="5" size="5" name="recty" value="<?php if ($recty<.1){$recty = 2;echo $recty; }else {echo $recty;} ?>" /></td></tr>
<tr><td>Horizontal repeat<br />
max = 8 </td><td><input type="text" maxlength="2" size="3" name="dupx" value="<?php if ($dupx<1 or $dupx>8){$dupx = 2;echo $dupx; }else {echo $dupx;} ?>" /></td></tr>
<tr><td>Vertical repeat<br />
max = 8 </td><td><input type="text" maxlength="2" size="3" name="dupy" value="<?php if ($dupy<1 or $dupy>8){$dupy = 1;echo $dupy; }else {echo $dupy;} ?>" /></td></tr>
<tr><td>Cutter kerf offset </td><td><input type="text" maxlength="5" size="5" name="kerf" value="<?php if ($kerf<.0001){$kerf = .03;echo $kerf; }else {echo $kerf;} ?>" /></td></tr>
<tr><td>Spacing for multiples </td><td><input type="text" maxlength="5" size="5" name="clear" value="<?php if ($clear<.01){$clear = .375;echo $clear; }else {echo $clear;} ?>" /></td></tr>
<tr><td>Resolution </td><td><input type="text" maxlength="4" size="5" name="res" value="<?php if ($res<1){$res = 1000;echo $res; }else {echo $res;} ?>" /></td></tr>
</table>
<p><input type="hidden" name="tried" value="yes" />
<input type="submit" value="<?php echo $tried ? 'recalculate' : 'calculate'; ?>" />
</p></form>
<?php
$clear = $clear*$res;
$lead = 100;
$kerf2 = $kerf*2;
$kerfz = $kerf*$res*$zoom2;
$rad = ($rectx+$kerf2)/2;
$rad2 = ($recty+$kerf2)/2;
$rectx = ($rectx+$kerf2)*$res;
$recty = ($recty+$kerf2)*$res;
$seg = pi()/round(128