Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Line drawing tool (https://forums.graalonline.com/forums/showthread.php?t=134262183)

Crow 02-21-2011 09:01 PM

Line drawing tool
 
Published by request. Draws lines using Chompy's and Sales' DrawLine() function. Hold ctrl and drag yer mouse through Graal, wee~ ^^

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
this.draw = false;
  
this.ox = nil;
  
this.oy = nil;
  
this.iIndex = 0;
}

// erase drawn lines
function onEraseLines()
  
hideImgs(0, 199);

// mouse stuff
function GraalControl.onMouseDown(kmod) {
  if (
kmod in |4, 8|) { // ctrl
    
this.draw = true;
    
this.ox = mousex;
    
this.oy = mousey;
    
    
cancelEvents("EraseLines");
  }
}

function 
GraalControl.onMouseUp() {
  if (!
this.draw)
    return;
  
  
this.draw = false;
  
cancelEvents("EraseLines");
  
scheduleEvent(3, "EraseLines", nil);
}

function 
GraalControl.onMouseDragged() {
  if (!
this.draw)
    return;
  
  
temp.dx = abs(this.ox - mousex);
  
temp.dy = abs(this.oy - mousey);
  
temp.d  = (temp.dx ^ 2 + temp.dy ^ 2) ^ 0.5;
  if (
temp.d > 0.1) {
    
temp.i = this.iIndex;
    
temp.t = 0.5;
    
    
DrawLine(temp.i, this.ox, this.oy, mousex, mousey, 2 / 16);
    
changeImgColors(temp.i, 1, 1, 1, 1);
    
changeImgVis(temp.i, 3);
    
    
this.iIndex++;
    
this.iIndex %= 200;
    
    
this.ox = mousex;
    
this.oy = mousey;
  }
}


// draw-a-line - thanks Chompy & Sales
// http://forums.graalonline.com/forums/showthread.php?t=78427
function DrawLine(idx, sx, sy, tx, ty, w) {
  
w = (w == nil ? 1 / 16 : w);
  
temp.ang = getangle(tx - sx, ty - sy) + pi / 2;
  
  
showPoly(idx,
    { 
sx, sy,
      
tx, ty,
      
tx + cos(ang) * w, ty - sin(ang) * w,
      
sx + cos(ang) * w, sy - sin(ang) * w  });
} 


Soala 02-22-2011 03:02 AM

Kewl stuff :O

Toxen 02-22-2011 04:28 PM

very cool. repp++

xAndrewx 02-22-2011 07:40 PM

on the other persons screen does it show random lines? not a full line

Crow 02-22-2011 07:47 PM

Quote:

Originally Posted by xAndrewx (Post 1632654)
on the other persons screen does it show random lines? not a full line

That can happen if you're drawing "too fast", yea. Seems to be a synchronization problem though.

xAndrewx 02-22-2011 07:52 PM

Ahhh- dusty had the same problem :[

good job though =D

Twaina 02-25-2011 05:14 PM

Old

Crow 02-26-2011 02:48 PM

Quote:

Originally Posted by Twaina (Post 1633220)
Old

Duh.

salesman 02-26-2011 05:06 PM

Quote:

Originally Posted by Twaina (Post 1633220)
Old

ur old


All times are GMT +2. The time now is 02:50 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.