lilo_booter

OpenJScad RPN Hacking

Apr 30th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. function stack( )
  2. {
  3. this.inner = [ ];
  4.  
  5. this.push = function( object )
  6. {
  7. if ( typeof( object ) == "string" && object in this )
  8. eval( "this." + object + "()" );
  9. else
  10. this.inner.push( object );
  11. return this;
  12. }
  13.  
  14. this.pop = function( )
  15. {
  16. return this.inner.pop( );
  17. }
  18.  
  19. this.union = function( )
  20. {
  21. var a = this.pop( );
  22. var b = this.pop( );
  23. this.push( union( a, b ) );
  24. return this;
  25. }
  26.  
  27. this.difference = function( )
  28. {
  29. var a = this.pop( );
  30. var b = this.pop( );
  31. this.push( difference( a, b ) );
  32. return this;
  33. }
  34.  
  35. this.translate = function( )
  36. {
  37. var a = this.pop( );
  38. var b = this.pop( );
  39. this.push( b.translate( a ) );
  40. return this;
  41. }
  42.  
  43. this.scale = function( )
  44. {
  45. var a = this.pop( );
  46. var b = this.pop( );
  47. this.push( b.scale( a ) );
  48. return this;
  49. }
  50.  
  51. this.dup = function( )
  52. {
  53. var a = this.pop( );
  54. this.push( a );
  55. this.push( a );
  56. return this;
  57. }
  58.  
  59. this.swap = function( )
  60. {
  61. var a = this.pop( );
  62. var b = this.pop( );
  63. this.push( a );
  64. this.push( b );
  65. return this;
  66. }
  67. }
  68.  
  69. function main( )
  70. {
  71. return new stack( ) // Create stack
  72. .push( cube( ) ) // Push a cube
  73. .dup( ) // Duplicate the top of stack
  74. .push( [ 1, 1, 0 ] ) // Push coordinates
  75. .translate( ) // Translate
  76. .union( ) // Join the two objects
  77. .push( 10 ) // Push 10
  78. .scale( ) // Scale
  79. .pop( ); // Return top of stack
  80. }
Add Comment
Please, Sign In to add comment