473,714 Members | 2,464 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

javascript basics draw a line

R
Hello everybody!

I'm newbie to JavaScript and I have a basic question.

I have X and Y coordinates of A and B points.

How can I draw a line connecting A and B?

thanks in advance
cheers
R

Jul 24 '05 #1
6 30745
Hi R,

R wrote:
Hello everybody!

I'm newbie to JavaScript and I have a basic question.

I have X and Y coordinates of A and B points.

How can I draw a line connecting A and B?

thanks in advance
cheers
R


Javascript does not have a mechanism to do graphics (such as drawing a
line). But there are ways to simulate this. Check out this page:
http://www.walterzorn.com/jsgraphics/jsgraphics_e.htm

Jul 24 '05 #2
ASM
R wrote:
Hello everybody!

I'm newbie to JavaScript and I have a basic question.

I have X and Y coordinates of A and B points.

How can I draw a line connecting A and B?


you take your ruler and your pencil and trace it

not possible in JavaScript

you can simulate a vertical or horizontal line
with a div reduced to 1 px (width or height)
and no more

You can also use an image of a sqare with a diagonal drawn
and resize the image betwen the 2 points

+---+ B
| /|
| / |
|/ |
+---+
A

--
Stephane Moriaux et son [moins] vieux Mac
Jul 24 '05 #3
R said the following on 7/24/2005 3:32 PM:
Hello everybody!

I'm newbie to JavaScript and I have a basic question.

I have X and Y coordinates of A and B points.

How can I draw a line connecting A and B?


<URL: http://members.aol.com/hikksnotathom...hit/index.html >

Something like that?
Click two points in the blue, it "draws" a red line between them.
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 24 '05 #4
Randy Webb wrote:
R said the following on 7/24/2005 3:32 PM:
Hello everybody!

I'm newbie to JavaScript and I have a basic question.

I have X and Y coordinates of A and B points.

How can I draw a line connecting A and B?


<URL: http://members.aol.com/hikksnotathom...hit/index.html >

Something like that?
Click two points in the blue, it "draws" a red line between them.
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly


I must say, I've always toyed with the idea of line drawing but... 400
DIVs is a bit excessive, in my opinion. It's an incredibly brute-force
solution, but it does get the mental cogs clicking.

Seems simpler to JS-generate an arbitrary number of spans with custom
widths based on each line's pixel requirements. The height would always
be 1px, and the top would always be 1px different from the previous.

i.e. for a line 0,0 to 100,100, JS-create 100 spans of 1px width, with
incremented values for top.

For a line 0,0 to 100,1, JS-create two spans of 50px width, the first
from 0,0 to 50,0, and the second from 50,1 to 100,1.

Interesting... I may end up doodling out a Line object because of this
madness.

hm.

Always seemed of very limited practical use, though.

Jul 25 '05 #5
VK


Christopher J. Hahn wrote:
Randy Webb wrote:
R said the following on 7/24/2005 3:32 PM:
Hello everybody!

I'm newbie to JavaScript and I have a basic question.

I have X and Y coordinates of A and B points.

How can I draw a line connecting A and B?


<URL: http://members.aol.com/hikksnotathom...hit/index.html >

Something like that?
Click two points in the blue, it "draws" a red line between them.
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly


I must say, I've always toyed with the idea of line drawing but... 400
DIVs is a bit excessive, in my opinion. It's an incredibly brute-force
solution, but it does get the mental cogs clicking.

Seems simpler to JS-generate an arbitrary number of spans with custom
widths based on each line's pixel requirements. The height would always
be 1px, and the top would always be 1px different from the previous.

i.e. for a line 0,0 to 100,100, JS-create 100 spans of 1px width, with
incremented values for top.

For a line 0,0 to 100,1, JS-create two spans of 50px width, the first
from 0,0 to 50,0, and the second from 50,1 to 100,1.

Interesting... I may end up doodling out a Line object because of this
madness.

hm.

Always seemed of very limited practical use, though.

Why so complicated?! Internet Explorer has build-in VML module (IE 5
and higher). For others there is SVG plug-in.
Both VML and SVG can be fully JavaScript driven, so you can do
anything: from simple lines to interactive virtual worlds.

