Wierd line of code

I was looking at a fractal tree example, and came opon this, and didnt know what to make of it, so here it is.


w = (level == 1) ? 9 : max_level-level+1; 

If you want it in context here it is


function growtree(level, o_x, o_y, angle, len) { 
   rad = Math.PI/180*angle; 
   var e_x = o_x+len*Math.cos(rad); 
   var e_y = o_y-len*Math.sin(rad); 
   w = (level == 1) ? 9 : max_level-level+1; 
   this.lineStyle(w,0xabcdef, 100); 
   moveTo(o_x, o_y); 
   lineTo(e_x, e_y); 
   if (level<max_level) { 
      for (var i = 1; i<=max_shoot; i++) { 
         growtree(level+1, e_x, e_y, angle+max_angle*(Math.random()*2-1), len*short_fraction); 
      } 
   } 
} 
max_angle = 60; 
max_level = 6; 
max_shoot = 4; 
short_fraction = .7; 
base_angle = 6;
_root.onMouseDown = function() { 
   this.clear(); 
   growtree(1, Stage.width/2, Stage.height, 90+base_angle*(Math.random()*2-1), 115); 
}; 
growtree(1, Stage.width/2, Stage.height, 90+base_angle*(Math.random()*2-1), 115);

P.S. Does kirupa have 25 line competitions like the bit-101 forums? or add a line change a line threads.Just wondering.

Hey thanks, i never knew you could write it like that. Ill check that thread out too. Thanks again!

welcome :slight_smile:
You can also check this tutorial for more info on the tertiary operator: http://www.kirupa.com/developer/actionscript/tricks/tertiary.htm

wow.

i didnt know that, its wierd.
suppose it’d be alright for coding
huge amounts of stuff, but i personally
prefer to have my ‘if,then,else’ things
’nested’ within eachother and indented.