![]() |
|
Line Algorihtm |
fatboy2
Member #8,239
January 2007
|
I need help with writing a line drawing algorithm. I want the line to start from a fixed point and then draw to different points. For example, the line starts from a fixed point and then draws to where the mouse is. I want the line to change each time I move the mouse. i want the line to be drawn like in Ms Paint. |
Matthew Leverton
Supreme Loser
January 1999
![]() |
|
fatboy2
Member #8,239
January 2007
|
But that would draw only one line, i want the line to constantly change shape as i pull the mouse, like MsPaint |
Matthew Leverton
Supreme Loser
January 1999
![]() |
Your problem is so simple, you really should try to think about how to solve it yourself. If you cannot, then you really should get a new hobby. |
Mr. Big
Member #6,196
September 2005
|
A line is a line. |
fatboy2
Member #8,239
January 2007
|
I do not need animation, I want to be able to drag the line with the mouse like in Paint in real time. The routine that you gave me would draw lots of lines instead of 1. PS If my problem is so simple why do not you just give the answer? |
Mr. Big
Member #6,196
September 2005
|
Programmers these days aren't what they used to be, are they? P.S: |
Evert
Member #794
November 2000
![]() |
Quote: If my problem is so simple why do not you just give the answer? Because you should really be able to think of it yourself if you ever want to do any serious programming, that's why. Definately not because we don't know how. Anyway, here's a hint to get you started: you draw a line from (x, y) to the location of the mouse. Then the mouse moves, and you draw a new line to its new position. Your problem? The old line is still there. You figure it out from here. By the way, Quote: like in Paint This is not as clear a reference as you might think it is. |
fatboy2
Member #8,239
January 2007
|
I knew that the problem is the old present without you having to tell me. I do not know how to get rid of the old line. I think that it is possible to remove the old lines by plotting individual pixels along them. The thing is also that I want to be able to do that on various backgrounds, so I need to take the color of each point on the line and then plot pixels with the colors that these pixels were previously. PS I think that you are all just making up excuses for not helping |
Matthew Leverton
Supreme Loser
January 1999
![]() |
Have you ever heard of double buffering? You're supposed to draw from all of your sources to an intermediate bitmap. Then you copy that bitmap to the screen. Once you do that, your problem is trivial. |
Mr. Big
Member #6,196
September 2005
|
Basically, if you're writing a paint program, you'll need two bitmaps. (Not counting 'screen'.) |
Evert
Member #794
November 2000
![]() |
Quote: The thing is also that I want to be able to do that on various backgrounds, so I need to take the color of each point on the line and then plot pixels with the colors that these pixels were previously. That's already a better question to ask, because it at least makes it clear that you've actually thought about the problem. This isn't clear in your original message. Quote: I think that you are all just making up excuses for not helping Right. On that note, don't expect help from me in the future. |
gnolam
Member #2,030
March 2002
![]() |
Quote: PS I think that you are all just making up excuses for not helping
Matthew already told you what that "excuse" is. If you can't figure this out after the information you've already been given, programming just isn't for you. Seriously. -- |
Johan Halmén
Member #1,550
September 2001
|
What we have here is a difficulty to exactly know the level of abstraction. I have a strange BASIC tool on my old Mac (68k). It had this funny sprite data type. You could define a variable as a sprite and attach it to a bitmap resource. Then you could perform some draw_sprite function that place the sprite on the screen. And doing draw_sprite again with other coordinates moved the sprite to its new place. So the sprite could be seen only on one place on the screen at a time. A bit like the line drawing thing fatboy2 is asking for. Programming with Allegro is on a lower abstraction level. "Line writing algorithm" is in the first place wrong terminology for fatboy2's problem. As Matthew said, this is a very simple thing. Only that no one would expect such a function to be incorporated in Allegro's set of drawing primitives functions. That said, *click* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
kentl
Member #2,905
November 2002
|
fatboy2:
Translate it all to C and Allegro API calls. You will get a program that does the above, however you probably won't be satisfied as the line flickers terribly. Now it's time to add double buffering to it to fix the flicker. Come back and post the code you've got for the little algorithm above without double buffering. Then we'll talk about double buffering to get rid of the flicker and to have different backgrounds to get it as you want it to be. |
Johan Halmén
Member #1,550
September 2001
|
[branestorming] When line gets first time drawn: When next line gets drawn: This might be faster than the double buffering and blitting.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
Neil Black
Member #7,867
October 2006
![]() |
I used the same method as Mr. Big when I was making a sprite editor. Of course, that project died when I found Allegro Sprite Editor ^-^, but the line function worked great.
|
|