2013年6月7日星期五

「筆記」QC進階筆記 2-3



結合上週的進度,在本範例中,利用滑鼠拖拉的動作,動態的產生新的矩形,矩形之後便會不停沿著y軸循環移動,如同上升的泡泡一般。

var first=true;
var x1;
var y1;
var x2;
var y2;

var out_x;
var out_y;
var width;
var height;

var mySquare=[];

function (__number out_x,__number out_y,__number width,__number height,__structure myStructures) 
main (__number x,__number y,__boolean click ,__boolean clear,__number time)
{
 var result = new Object();
 if(clear){ mySquare=[];}
  
 if(click){
  if(first){
   x1=x;
   y1=y; 
   first=false;
  }
  x2=x;
  y2=y;
  
  out_x=(x1+x2)/2;
  out_y=(y1+y2)/2;
  width=Math.abs(x1-x2);
  height=Math.abs(y1-y2);
  
  result.out_x=(x1+x2)/2;
  result.out_y=(y1+y2)/2;
  result.width=Math.abs(x1-x2);
  result.height=Math.abs(y1-y2); 
  
 }else{
  if(first==false){
   mySquare.push({ax:out_x,ay:out_y,awidth:width,aheight:height});
  }
 first=true;
 }
 
 for(var i=0;i<mySquare.length;i=1+1){  
  
  if(mySquare[i].ay <2){
   mySquare[i].ay += (i%15+5)/300;
  }else{
   mySquare[i].ay =-1
  }
 }
 result.myStructures=mySquare;
 return result;
}


 (主程式)

(NewSquare)

Download qc2_w2-5.qtz