473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 13361
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
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
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

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Florian Lindner | last post by:
Hello, I'm looking for a program or python library to draw graphs. They should look like the that: /--------\ /--------\ | Node A | ------ belongs to ----> | Node B |...
3
by: LadyKnight | last post by:
I am trying to build a new personal homepage and decided to try using CSS for the first time. I came across some dashed underlines for links on this page (and several others): ...
4
by: thomasp | last post by:
I found the following code on MSDN to draw a line in VB2005. Public Sub DrawLinePoint(ByVal e As PaintEventArgs) ' Create pen. Dim blackPen As New Pen(Color.Black, 3) ' Create points that...
2
by: dan heskett | last post by:
I am owner-drawing a listbox, in an attempt to create a nice list with some custom "fields" and text layout. Essentially it works, but I must be missing something big, conceptually, because I...
4
by: Geoff | last post by:
Hi Can anybody give me some ideas/code to get a dashed line on a form to be animated i.e. the dashed lines move in one direction? Thanks in advance Geoff
4
by: Jason Huang | last post by:
Hi, In my C# Windows Form, how do I draw a Line? Thanks for help. Jason
9
by: zhaow | last post by:
Hi, All Greetings! I want to develop as appllication that requires a line-drawing function in the blank area between two forms. I have looked up the MSDN, it says that a graphics object need a...
8
by: Mel | last post by:
I need to draw a red frame around the element under current pointer. I have seen it done in debuggers, but need to have it in my application, without the need to download and install...
0
by: Red Head | last post by:
Hello I've written some code to draw a rectangle on a picture box when the user moves the mouse. (the previous rectangle is cleared) This works fine but the very first rectangle is not removed...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.