Author Topic: draw thick line slow  (Read 1514 times)

cjhrules

  • Indy CoS Project Leader
    • cjhrules worked on one or more games that was nominated for an AGS Award!
draw thick line slow
« on: 19 Mar 2006, 13:23 »
Hi!
I'm using the "draw line function" to draw lines slow. Is it possible to modify this script to increase the thicknes of the line.

THis is the script:

Code: [Select]
/-------------------------------------------------------

//       This is the script for the Red line on the maps     
//-------------------------------------------------------
function StepsRightDown(int beginX, int beginY, int endX, int endY, int delay, int stepX, int stepY){
  int flag;  //flag to leave Y loop
  while(beginX<=endX){
    beginX++;
    if(beginX%(stepX)==0){  //the step equasion. If X is the right stepvalue, it will stop and let Y move
      while(flag==0){
        beginY++;
        if(beginY%(stepY)==0){  //if Y is done, it goes back to moving X
          flag=1;
        }
        RawDrawLine(beginX/10,beginY/10,beginX/10,beginY/10);  //deviding everthing back to screen co-ord.
        if(beginY%delay==0)Wait(1); //delay is anti delay. meaning bigger value makes line go faster. delay can't be 0!
      }
      flag=0;
    }
    RawDrawLine(beginX/10,beginY/10,beginX/10,beginY/10);
    if(beginX%delay==0)Wait(1);
  }
}

function StepsLeftDown(int beginX, int beginY, int endX, int endY, int delay, int stepX, int stepY){
  int flag;
  while(beginX>=endX){ 
    beginX--;
    if(beginX%(stepX)==0){
      while(flag==0){
        beginY++;
        if(beginY%(stepY)==0){
          flag=1;
        }
        RawDrawLine(beginX/10,beginY/10,beginX/10,beginY/10);
        if(beginY%delay==0)Wait(1);
      }
      flag=0;
    }
    RawDrawLine(beginX/10,beginY/10,beginX/10,beginY/10);
    if(beginX%delay==0)Wait(1);
  }
}

function StepsRightUp(int beginX, int beginY, int endX, int endY, int delay, int stepX, int stepY){
  int flag;
  while(beginX<=endX){ 
    beginX++;
    if(beginX%(stepX)==0){
      while(flag==0){
        beginY--;
        if(beginY%(stepY)==0){
          flag=1;
        }
        RawDrawLine(beginX/10,beginY/10,beginX/10,beginY/10);
        if(beginY%delay==0)Wait(1);
      }
      flag=0;
    }
    RawDrawLine(beginX/10,beginY/10,beginX/10,beginY/10);
    if(beginX%delay==0)Wait(1);
  }
}

function StepsLeftUp(int beginX, int beginY, int endX, int endY, int delay, int stepX, int stepY){
  int flag;
  while(beginX>=endX){ 
    beginX--;
    if(beginX%(stepX)==0){
      while(flag==0){
        beginY--;
        if(beginY%(stepY)==0){
          flag=1;
        }
        RawDrawLine(beginX/10,beginY/10,beginX/10,beginY/10);
        if(beginY%delay==0)Wait(1);
      }
      flag=0;
    }
    RawDrawLine(beginX/10,beginY/10,beginX/10,beginY/10);
    if(beginX%delay==0)Wait(1);
  }
}

