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

 Chompy 01-21-2008 10:48 PM

drawLine()

Graal Script Code:

``` //#CLIENTSIDEpublic function drawLine(index, xy1, xy2, color, thickness, layer) {  with(findimg(index)) {    polygon = {      xy1[0], xy2[1], xy2[0], xy1[1],      xy2[0]+thickness, xy1[1]+thickness, xy1[0]+thickness, xy2[1]+thickness    };    layer = layer;    red = color[0];    green = color[1];    blue = color[2];    alpha = color[3];  }}  ```
Basic example:
Graal Script Code:

``` //#CLIENTSIDEfunction onCreated() {  drawLine(200, {15, 20}, {31, 18}, {1, 0, 0, 0.99}, 0.3, 2);  // 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

Graal Script Code:

``` with( findimg( 200 ) ){  image = "block.png";  x = 10;  y = 20;}  ```
Graal Script Code:

``` showimg( "block.png", 10, 20 );  ```

 Rapidwolve24 01-22-2008 03:42 AM

Quote:
 Originally Posted by cbkbud (Post 1371112) Why will people do something like Graal Script Code: ``` with( findimg( 200 ) ) {   image = "block.png";   x = 10;   y = 20; }  ``` instead of just Graal Script Code: ``` showimg( "block.png", 10, 20 );  ```
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

Graal Script 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?

All times are GMT +2. The time now is 07:07 AM.