Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Drawing a line

Use this:
Code:
class Bitmap
def draw_line(x1, y1, x2, y2)
    color = Color.new(255, 255, 255, 255)
    if x1 == x2
      x = x1
      for y in (y1 < y2 ? y1..y2 : y2..y1)
        set_pixel(x, y, color)
      end
    else
      a = (y2-y1)/(x2-x1).to_f
      if -1 < a and a < 1
        for x in (x1 < x2 ? x1..x2 : x2..x1)
          y = a * (x - x1) + y1
          set_pixel(x, y, color)
        end
      else
        for y in (y1 < y2 ? y1..y2 : y2..y1)
          x = (y - y1) / a + x1
          set_pixel(x, y, color)
        end
      end
    end
  end
end
This function, draws a line from point x1, y1 to x2, y2.
 

rutix

Member

hehe thnx :) i will expand it a little bit ^^

Edit: I get error:
undefined method `draw_line` for #<Scene_Menu::Window_1:0x15bb390>

Edit: Never mind made a very stupid mistake ^^
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top