Wiki

Reso-nance numérique | Arts et cultures libres

Outils du site


Panneau latéral

projets:laserbox-parametrique:accueil

Laserbox paramétrique

Description

De passage au 8Fablab de Crest ou nos acolytes de BrutPop sont en vadrouille…
Essai de boite laser en CP pour les capteurs de la brutbox avec de jolies arrondies.
Le fichier .ps est paramétrique, en l'ouvrant avec un éditeur de texte on peut changer la taille de la boite et des arrondis…

Le Code

%!PS
%
% flexbox.ps
% A 3 piece flexible box that can be laser cut from semi-rigid materials
%
% Edited my Tom Speller (@Seithing)
%
% V1.3 by Tom
% change log and updates on thingiverse   - http://www.thingiverse.com/thing:619365
%
% Originaly
% by Brian Dahlem 						  - http://www.thingiverse.com/thing:17240
% based on the simple box - type 2 by FdS - http://www.thingiverse.com/thing:14018
% using the sninge technique from snijlab - http://www.thingiverse.com/thing:12707

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The following lines define basic information about your box, change as necessary

% Define basic measurement units -- don't change put the desiered unit in the unit var below
/inch 72 def
/cm 28.3465 def
/mm 2.83465 def

/unit mm def %selects what unit is used in the following vars + the text (selection about)

% Define box parameters -- This is the size of the box you want
/boxlength 60 unit mul def         % long dimension of flat side of the box
/boxwidth 60 unit mul def          % dimension across the hinge
/boxheight 60 unit mul def         % short dimension across flat side of the box
/cornerradius 15 unit mul def        % radius of the hinge. Suggested min 15mm
/materialthickness 3 unit mul def % thickness of the material which will become the box walls
/tabwidth materialthickness 2 mul def		  % suggested width of tabs in the joints

/fingerTab 0 unit mul def %finger hole for opening box, set to 0 for none. 12 is a good size for a finger
/fingerinset 5 unit mul def %offset to move the center of the circle. 5 is a good offset for a finger

% Define the laser cutter page size A3 420x290mm
/pagewidth 420 unit mul def
/pageheight 290 unit mul def


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Here down is the code that makes your pretty little box, change only if you dare.
%
% Warning... it gets ugly ahead

% setup the page
<< /PageSize [pagewidth pageheight] >> setpagedevice % Set the pagesize, only sometimes works?  Good enough for gov't

/border materialthickness def   % Move away from the edge of the material, for that nice scorched edges goodness
0 pageheight translate
1 -1 scale
border border translate

% 0 - 1 for colour

% outside cut colour
/outR 0 def
/outG 0 def
/outB 0 def

% hinge cut colour due to the way my laser software works it tries to cut the outside before the inside. 
% making it different colours mean I can set the cut manauly
/hingeR 1 def
/hingeG 0 def
/hingeB 0 def

0.01 setlinewidth        % Setup to make vector cuts with hairline thickness (just enough to see)
outR outG outB setrgbcolor     % Use black for cutouts, because that makes the most sense

% draw a rectangle
/box {                % Draw a box with a given width and height from the current location
  /height exch def
  /width exch def

  0 height rlineto
  width 0 rlineto
  0 height neg rlineto
  width neg 0 rlineto  
} def

% Some basics...
/min { 2 copy gt { exch } if pop } bind def
/max { 2 copy lt { exch } if pop } bind def
/pi 3.14159 def

% Define some features of the box
/innerradius cornerradius materialthickness sub def  % The radius of the corners minus the thickness of the material
/tablen materialthickness def                        % How tall to make tabs
/toplen boxlength cornerradius 2 mul sub def         % How long is the top / bottom side
/frontheight boxheight tablen 2 mul sub def          % How tall is the front face, minus tabs
/frontwidth boxlength tablen 2 mul sub def           % How wide is the front face, minus tabs
/sideheight boxheight cornerradius 2 mul sub def     % How tall are the sides, not counting hinges
/hingelen innerradius 2 div pi mul def               % How long is a flattened out hinge (the circumference of 1/4 inner radius)

/breaklen materialthickness 2 div def                % How long should breaks in the hinge lines be
/numhingelines boxwidth 96 div ceiling def           % How many segments should there be in a hinge line
/winglen toplen 2 div hingelen 2 mul sideheight add add def  % How long a wing of the drawing is when drawn out flat

%for the tabs at the base (between the wings).
/numtabsbase toplen tabwidth div 2 div floor 2 mul 1 add def  % How many tabs (odd number) connect the bottom to the front
/tabsizebase toplen numtabsbase div def                           % How big are those tabs

