Login | Register

Script to draw a diagram

July 18, 2006, 11:36 by Calle
[loading]
-->
This script is created by myself, although I never used it for anything, I hope someone else can use it for something:
<div style="clear: both;">
//Argument 0 = diagram width
//Argument 1 = diagram height
//Argument 2 = the lowest value (vertical)
//Argument 3 = highest value (vertical)
//Argument 4 = the lowest value (horizontal)
//Argument 5 = highest value (horizontal)

//X-variable = global.xpos
//Y-variable = global.ypos
//Setting-variabel = global.settings
//Setting 1 = Interval for the vertical
//Setting 2 = Interval for the vertical

//Typical call: script_dots(600,440,1,10,1,20)

//Basic settings
st_x = 20;
st_y = room_height-20;

draw_line(st_x,st_y,st_x+argument0,st_y);
draw_line(st_x,st_y,st_x,st_y-argument1);

i = argument2;
dx = argument0/argument5;
dy = argument1/argument3;
da = argument3/(argument1/string_height("1";))
while(i-1<argument3) {
draw_text(st_x-(string_width(string(i))+5),
st_y-dy*i-string_height(string(i))/2,i);
i += global.settings[1]*ceil(da);
}

i = argument4;
draw_set_halign(fa_center);
da = argument5/(argument0/string_width("_";));
while(i-1<argument5) {
draw_text(st_x+dx*i,st_y+(string_height(string(i)))-15,i);
i += global.settings[1]*ceil(da);
}

//Restore settings
draw_set_halign(fa_left);

//Draw the line

l = 1;
while(l<global.lnr) {
i = 0;
prev_x = global.xpos[1,l];
prev_y = global.ypos[1,l];
while(i<100) {
if (global.xpos[i,l]*dx<argument0)
&& (global.ypos[i,l]*dy<argument1) {
draw_line(st_x+prev_x*dx,st_y-prev_y*dy,st_x+global.xpos[i,l]*dx,
st_y-global.ypos[i,l]*dy);
draw_point(st_x+global.xpos[i,l]*dx,st_y-global.ypos[i,l]*dy);
}
prev_x = global.xpos[i,l];
prev_y = global.ypos[i,l];
i+=1;
}
l +=1;
}
</div>

I wrote this script a long time ago as a part of a program I was creating. Just look at all the options the user got! A typical call would look like this:

script_dots(600,440,1,50,1,5);

And besides, the user got even more choices with the variables listed. There are even more, not mentioned in the script, the values to draw, initialized like this:

global.ypos[100,global.lnr+1] = 0
global.ypos[1,2] = 3
global.ypos[2,2] = 20
global.ypos[6,2] = 7
global.ypos[10,2] = 3
global.ypos[3,2] = 7


And of course the same way for global.xpos, note that the second variable defines which line the value is added to. This means you can have multiple lines.

Obviously the script itself should be called in draw event and initializing anywhere, but before the script is called. In my program I also had another piece of code added to my script:

//Draw background
draw_sprite_stretched("",0,st_x-20,st_y-
argument1-0.1*argument1,argument0+0.1*argument0,argument1+0.2*argument1);
//Draw background
draw_sprite_stretched("",0,st_x,st_y-argument1,
argument0,argument1);


This made the diagram a little bit fancier. I won’t explain all of this code (it’s obvious anyway), you ask instead and I’ll answer.

Comments

Loading comments... [loading]
.
Users logged in:

game maker articles, game maker examples, game maker tutorials, gmtutorials, game maker questions and answers, game maker crash course, how to create games