Advertisement
Drakim

Drawing Algorithm

Nov 5th, 2011
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. while({xS-=ysin;yS+=ycos;++j<down;}) { // Y-Loop
  2.   // Find the START of the x loop
  3.   amount1 = Std.int(  if(xcos<0&&xS>wClip) {(wClip-xS)/xcos+1;} else if(xcos>0&&xS<0) {-xS/xcos+1;}  );
  4.   amount2 = Std.int(  if(xsin<0&&yS>hClip) {(hClip-yS)/xsin+1;} else if(xsin>0&&yS<0) {-yS/xsin+1;}  );
  5.   amount1 = ((amount1<amount2)?amount2:amount1);
  6.        
  7.   // Find the END of the x loop
  8.   amount3 = Std.int(  if(xcos>0&&xS<wClip) {(wClip-xS)/xcos+1;} else if(xcos<0&&xS>0) {-xS/xcos+1;}  );
  9.   amount4 = Std.int(  if(xsin>0&&yS<hClip) {(hClip-yS)/xsin+1;} else if(xsin<0&&yS>0) {-yS/xsin+1;}  );
  10.   amount3 = ((amount3>amount4)?amount4:amount3);
  11.          
  12.   // If START is later than END then obviously we shouldn't draw this row (this is a skip-y solution)
  13.   if(amount1>amount3) {continue;} //SKIP
  14.          
  15.   // Set the starting position (this is a jump-x solution)
  16.   i=left+amount1;
  17.   xSR=xS+xcos*amount1-xcos;
  18.   ySR=yS+xsin*amount1-xsin;
  19.          
  20.   // Set the ending position (this is a jump-x solution)
  21.   right=left+amount3+1;
  22.  
  23.   // Start the loop
  24.   while({xSR+=xcos;ySR+=xsin;++i<right;}) { // X-Loop
  25.     color=getPixel(Std.int(xSR)+xClip,Std.int(ySR)+yClip);  // Get the color at a transformed position
  26.     if(color!=0xFF00FF) {_context.target.drawPixel(color,_x+i,_y+j);} // Set the color at an untransformed position
  27.   }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement