Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   drawLine() (https://forums.graalonline.com/forums/showthread.php?t=78427)

Chompy 01-21-2008 10:48 PM

drawLine()
 
PHP Code:

//#CLIENTSIDE
public function drawLine(indexxy1xy2colorthicknesslayer) {
  
with(findimg(index)) {
    
polygon = {
      
xy1[0], xy2[1], xy2[0], xy1[1],
      
xy2[0]+thicknessxy1[1]+thicknessxy1[0]+thicknessxy2[1]+thickness
    
};
    
layer layer;
    
red color[0];
    
green color[1];
    
blue color[2];
    
alpha color[3];
  }


Basic example:
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
drawLine(200, {1520}, {3118}, {1000.99}, 0.32);
  
// will draw a red line from 15,20 to 31,18 with a thickness of 0.3 tiles


Basicly you give the function: index, xy1[], xy2[], color[], thickness and layer

The function will draw polygon from xy1 to xy2, thickness of the line is based on the 4th param (if layer is 4 or lower, it is given in tiles. If 5 or higher thickness is in pixels (This goes to coordinats to (xy1 and xy2))

A nifty little function that I thought I could share :)

DustyPorViva 01-21-2008 11:05 PM

Hmm... does the thickness take into account the direction of the line? From reading it it doesn't seem it, maybe that'd be a good addition.

Inverness 01-21-2008 11:12 PM

The fancy one you have should be drawline2(), and just have a simple drawline(x1, y1, x2, y2) like in Java and have setcolor() and stuff seperate :o

Chompy 01-21-2008 11:13 PM

Quote:

Originally Posted by DustyPorViva (Post 1371028)
Hmm... does the thickness take into account the direction of the line? From reading it it doesn't seem it, maybe that'd be a good addition.

Hmm, yeah, I edited it :o

It now works, but it makes some sharp corners:
..______
./......../
/_____/ (Where you remove the dots (pm, this is a zoomed version of the line :p))

I could add some checking to see which direction it is going based on the gived coords tho..

coreys 01-21-2008 11:51 PM

I think Graal should have brush functionality much like C#. ;(

Chompy 01-22-2008 12:06 AM

Quote:

Originally Posted by coreys (Post 1371062)
I think Graal should have brush functionality much like C#. ;(

:p

cbk1994 01-22-2008 03:19 AM

Why will people do something like

PHP Code:

withfindimg200 ) )
{
  
image "block.png";
  
10;
  
20;


instead of just
PHP Code:

showimg"block.png"1020 ); 


Rapidwolve24 01-22-2008 03:42 AM

Quote:

Originally Posted by cbkbud (Post 1371112)
Why will people do something like

PHP Code:

withfindimg200 ) )
{
  
image "block.png";
  
10;
  
20;


instead of just
PHP Code:

showimg"block.png"1020 ); 


I think he did it to avoid having to use changeimgvis and changeimgcolors?

coreys 01-22-2008 04:13 AM

It's just a matter of preference.

Inverness 01-22-2008 04:44 AM