function Steps(int beginX, int beginY, int endX, int endY, int colour, int delay, int steps){  //X & Y are screen co-ord multiplied by 10. If you test it and there is still a deviation, add exrta 0's
  int stepX;
  int stepY;
  RawSetColor(colour);
  if     (beginX-endX<0&&beginY-endY<0){  //right down
    if     ((endX-beginX)<=(endY-beginY)&&steps==0){stepX=10; stepY=(endY-beginY)*10/(endX-beginX);}  //if you use steps=0 then the function will draw a straight line
    else if((endX-beginX)> (endY-beginY)&&steps==0){stepX=(endX-beginX)*10/(endY-beginY); stepY=10;}  //because we use ints, we have to check if hor is bigger then ver first (to avoid value/0)
    else                                           {stepX=(endX-beginX)*10/steps; stepY=(endY-beginY)*10/steps;}  //steps can't be bigger then the maximum steps (endX-beginX) or (endY-beginY) wichever is smaller
    if(steps/10<(endX-beginX)&&steps/10<(endY-beginY))StepsRightDown(beginX,beginY,endX,endY,delay,stepX,stepY);  //eqasion to prevent value/0 errors. it wil just skip the function
  }
  else if(beginX-endX>0&&beginY-endY<0){  //left down
    if     ((beginX-endX)<=(endY-beginY)&&steps==0){stepX=10; stepY=(endY-beginY)*10/(beginX-endX);}  //the values are multiplied by 10 to make them more acured
    else if((beginX-endX)> (endY-beginY)&&steps==0){stepX=(beginX-endX)*10/(endY-beginY); stepY=10;}  //this looks all very complicated, but it's only calculating the max amount of steps
    else                                           {stepX=(beginX-endX)*10/steps; stepY=(endY-beginY)*10/steps;}  //begin & end CAN't be the same value! or you'll get value/0!
    if(steps/10<(beginX-endX)&&steps/10<(endY-beginY))StepsLeftDown(beginX,beginY,endX,endY,delay,stepX,stepY);
  }
  else if(beginX-endX<0&&beginY-endY>0){  //right up
    if     ((endX-beginX)<=(beginY-endY)&&steps==0){stepX=10; stepY=(beginY-endY)*10/(endX-beginX);}  //If you test it and there is still a deviation, add exrta 0's to all the 10's.
    else if((endX-beginX)> (beginY-endY)&&steps==0){stepX=(endX-beginX)*10/(beginY-endY); stepY=10;}  //it will slow down delay because it will draw every point 100 times
    else                                           {stepX=(endX-beginX)*10/steps; stepY=(beginY-endY)*10/steps;}
    if(steps/10<(endX-beginX)&&steps/10<(beginY-endY))StepsRightUp(beginX,beginY,endX,endY,delay,stepX,stepY);
  }
  else if(beginX-endX>0&&beginY-endY>0){  //left up
    if     ((beginX-endX)<=(beginY-endY)&&steps==0){stepX=10; stepY=(beginY-endY)*10/(beginX-endX);}
    else if((beginX-endX)> (beginY-endY)&&steps==0){stepX=(beginX-endX)*10/(beginY-endY); stepY=10;}
    else                                           {stepX=(beginX-endX)*10/steps; stepY=(beginY-endY)*10/steps;}
    if(steps/10<(beginX-endX)&&steps/10<(beginY-endY))StepsLeftUp(beginX,beginY,endX,endY,delay,stepX,stepY);
  }
}

fovmester

  • I am slowly making progress...
    • I can help with translating
    • fovmester worked on one or more games that was nominated for an AGS Award!
Re: draw thick line slow
« Reply #1 on: 19 Mar 2006, 14:05 »
Whoa, that a hell lot of code!

cjhrules

  • Indy CoS Project Leader
    • cjhrules worked on one or more games that was nominated for an AGS Award!
Re: draw thick line slow
« Reply #2 on: 19 Mar 2006, 14:15 »
Yeah, I found it on this forum. I thought I better post it in case someone knows someting about this.

Re: draw thick line slow
« Reply #3 on: 13 Mar 2010, 16:08 »
Hi,
is there a newer version of the code that suits the latest version of AGS?

monkey0506

  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
    • monkey0506 worked on one or more games that won an AGS Award!
    •  
    • monkey0506 worked on one or more games that was nominated for an AGS Award!
Re: draw thick line slow
« Reply #4 on: 13 Mar 2010, 18:55 »
Code: [Select]
//-------------------------------------------------------
// This is the script for the Red line on the maps
//-------------------------------------------------------
DrawingSurface *backgroundSurface;
DrawingSurface *backgroundBackup;
int backgroundDrawingColor = 0;