I'm just started with SVG (after VML), so instead of the requested line
I used a 3rd party sample. But the idea is rather clear I hope.
<html xmlns:v="urn:sc hemas-microsoft-com:vml">
<head>
<title>VML Test</title>

<script type="text/javascript">
function drawLine() {
/*@cc_on @*/
/*@if (@_jscript_vers ion >= 4)
var A = [10,150];
var B = [400,200];
var myLine = document.getEle mentById('line0 1');
myLine.from = A;
myLine.to = B;
/*@end @*/
}
window.onload = drawLine;
</script>

<style type="text/css">
v\:* { behavior: url(#default#VM L);}
body { background-color: #FFFFFF}
</style>

</head>

<body>

<!--[if gte IE 5]>
<v:group id="vmlApp"
style="position : absolute; left: 50px; top: 50px; height: 300px;
width: 500px"
coordorigin="0, 0"
coordsize="500, 300">
<v:rect id="vmlMainFram e"
style="position :absolute; top:0px; left:0px; width:500px;
height:300px">
<v:fill
color="#FFFFFF"/>
<v:stroke
color="#000000"
weight="2px"/>
</v:rect>
<v:line id="line01">
</v:line>
</v:group>
<script type="text/JScript">
self.isVMLEnabl ed = true;
</script>
<![endif]-->
<script>
if(self.isVMLEn abled == undefined) {
document.write( '<embed width="222" height="300"
src="http://www.carto.net/papers/svg/samples/shapes.svg"
name="printable _map" type="image/svg+xml">');
}
</script>
</body>
</html>
More interesting reading:

<http://msdn.microsoft. com/library/default.asp?url =/workshop/author/vml/>
<http://www.mozilla.org/projects/svg/>
<http://plugindoc.mozde v.org/windows.html>

Jul 25 '05 #6
VK
If anyone is still interested:

A ready to use VML/SVG compatible block is located here:

<http://www.geocities.c om/schools_ring/VML_SVG.html>

To get a copy of the page w/o Yahoo's crap go to:
<<http://www.geocities.c om/schools_ring/VML_SVG.zip>

This test line drawer is fully functional for IE users from the scratch
(no additional soft is needed).

For other browsers it will be proposed to install Adobe SVG plugin.

SVG version of the line drawer is not ready (I'm still studying SVG) so
a 3rd party placeholder is used.

Jul 26 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
9703
by: Dennis | last post by:
Hello, Ive to draw a line on a picture i used this code: Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) x1 = z.X y1 = z.Y lbl3 = "x1: " & x1 lbl4 = "y1: " & y1
1
2164
by: smilnet | last post by:
I want to Make a Draw Line Contrls,Please Help me Thanks!
4
5157
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 define line. Dim point1 As New Point(100, 100) Dim point2 As New Point(500, 100)
1
2570
by: Alejandro | last post by:
Hi, I Have a form with Collection of 52 picturebox. Public cl As New Collection Private m_Bitmap As Bitmap Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
1
12719
by: balakrishnan.dinesh | last post by:
Hi frnds, Im creating function to plot line graph in javascript . I have marked the points in graph. but what i need to do is, i want to draw the line between those marked point, but i dont konw how to draw line betwwen the marked points The output for my function will be like this , So the marked point (*) should be connected through lines,
4
6075
by: =?Utf-8?B?bWFydGluMQ==?= | last post by:
Hi, All, I want to draw line chart on the web using visual basic 2005, vb 2005 doesn't have chart components, so can anyone point out where I can start working this? Thanks, Ma
2
1964
by: Chetana | last post by:
Hi , I have created one application which has multiple lat and lon values . I want to draw a polyline for those point .I am not using google map so I want function in javascript to draw line. If anyone has any idea about this reply me immidiately. Thanks.
0
1224
by: joshguru | last post by:
i have to draw a line by mouse after i clicked the button "draw line" in my form in vb.net....send me sample coding.........
1
9051
by: Joe Elliot | last post by:
Hi All, could anyone help me with how to draw in picturebox (c#) line, using equation ax + by + c = 0. As a result from calculation I have calculate a, b,c, but now I need draw line to picturebox with this I try calculate: x=-c-y*b/a z=-c-a*x/b double x = new double; double y = new double;
0
8801
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8707
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7953
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5947
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4464
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3158
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2110
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.