View Single Post
Old 04-25-2013, 11:40 PM   #48
bang
Human being with feelings
 
bang's Avatar
 
Join Date: Jul 2006
Posts: 554
Default newJs pseudo-object parameters

hello all!

seems that the main limitation of newJs pseudo-objects is that inside a function "this.foo" is all there is. there's no inbuilt way to refer to "that.foo". here's my current workaround technique:
Code:
function rgbapush()
  instance( r, g, b, a )
(
  stack_push( a );
  stack_push( b );
  stack_push( g );
  stack_push( r );
);

function rgbapop()
  instance( r, g, b, a )
(
  stack_pop( r );
  stack_pop( g );
  stack_pop( b );
  stack_pop( a );
);

// a.rgbapush(); b.rgbapush();
function rgbamix( mix ) // thread safe
  instance( r, g, b, a ) local( mix1 )
(
  mix1= 1-mix;
  this.rgbapop(); // this= b.rgbapush();
  // keep in sync w/ rgbapop()
  r= stack_pop() * mix1 + r * mix; //stack_pop( a.r );
  g= stack_pop() * mix1 + g * mix; //stack_pop( a.g );
  b= stack_pop() * mix1 + b * mix; //stack_pop( a.b );
  a= stack_pop() * mix1 + a * mix; //stack_pop( a.a );
);

/*** alas, doesn't work:
// a.rgbapush(); b.rgbapush();
function rgbamix2( mix )
  instance( r, g, b, a )
  local(a1, b1)
(
  mix1= 1-mix;
  b1.rgbapop(); a1.rgbapop();
  r= a1.r * mix1 + b1.r * mix;
  g= a1.g * mix1 + b1.g * mix;
  b= a1.b * mix1 + b1.b * mix;
  a= a1.a * mix1 + b1.a * mix;
); ***/
anyone have anything better than this?

enjoy! /dan
bang is offline   Reply With Quote