Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function stack( )
- {
- this.inner = [ ];
- this.push = function( object )
- {
- if ( typeof( object ) == "string" && object in this )
- eval( "this." + object + "()" );
- else
- this.inner.push( object );
- return this;
- }
- this.pop = function( )
- {
- return this.inner.pop( );
- }
- this.union = function( )
- {
- var a = this.pop( );
- var b = this.pop( );
- this.push( union( a, b ) );
- return this;
- }
- this.difference = function( )
- {
- var a = this.pop( );
- var b = this.pop( );
- this.push( difference( a, b ) );
- return this;
- }
- this.translate = function( )
- {
- var a = this.pop( );
- var b = this.pop( );
- this.push( b.translate( a ) );
- return this;
- }
- this.scale = function( )
- {
- var a = this.pop( );
- var b = this.pop( );
- this.push( b.scale( a ) );
- return this;
- }
- this.dup = function( )
- {
- var a = this.pop( );
- this.push( a );
- this.push( a );
- return this;
- }
- this.swap = function( )
- {
- var a = this.pop( );
- var b = this.pop( );
- this.push( a );
- this.push( b );
- return this;
- }
- }
- function main( )
- {
- return new stack( ) // Create stack
- .push( cube( ) ) // Push a cube
- .dup( ) // Duplicate the top of stack
- .push( [ 1, 1, 0 ] ) // Push coordinates
- .translate( ) // Translate
- .union( ) // Join the two objects
- .push( 10 ) // Push 10
- .scale( ) // Scale
- .pop( ); // Return top of stack
- }
Add Comment
Please, Sign In to add comment