%finger tab maths
%see if fingerTab is greater then 0. if so add hole
fingerTab 0 gt {
  /x fingerTab fingerinset sub def %work out how far form the edge of the circle the sagitta is
  /y 2 2 fingerTab mul x mul x 2 exp sub sqrt mul def % the maths that calulates the offset, some how works.
  /changeangle fingerinset y 2 div atan def %angle to +/- from arc to move the hole
  /lineloss fingerTab y 2 div sub def % add a little more to the line to compensate for what was lost in moving the circle
  } {
  %if finger tab set to 0 set all to 0. don't add hole
  /x 0 def
  /y 0 def
  /changeangle 0 def
  /lineloss 0 def
  /fingerinset 0 def
  } ifelse

% Draw 1/2 of the top, one "flap" of the lid
/drawflap {
  newpath 
    toplen 2 div 0 moveto    % Start at the end of the flap closest to the body
    tabwidth 2 mul 0 lineto  % draw the edge up to the tab
    0 tablen rlineto         % cut in a tab
    tabwidth neg 0 rlineto
    0 tablen neg rlineto     % and back out to lock it
    tabwidth neg 0 rlineto
    
    fingerinset neg boxwidth 2 div fingerTab 270 changeangle add 90 changeangle sub arc % draw arc for finger hole
    
    0 boxwidth 2 div fingerTab sub lineloss add rlineto       % draw the end of the top flap
    
    tabwidth 0 rlineto       % and draw the locking tabs
    0 tablen neg rlineto
    tabwidth 0 rlineto
    0 tablen rlineto
    toplen 2 div boxwidth lineto  % finish by returning to the body end of the flap
  stroke
} def

% Draw a hinge line going all the way across the hinge
/longline {
  /linelen boxwidth numhingelines breaklen 2 mul sub numhingelines div def  % How long is a segment in a long line?

  % Draw 1/2 a line to start
  0 linelen 2 div rlineto

  % Fill in the space with full lines
  2 1 numhingelines {
    0 breaklen 2 mul rmoveto
    0 linelen rlineto
  } for

  % Draw the last half line to even it out
  0 breaklen 2 mul rmoveto
  0 linelen 2 div rlineto

} def

% Draw a hinge line with end caps
/shortline {
  /linelen boxwidth numhingelines 1 sub breaklen 2 mul mul breaklen 2 mul add sub numhingelines div def

  % Skip a break then fill the space with evenly spaced lines
  0 breaklen neg rmoveto
  1 1 numhingelines {
    0 linelen neg rlineto
    0 breaklen 2 mul neg rmoveto
  } for
} def

% Draw a flattened out hinge - alternating short and long lines
/drawhinge {
  /minwidth materialthickness def            % the minimum width for a hinge section (2 lines)
  /numbars hingelen minwidth div floor def   % the number of hinge sections per hinge
  /barwidth hingelen numbars div def         % the actual width of a hinge section
  
  hingeR hingeG hingeB setrgbcolor     % Set colour to hinge colour

  newpath
    0 boxwidth moveto                        % start at the bottom of the hinge and draw a short line
    shortline
 
    1 1 numbars {                            % for each of the sections in the hinge
      /i exch def
      i barwidth mul barwidth 2 div sub 0 moveto  % move to the middle of the section and draw
      longline                                    % a long line to split the section in half
      i barwidth mul boxwidth moveto              % move to the end of the section and
      shortline                                   % draw a shortline to connect to the next section
    } for
  stroke
  outR outG outB setrgbcolor     % back to black for the outside lines
  newpath
    0 0 moveto                               % draw the sides of the hinge
    hingelen 0 rlineto
    0 boxwidth rmoveto
    hingelen neg 0 rlineto
  stroke
} def

%draw tabs for bottom of the sides of box (ones between the wings)
/drawbasetabs {
	newpath
	  0 0 moveto
      tabsizebase 0 rlineto                % draw tabs and slots along the bottom line of the front
      1 1 numtabsbase 2 div { 
        0 tablen rlineto
        tabsizebase 0 rlineto
        0 tablen neg rlineto
        tabsizebase 0 rlineto 
      } for
    stroke
} def

% Draw an edge of the box, using tabs to connect to the front/back if the side is large enough
/drawendedge {
  /numtabs sideheight tabwidth div 2 div ceiling 2 mul 1 add def  % how many tabs to connect to front
  /tabsize sideheight numtabs div def                             % how big should the tabs be

  newpath
    0 0 moveto                 % Move to the top of the side
    tabsize 0 rlineto          % draw the first tab
    1 1 numtabs 2 div {        % if there are more tabs
      0 tablen rlineto         % draw the tab
      tabsize 0 rlineto
      0 tablen neg rlineto     % then return to the side
      tabsize 0 rlineto        % for the slot
    } for
  stroke
} def

