B
B
Borislav Yanchenko2019-02-15 14:21:12
Java
Borislav Yanchenko, 2019-02-15 14:21:12

How to draw a line with my point drawing method?

I have my own method for drawing a point, you can't use another one. I need to draw a line. We need some ready-made line drawing method that can be easily changed.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton Kuznetsov, 2019-02-15
@Kuznetsov

Most likely, your method takes X and Y coordinate parameters. Therefore, you just need to call it in a loop, changing one of the coordinates in each iteration: X for a horizontal line, Y for a vertical one. Well, or both - for the diagonal)

W
Warlodya, 2019-02-15
@Warlodya

You can use the Bresenham algorithm
https://ru.wikipedia.org/wiki/%D0%90%D0%BB%D0%B3%D...
https://ru.wikibooks.org/wiki/%D0%A0% D0%B5%D0%B0%D...

E
Evgeny Petryaev, 2019-02-16
@Gremlin92

width=300;
height=300;
CreateWindowEx(hwnd,width,height);
color = red;
x = 100;
for(int i=0;i<100;i++)
{
    SetPixel(i,x,red);//горизонтальная линия
    SetPixel(x,i,red);//вертикальная линия
    SetPixel(i,i,red);//диагональная линия
}
SwapBuffers(doubleBuffer,hwnd);

I can't vouch for the correctness of the code I haven't coded for a long time

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question