473,508 Members | 2,324 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 30726
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.javascript 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.javascript 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.javascript 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:schemas-microsoft-com:vml">
<head>
<title>VML Test</title>

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

<style type="text/css">
v\:* { behavior: url(#default#VML);}
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="vmlMainFrame"
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.isVMLEnabled = true;
</script>
<![endif]-->
<script>
if(self.isVMLEnabled == 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.mozdev.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.com/schools_ring/VML_SVG.html>

To get a copy of the page w/o Yahoo's crap go to:
<<http://www.geocities.com/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
9679
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...
1
2150
by: smilnet | last post by:
I want to Make a Draw Line Contrls,Please Help me Thanks!
4
5141
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...
1
2551
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)...
1
12703
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...
4
6058
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
1949
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....
0
1200
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
9013
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...
0
7229
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
7129
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...
1
7061
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...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5637
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,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3208
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...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1566
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 ...

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.