showimg() = GS1 >:(
As far as I'm concerned considering the way you can use findimg(), I consider showimg() to just be a remnant of GS1 existing for compatibility.

cbk1994 01-22-2008 04:47 AM

Quote:

Originally Posted by Inverness (Post 1371137)
showimg() = GS1 >:(
As far as I'm concerned considering the way you can use findimg(), I consider showimg() to just be a remnant of GS1 existing for compatibility.

Hmm ... I've always used the functions like changeimgcolor, etc.

Will probably start using findimg().

Twinny 01-22-2008 04:59 AM

Quote:

Originally Posted by Inverness (Post 1371137)
I consider showimg() to just be a remnant of GS1 existing for compatibility.

This drawline...it has it's own function to allow people to quickly draw a line using 1 line of code. Technically you could just add the provided code at every instance and it would have the same effect, yes? People will still choose the function as it's easier. showimg() seems quite similar to this.

DustyPorViva 01-22-2008 05:47 AM

I use showimg because it's shorter. If I'm going to be showing an image and change a lot about it though, I'll usually use findimg.

Chompy 01-22-2008 05:53 PM

Quote:

Originally Posted by Rapidwolve24 (Post 1371124)
I think he did it to avoid having to use changeimgvis and changeimgcolors?

Quote:

Originally Posted by coreys (Post 1371134)
It's just a matter of preference.

:)

And, I find using findimg() easier to read and debug

Dan 01-22-2008 07:28 PM

PHP Code:

    polygon = {
      
xy1[0]-(thickness/2), xy2[1]-(thickness/2), xy2[0]-(thickness/2), xy1[1]-(thickness/2),
      
xy2[0]+(thickness/2), xy1[1]+(thickness/2), xy1[0]+(thickness/2), xy2[1]+(thickness/2)
    }; 

Wouldn't that look better?

DustyPorViva 01-22-2008 07:32 PM

What he needs to do is get the angle of the line, then draw the points half of thickness 90 degree's out to each side.

Tolnaftate2004 01-22-2008 09:46 PM

Quote:

Originally Posted by Inverness (Post 1371137)
showimg() = GS1 >:(
As far as I'm concerned considering the way you can use findimg(), I consider showimg() to just be a remnant of GS1 existing for compatibility.

This is an awful way to think of it. showimg() is decidedly a function with a return value; it was not so in GS1.

It seems superfluous to me to use the with-findimg construct for (essentially) static images.

Chompy 01-22-2008 10:47 PM

Quote:

Originally Posted by DustyPorViva (Post 1371220)
What he needs to do is get the angle of the line, then draw the points half of thickness 90 degree's out to each side.

yeah :o

well, getangle(xy1[0]-xy2[0], xy1[1]-xy2[1]); would do that, but, I haven't got to work on this little function as much, because I've been busy with other stuff :(

Crow 01-22-2008 10:55 PM

showimg() being GS1? Try to use findimg() serverside.

Inverness 01-22-2008 11:36 PM

findimg() is listed in the serverside script functions.

I always use findimg() now because I don't want to alternate between two days of doing the same thing. findimg() works for the simple and the complex and is much more readable.
Quote:

Originally Posted by Tolnaftate2004 (Post 1371250)
showimg() is decidedly a function with a return value; it was not so in GS1.

There would have been no point for it returning an object in GS1. Also making it return the image object in GS2 was a good move.

So theres now 3 ways to do the same thing:
PHP Code:

// GS1
showimg(1"light3.png"3.53);
changeimgcolor(110.400);
changeimgvis(13);
// Half GS2
with (showimg(1"light3.png"3.53)) {
  
red 1;
  
green 0.4;
  
blue 0;
  
alpha 0;
  
layer 3;
}
// Full GS2
with (findimg(1)) {
  
image "light3.png";
  
thiso.3.5;
  
thiso.3;
  
red 1;
  
green 0.4;
  
blue 0;
  
alpha 0;
  
layer 3;



cbk1994 01-23-2008 01:06 AM

Quote:

Originally Posted by Inverness (Post 1371277)
code which says that things are gs1, half-gs2, and gs2]

How can you say GS1, half-GS2, and GS2? It's personal preference!

GS1 is

PHP Code:

showimg 200block.png1030

Half-GS2 is

PHP Code:

showimg 200block.png1030;
changeimgvis20020 ); 

GS2 is

PHP Code:

showimg200"block.png"1030 ); 

Just because something else was added does not mean previous functions were deprecated (though it may well be).

Inverness 01-23-2008 01:44 AM

Quote:

Originally Posted by cbkbud (Post 1371307)
<snip>

Okay, you're not understanding my point of view and I don't feel like explaining so lets just drop it.

Angel_Light 01-23-2008 02:35 AM

Invern is right, showImg(); was made just for compatibility with showimg; GS2 is technically not related to GS1. You should use findImg, it is more object oriented than showImg;

cbk1994 01-23-2008 03:00 AM

Quote:

Originally Posted by Inverness (Post 1371326)
Okay, you're not understanding my point of view and I don't feel like explaining so lets just drop it.

works4me

Admins 01-23-2008 06:38 PM

Quote:

Originally Posted by coreys (Post 1371062)
I think Graal should have brush functionality much like C#. ;(

There is the GuiDrawingPanel. It will soon be possible to also draw text and lines into that and may be used with showimgs.

Chompy 01-23-2008 07:07 PM

Quote:

Originally Posted by Stefan (Post 1371491)
There is the GuiDrawingPanel. It will soon be possible to also draw text and lines into that and may be used with showimgs.

Nice

Tolnaftate2004 01-23-2008 07:51 PM

Quote:

Originally Posted by Angel_Light (Post 1371339)
Invern is right, showImg(); was made just for compatibility with showimg;

No, there never existed anything called showimg(); in GS1; showimg; was retained for backwards compatibility.
Quote:

You should use findImg, it is more object oriented than showImg;
No, these two functions return the same thing. You can't say one is more OO than the other.

But showimg involves no lookup.

Crow 01-23-2008 08:14 PM

Quote:

Originally Posted by Inverness (Post 1371277)
findimg() is listed in the serverside script functions.

Never got findimg() to work serverside when I would want to display text.

Inverness 01-23-2008 11:43 PM

I seem to recall showtext working clientside only back in the GS1 days.
Quote:

Originally Posted by Tolnaftate2004 (Post 1371501)
No, there never existed anything called showimg(); in GS1; showimg; was retained for backwards compatibility.

No, these two functions return the same thing. You can't say one is more OO than the other.

But showimg involves no lookup.

Of course there was no showimg() in GS1 as that is a GS2 function equivalent. When the scripting engine reads GS1 script I'm pretty damn sure its just executing the GS2 equivalent of the function which would be showimg().

And how do you mean that showimg() involves no lookup?

Kristi 01-24-2008 12:28 AM

showimg is a fine function. I personally do something like
this.whatevz = showimg(whatevz);
then generally reference the variable when i want to change anything
this.whatevz.red = rad;

napo_p2p 01-24-2008 06:43 AM

findimg() vs. showimg() is just a matter from preference. one isn't more OO than the other; one isn't more 'GS2' than the other. they are pretty much equivalent.

For example, taking
Quote:

Originally Posted by Kristi (Post 1371570)
showimg is a fine function. I personally do something like
this.whatevz = showimg(whatevz);
then generally reference the variable when i want to change anything
this.whatevz.red = rad;

i would do something along the lines of:
PHP Code:

with (findimg(1)) {
  
//whatevz
  
thiso.whatevz this;


but either way is just as good.

salesman 03-13-2009 11:58 PM

I came across this thread when trying to find out if there was a built in drawLine() function. However, I needed the width of the line to be the same regardless of angle and made this:

PHP Code:

//DrawLine( img_index, start_x, start_y, target_x, target_y, width_in_tiles, red, green, blue, alpha)
public function DrawLineindsxsytxtywidrgbalph ) {
  
temp.ang getangle(tx sxty sy) + (pi/2);
  
temp.wid = ( wid == NULL .1 wid );

  
with findImg(ind) ) {
    
polygon = {
      
sxsy,
      
txty,
      
tx cos(ang)*widty sin(ang)*wid,
      
sx cos(ang)*widsy sin(ang)*wid
    
};
    
red = ( || );
    
green = ( || );
    
blue = ( || );
    
alpha = ( alph <= || alph alph);
    
layer 3;
  }


An example:
PHP Code:

DrawLine(20025254545);
//Draws a black line of width .1 tiles from 25,25 to 45,45 

or if you want to specify color, width and alpha:
PHP Code:

DrawLine(20025254545.3100.5);
//Draws a semi-transparent red line of width .3 tiles from 25,25 to 45,45 



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

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