G
Gatorchopps
Guest
Hello.
I've been working on a program that draws lines that spawn more lines at various angles to create a sort of art experiment. Stuff like this:
Each line should draw itself to a surface pixel by pixel while checking for collisions with other lines and objects. This works for the most part except at some specific angles it seems. Essentially what I'm having each object do is:
You'll notice the lines on the right side terminated themselves for some reason. I'm just stumped on why only some of the lines are doing this. I think it may have something to do with the object moving less then a pixel some steps and detecting the previous steps pixel and destroying it self. I can't seem to find a solution and any help would be appreciated!
Here's the code for the line objects:
I'll attach the .gmz file if needed. Thanks!
I've been working on a program that draws lines that spawn more lines at various angles to create a sort of art experiment. Stuff like this:
Each line should draw itself to a surface pixel by pixel while checking for collisions with other lines and objects. This works for the most part except at some specific angles it seems. Essentially what I'm having each object do is:
- Draw a pixel at it's current location
- Move 1 pixel in a specific direction (using lengthdir_x/y functions)
- Check new location for pre-existing pixels and if so destroy self
- repeat until destroyed or it gets to the specified length
You'll notice the lines on the right side terminated themselves for some reason. I'm just stumped on why only some of the lines are doing this. I think it may have something to do with the object moving less then a pixel some steps and detecting the previous steps pixel and destroying it self. I can't seem to find a solution and any help would be appreciated!
Here's the code for the line objects:
Code:
//Length to draw line before spawning more lines
length = 50
//How many new lines to spawn
spawns = 6
//Direction to draw lines
dir = 90
//Color of line
color = c_lime
//Current distance traveled
dist = 0
//If lines should die if they collide
kill = true
Code:
surface_set_target(global.canvas)
//Draw point on canvas
draw_point_color(x,y,color)
//Move object towards it's direction
x+= lengthdir_x(1,dir)
y+= lengthdir_y(1,dir)
//Increase distanc counter
dist +=1
surface_reset_target()
//If object has reached its max length spawn new objects and destroy self
if dist >= length
{
var inst, inc;
inc = 360/spawns
for(i=0;i<spawns;i+=1)
{
inst= instance_create(x+round(lengthdir_x(1,dir)),y+round(lengthdir_y(1,dir)),obj_spawn)
inst.dir = dir
dir+=inc
}
instance_destroy()
}
////////////
var col, alpha;
if kill = true
{
//If there is a pixel at the objects location destroy self
col = surface_getpixel_ext(global.canvas,x, y);
alpha = (col >> 24) & 255;
if alpha = 255
{
instance_destroy()
//show_message("alpha")
}
// If object is outside the room destroy it (with a buffer of 10 pixels)
if x>=room_width-10
{
instance_destroy()
//show_message("x>room")
}
if y>=room_height-10
{
instance_destroy()
//show_message("y>room")
}
if x<=10
{
instance_destroy()
//show_message("x<0")
}
if y<=10
{
instance_destroy()
//show_message("y<0")
}
}
I'll attach the .gmz file if needed. Thanks!