% Draw an end of the box horizontally
/drawend {
  gsave
    drawendedge                     % Only draw the 2 edges of the end not connected to the hinges
    sideheight boxwidth translate
    -1 -1 scale
    drawendedge
  grestore
} def

% Draw a "wing" of the box, consisting of 1/2 the top, 2 hinges and a side
/drawwing {
  % Draw the two hinges before drawing the outline of the wing - use this order for laser cutting betterment
  gsave
    toplen 2 div 0 translate  % Skip over the flap
    drawhinge                 % Draw a hinge
    hingelen sideheight add 0 translate % Skip over the end/side
    drawhinge                 % Draw a hinge
  grestore
  gsave                       % Go back to the beginning of the wing
    drawflap                  % Draw the top flap
    toplen 2 div hingelen add 0 translate % skip over the hinge
    gsave %draw only the bottom edge as the box sides do the other side
      sideheight boxwidth translate
      -1 -1 scale
      drawendedge
    grestore
  grestore
} def


% Draw the front/back side of the box
/drawfront {

  gsave
    tablen tablen translate

    % Connect the front side to the bottom with tabs
    newpath
      innerradius frontheight moveto   % Start at the bottom, inside of the curved corner
      tabsizebase 0 rlineto                % draw tabs and slots along the bottom line of the front
      1 1 numtabsbase 2 div { 
        0 tablen rlineto
        tabsizebase 0 rlineto
        0 tablen neg rlineto
        tabsizebase 0 rlineto 
      } for
      frontwidth innerradius sub frontheight moveto  % draw the corner at the bottom right of the front
      frontwidth innerradius sub frontheight innerradius sub innerradius 90 0 arcn
    stroke

    % draw a corner radius then the side connecting one end to the front
    gsave
      frontwidth frontheight innerradius sub translate % move to the bottom of the right edge
      270 rotate
      drawendedge  % draw the edge connecting the front and an end
    grestore

    % draw another corner radius, the side connecting the top flaps to the front, and another corner
    newpath
      frontwidth innerradius sub innerradius innerradius 0 270 arcn  % draw the top right corner
      toplen 2 div neg tabwidth 2 mul add 0 rlineto                  % draw the right half of the top
      0 tablen neg rlineto                                           % stick out a tab to grab the top flap
      tabwidth neg 0 rlineto
      0 tablen rlineto                                               % Make a slot to hold both flaps' tabs
      tabwidth 2 mul neg 0 rlineto                                 
      0 tablen neg rlineto                                           % make a tab to grab the other flap
      tabwidth neg 0 rlineto
      0 tablen rlineto
      innerradius 0 lineto                                           % then finish off the top of this side
      innerradius innerradius innerradius 270 180 arcn               % with a top left corner
    stroke
 
    % draw the last side of the front, connecting the front to another end
    gsave
      0 innerradius translate   % below the corner
      90 rotate
      drawendedge               % draw the edge connecting with the left end
    grestore

    % finish off the front with the last corner radius
    newpath
      innerradius frontheight innerradius sub innerradius 180 90 arcn % draw the bottom left corner to finish this side
    stroke
  grestore  
} def

% Go ahead and actually draw the box

% Draw the two wings - the top flaps and ends
gsave
  0 boxlength tablen sub translate   % line up the wing with the bottom of the box's front side
  drawwing                           % draw the wing
  gsave
    winglen 0 translate %move to wing middle
    drawbasetabs %draw tabs between wings
    0 boxwidth translate
    1 -1 scale %mirror horisontal
    drawbasetabs %draw bottom tabs fo wings
  grestore
  2 toplen mul sideheight 2 mul add hingelen 4 mul add 0 translate  % skip over to the other side of the box
  -1 1 scale
  drawwing                                                          % and draw the other wing
grestore

% Draw the front and back of the box, connected up to the wings this also makes the bottom
gsave
  
  toplen 2 div hingelen add cornerradius sub boxlength translate  % line up the front so it will mesh with the wings
  -90 rotate                            %rotate it so it sits ontop
  drawfront                             % and draw it

  0 boxheight hingelen 2 mul add sideheight add toplen add translate  % line up the front so it will mesh with the wings
  1 -1 scale                            %scale (mirror) to save having to work with vertical offset
  drawfront                             % and draw it
grestore

% We're done here, lets go home.
showpage
%%EOF

Matériaux

  • CP 3mmm
  • Machine Laser ( ici : Gravograph LS900 au 8fablab a Crest)
/home/resonancg/www/wiki/data/pages/projets/laserbox-parametrique/accueil.txt · Dernière modification: 2016/04/27 12:20 de resonance