469,934 Members | 2,757 Online

how to draw a dashed line in c 106 100+
can anybody tell me how to draw a dashed line in c

i've drawn a dotted one using a simple for but i can't figure out how to make it dashed ... i need a for loop that is increasing constantly but skips afew pixels in the way and then continue drawing again

here's the one i used to draw the dotted line
y=y1 where x1,y1 are start points x2,y2 end points
for( x=x1;x<=x2;x+=3)

{ putpixel(x,y,color);
}
Oct 26 '06 #1
4 11556 dtimes6
73 Try something like
Expand|Select|Wrap|Line Numbers
1. for( x1 = sx, y1 = sy; (x1 < ex)&&(y1 < ey); x1+=(dx*2), y1+=(dy*2)) {
2.     MoveTo(x1,y1); //Move To the pos don't draw line
3.     x2=x1+dx;
4.     y2=y1+dy;
5.     LineTo(x2,y2); //Line from (x1,y1) to (x2,y2)
6. }
7.
Oct 27 '06 #2
drnrusu
6 can anybody tell me how to draw a dashed line in c

i've drawn a dotted one using a simple for but i can't figure out how to make it dashed ... i need a for loop that is increasing constantly but skips afew pixels in the way and then continue drawing again

here's the one i used to draw the dotted line
y=y1 where x1,y1 are start points x2,y2 end points
for( x=x1;x<=x2;x+=3)

{ putpixel(x,y,color);
}
This is a very intresting ideea of drawing a line. I'll try it.
Sep 17 '07 #3
1 Try something like
Expand|Select|Wrap|Line Numbers
1. for( x1 = sx, y1 = sy; (x1 < ex)&&(y1 < ey); x1+=(dx*2), y1+=(dy*2)) {
2.     MoveTo(x1,y1); //Move To the pos don't draw line
3.     x2=x1+dx;
4.     y2=y1+dy;
5.     LineTo(x2,y2); //Line from (x1,y1) to (x2,y2)
6. }
7.

i m trying to solve this problem using c code
for(k=1;k<steps;k++)
{
x+=xinc;
y+=yinc;
if(cnt==0 || cnt > 5)
{
putpixel(x,y,15);
}
if(cnt >= 5 )
{
for(i=0;i<5;i++)
{
putpixel(x,y,0);
}
cnt=0;
}
}
problem is that only one space of blank space will be considered in dashed line.
Jul 10 '08 #4
hdanw
61 A dash is made up of dots.

Try putting your dots really close to gether for a while, then skip some space, and put them close together for another while...

Should look somehting like this:

..... ..... ..... ..... ..... .....
Jul 12 '08 #5

 7 posts views Thread by Florian Lindner | last post: by 3 posts views Thread by LadyKnight | last post: by 4 posts views Thread by thomasp | last post: by 2 posts views Thread by dan heskett | last post: by 4 posts views Thread by Geoff | last post: by 4 posts views Thread by Jason Huang | last post: by 9 posts views Thread by zhaow | last post: by 8 posts views Thread by Mel | last post: by reply views Thread by Red Head | last post: by reply views Thread by eddparker01 | last post: by reply views Thread by eddparker01 | last post: by reply views Thread by lanliddd | last post: by reply views Thread by isladogs | last post: by 1 post views Thread by isladogs | last post: by reply views Thread by Trystan | last post: by reply views Thread by Trystan | last post: by 1 post views Thread by skydivetom | last post: by 1 post views Thread by MikeCant | last post: by