function on_event(EventType event, int data) {
  if (event == eEventEnterRoomAfterFadein) {
    backgroundSurface = Room.GetDrawingSurfaceForBackground();
    backgroundBackup = backgroundSurface.CreateCopy();
    backgroundSurface.Release();
    backgroundSurface = null;
    backgroundDrawingColor = 0;
  }
  else if (event == eEventLeaveRoom) {
    if (backgroundSurface != null) backgroundSurface.Release();
    if (backgroundBackup != null) backgroundBackup.Release();
    backgroundSurface = null;
    backgroundBackup = null;
  }
}

function StepsRightDown(int beginX, int beginY, int endX, int endY, int delay, int stepX, int stepY) {
  backgroundSurface = Room.GetDrawingSurfaceForBackground();
  backgroundSurface.DrawingColor = backgroundDrawingColor;
  int flag; // flag to leave Y loop
  while (beginX <= endX) {
    beginX++;
    if ((beginX % stepX) ==0) { // the step equation. If X is the right stepvalue, it will stop and let Y move
      while (flag == 0) {
        beginY++;
        if ((beginY % stepY) == 0) { // if Y is done, it goes back to moving X
          flag=1;
        }
        backgroundSurface.DrawPixel(beginX / 10, beginY / 10); // dividing everything back to screen co-ord.
        if ((beginY % delay) == 0) Wait(1); // delay is anti delay. meaning bigger value makes line go faster. delay can't be 0!
      }
      flag = 0;
    }
    backgroundSurface.DrawPixel(beginX / 10, beginY / 10);
    if ((beginX % delay) == 0) Wait(1);
  }
  backgroundSurface.Release();
  backgroundSurface = null;
}

function StepsLeftDown(int beginX, int beginY, int endX, int endY, int delay, int stepX, int stepY) {
  backgroundSurface = Room.GetDrawingSurfaceForBackground();
  backgroundSurface.DrawingColor = backgroundDrawingColor;
  int flag;
  while (beginX >= endX) {
    beginX--;
    if ((beginX % stepX) == 0) {
      while (flag == 0) {
        beginY++;
        if ((beginY % stepY) == 0) {
          flag = 1;
        }
        backgroundSurface.DrawPixel(beginX / 10, beginY / 10);
        if ((beginY %delay) == 0) Wait(1);
      }
      flag = 0;
    }
    backgroundSurface.DrawPixel(beginX / 10, beginY / 10);
    if ((beginX % delay) == 0) Wait(1);
  }
  backgroundSurface.Release();
  backgroundSurface = null;
}

function StepsRightUp(int beginX, int beginY, int endX, int endY, int delay, int stepX, int stepY) {
  backgroundSurface = Room.GetDrawingSurfaceForBackground();
  backgroundSurface.DrawingColor = backgroundDrawingColor;
  int flag;
  while (beginX <= endX) {
    beginX++;
    if ((beginX % stepX) == 0) {
      while (flag == 0) {
        beginY--;
        if ((beginY % stepY) == 0) {
          flag = 1;
        }
        backgroundSurface.DrawPixel(beginX / 10, beginY / 10);
        if ((beginY % delay) == 0) Wait(1);
      }
      flag = 0;
    }
    backgroundSurface.DrawPixel(beginX / 10, beginY / 10);
    if ((beginX % delay) == 0) Wait(1);
  }
  backgroundSurface.Release();
  backgroundSurface = null;
}

function StepsLeftUp(int beginX, int beginY, int endX, int endY, int delay, int stepX, int stepY) {
  backgroundSurface = Room.GetDrawingSurfaceForBackground();
  backgroundSurface.DrawingColor = backgroundDrawingColor;
  int flag;
  while (beginX >= endX) {
    beginX--;
    if ((beginX % stepX) == 0) {
      while (flag == 0) {
        beginY--;
        if ((beginY % stepY) == 0) {
          flag = 1;
        }
        backgroundSurface.DrawPixel(beginX / 10, beginY / 10);
        if ((beginY %delay) == 0) Wait(1);
      }
      flag = 0;
    }
    backgroundSurface.DrawPixel(beginX / 10, beginY / 10);
    if ((beginX % delay) == 0) Wait(1);
  }
  backgroundSurface.Release();
  backgroundSurface = null;
}

function Steps(int beginX, int beginY, int endX, int endY, int colour, int delay, int steps) { // X & Y are screen co-ord multiplied by 10. If you test it and there is still a deviation, add extra 0's
  int stepX;
  int stepY;
  backgroundDrawingColor = colour;
  if (((beginX - endX) < 0) && ((beginY - endY) < 0)) { //right down
    if (((endX - beginX) <= (endY - beginY)) && (steps == 0)) {
      // if you use steps = 0 then the function will draw a straight line
      stepX = 10;
      stepY = ((endY - beginY) * 10) / (endX - beginX);
    }
    else if (((endX - beginX) > (endY - beginY)) && (steps == 0)) {
      // because we use ints, we have to check if hor is bigger then ver first (to avoid value / 0)
      stepX = ((endX - beginX) * 10) / (endY - beginY);
      stepY = 10;
    }
    else {
      // steps can't be bigger then the maximum steps (endX - beginX) or (endY - beginY) whichever is smaller
      stepX = ((endX - beginX) * 10) / steps;
      stepY = ((endY-beginY) * 10) / steps;
    }
    if (((steps / 10) < (endX - beginX)) && ((steps / 10 < (endY - beginY))) StepsRightDown(beginX, beginY, endX, endY, delay, stepX, stepY); //equation to prevent value / 0 errors. it wil just skip the function
  }
  else if (((beginX - endX) > 0) && ((beginY - endY) < 0)) { //left down
    if (((beginX - endX) <= (endY - beginY)) && (steps==0)) {
      // the values are multiplied by 10 to make them more acured
      stepX = 10;
      stepY = ((endY-beginY) * 10) / (beginX - endX);
    }
    else if (((beginX - endX) > (endY - beginY)) && (steps == 0)) {
      // this looks all very complicated, but it's only calculating the max amount of steps
      stepX = ((beginX - endX) * 10) / (endY - beginY);
      stepY = 10;
    }
    else {
      // begin & end can't be the same value! or you'll get value / 0!
      stepX = ((beginX - endX) * 10) / steps;
      stepY = ((endY - beginY) * 10) / steps;
    }
    if (((steps / 10) < (beginX - endX)) && ((steps / 10) < (endY - beginY))) StepsLeftDown(beginX, beginY, endX, endY, delay, stepX, stepY);
  }
  else if (((beginX - endX) < 0) && ((beginY - endY) > 0)) { //right up
    if (((endX - beginX) <= (beginY - endY)) && (steps == 0)) {
      // If you test it and there is still a deviation, add extra 0's to all the 10's.
      stepX = 10;
      stepY = ((beginY - endY) * 10) / (endX - beginX);
    }
    else if (((endX - beginX) > (beginY - endY)) && (steps == 0)) {
      // it will slow down delay because it will draw every point 100 times
      stepX = ((endX - beginX) * 10) / (beginY - endY);
      stepY = 10;
    }
    else {
      stepX = ((endX - beginX) * 10) / steps;
      stepY = ((beginY - endY) * 10) / steps;
    }
    if (((steps / 10) < (endX - beginX)) && ((steps / 10) < (beginY - endY))) StepsRightUp(beginX, beginY, endX, endY, delay, stepX, stepY);
  }
  else if (((beginX - endX) > 0) && ((beginY - endY) > 0)){ // left up
    if (((beginX - endX) <= (beginY - endY)) && (steps == 0)) {
      stepX = 10;
      stepY = ((beginY - endY) * 10) / (beginX - endX);
    }
    else if (((beginX - endX) > (beginY - endY)) && (steps == 0)) {
      stepX = ((beginX - endX) * 10) / (beginY - endY);
      stepY=10;
    }
    else {
      stepX = ((beginX - endX) * 10) / steps;
      stepY = ((beginY - endY) * 10) / steps;
    }
    if (((steps / 10) < (beginX - endX)) && ((steps / 10) < (beginY-endY))) StepsLeftUp(beginX, beginY, endX, endY, delay, stepX, stepY);
  }
}

function ClearLines() {
  if (backgroundBackup == null) return;
  if (backgroundSurface == null) backgroundSurface = Room.GetDrawingSurfaceForBackground();
  backgroundSurface.DrawSurface(backgroundBackup);
  backgroundSurface.Release();
  backgroundBackup.Release();
  backgroundSurface = null;
  backgroundBackup = null;
}

Note that I haven't actually tested this, I just switched it over to use the DrawingSurface functions.

Re: draw thick line slow
« Reply #5 on: 13 Mar 2010, 20:35 »
Does this seriously use four times almost identical code for every direction...? Wow.
Fail at Floaty Rog' now!  still having to deal with what games are going through

monkey0506

  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
    • monkey0506 worked on one or more games that won an AGS Award!
    •  
    • monkey0506 worked on one or more games that was nominated for an AGS Award!
Re: draw thick line slow
« Reply #6 on: 13 Mar 2010, 20:59 »
I didn't actually analyze the code or make modifications to it (much) other than just updating it as requested. But you probably have a fair point. Ha!

I recently wrote something to do this myself that I suppose I could release as a module if people are interested in it. Specifically the way I wrote the code was for connecting multiple points with a set number of sub-points in-between. The higher the number of sub-points, the slower the points are connected.

Re: draw thick line slow
« Reply #7 on: 15 Mar 2010, 20:40 »
WOW!
Thaks a lot, monkey! That's more than a fair point to me! :-)

I transfered your code into my global script, which worked fine except two minor problems:

1. Since there is no "eEventAfterFadeIn" for the on_event function (as far as I know), I put the "eEventAfterFadeIn" in the room's room_AfterFadeIn function (as Khris described here: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=32074.0) and declared the variables there too. In this room I want the lines to be drawn.

2. I got an error saying that input ended in the middle of an expression (or something like that). So I changed this line in the function Steps(...):

if (((steps / 10) < (endX - beginX)) && ((steps / 10 < (endY - beginY))) StepsRightDown(beginX, beginY, endX, endY, delay, stepX, stepY); //equation to prevent value / 0 errors. it wil just skip the function

into:

if (((steps / 10) < (endX - beginX)) && ((steps / 10 < (endY - beginY)))) {
      StepsRightDown(beginX, beginY, endX, endY, delay, stepX, stepY);
    } //equation to prevent value / 0 errors. it wil just skip the function

I hope that's right. At least there is no more error comming up! :-)

Now all I need to know is how I can call these functions from within the room script, what parameters do I have to use and so on. Can you give a practical example?

Thanks so much for your help!!

Greetings
adrian

monkey0506

  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
    • monkey0506 worked on one or more games that won an AGS Award!
    •  
    • monkey0506 worked on one or more games that was nominated for an AGS Award!
Re: draw thick line slow
« Reply #8 on: 15 Mar 2010, 20:47 »
Sadly seeing as I didn't author the code I don't really know what to tell you to use as far as the parameters and such (as I said I didn't really analyze the code much).

But good point about me missing that closing parenthesis there. :D

Re: draw thick line slow
« Reply #9 on: 15 Mar 2010, 20:52 »
Never mind. Maybe I'll figure it out by myself. That was a big step foreward, thaks again!

By the way: I guess I shouldn't be the only one who would be glad about a module for connecting multiple points with a variable number of sub-points. Sounds interesting!

Bye!