473,621 Members | 2,743 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Drawing math shape

bH
Hi All,
I have been looking at javascript drawing from this website :

http://www.cwdjr.net/geometricDraw/pentagon_draw.h tml"

and I am wondering why the author made it
into two images : upper half then lower half?. Is there a rule that
says
you can't do it in one set of calculated values for all the points as
the points
are placed in the document.write( )?

The javascript is placed below for reference:
.....start of copied?

<script type="text/javascript">

document.bgColo r="000000";

var py1=150 // y position of center of pentagon ;
var px=272 // x psition of center of pentagon ;
var r1=150 // radius that just holds pentagon
var ctr=0 ; // division counter ;

anga=(2*Math.PI )/5 ;
sl=r1*Math.sin( (2*Math.PI)/5) ;
d=r1*Math.cos(( Math.PI)/5) ;
e=r1*Math.cos(( 2*Math.PI)/5) ;
h1=d+e ;
f=e*Math.tan(an ga) ;
px1=px-f ; px2=px+f ;
h2=r1-e ;
sbeta=e/r1 ;
gamma=(Math.PI - anga)/2 ;
phi=gamma+Math. asin(sbeta) ;
tphi=Math.tan(p hi) ;
line=px2-px1 ;

for (r=0;r<h2;r=r+1 ) {
z=Math.round((r *line)/(2*h2)) ;
x=px1+z ;
y=py1-r ;
wd=line-2*z ;
rd=255 ; gn=0 ; bl=0 ;
document.write( '<div id=\"a'+ctr+'\" style=\"positio n:absolute;
left:'+x+'px; top:'+y+'px; height: 1px; width:'+wd+'px;

background-color: rgb('+rd+','+gn +','+bl+'); z-index:1;
visibility:visi ble\"><\/div>') ;
ctr=ctr+1 ;
window.status=" DIVISIONS
WRITTEN="+ctr ;
for (r=0;r<h1;r=r+1 ) {
z=Math.round(r/tphi) ;
x=px1+z ;
y=py1+r ;
wd=line-2*z ;
rd=255 ; gn=0 ; bl=0 ;
document.write( '<div id=\"a'+ctr+'\" style=\"positio n:absolute;
left:'+x+'px; top:'+y+'px; height: 1px; width:'+wd+'px;

background-color: rgb('+rd+','+gn +','+bl+'); z-index:1;
visibility:visi ble\"><\/div>') ;
ctr=ctr+1 ;
window.status=" DIVISIONS WRITTEN="+ctr ;
}
</script>
</head>
<body>
<script type="text/javascript">
if (px1<0 || px1>544 || px2<=px1 || px2>544) {
window.status=" Input values too extreme." } ;
</script>

.....end of copied
TIA
bH
Aug 1 '08 #1
15 2936
bH wrote:
I have been looking at javascript drawing from this website :

http://www.cwdjr.net/geometricDraw/pentagon_draw.h tml"

and I am wondering why the author made it into two images : upper half
then lower half?.
There are no images. Firebug shows there are but a number of generated 1px
high HTML `div' elements, a rather stupid design.
Is there a rule that says you can't do it in one set of calculated values
for all the points as the points are placed in the document.write( )?
There is a rule that says: the right tool for the right purpose. The right
tool here is (standards-compliant) SVG (which is supported well enought to
be used in Wikipedia for all kinds of scalable graphics) or maybe
(proprietary) Canvas; certainly not plain HTML. The whole thing there is a
nice inefficient beginner's exercise, nothing more.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Aug 1 '08 #2
SAM
bH a écrit :
Hi All,
I have been looking at javascript drawing from this website :

http://www.cwdjr.net/geometricDraw/pentagon_draw.h tml"
In same idea :
<http://www.walterzorn. com/jsgraphics/jsgraphics_e.ht m>
and I am wondering why the author made it
into two images : upper half then lower half?.
perhaps because he could not resolve the drawing of a pentagone ?
and preferred to draw a triangle then a trapeze ?

How do you do to find the position of the 5 points of a pentagone
(relatively to x and y axes)
Same question using canvas or svg ... ? !

--
sm
Aug 1 '08 #3
Thomas 'PointedEars' Lahn wrote:
bH wrote:
>I have been looking at javascript drawing from this website :
>http://www.cwdjr.net/geometricDraw/pentagon_draw.h tml"
and I am wondering why the author made it into two images : upper half
then lower half?.

There are no images. *Firebug shows there are but a number of generated1px
high HTML `div' elements, a rather stupid design.
>Is there a rule that says you can't do it in one set of calculated values
for all the points as the points are placed in the document.write( *)?

There is a rule that says: the right tool for the right purpose. *The right
tool here is (standards-compliant) SVG (which is supported well enought to
be used in Wikipedia for all kinds of scalable graphics) or maybe
(proprietary) Canvas; certainly not plain HTML.
I would probably prefer a Google Chart that outputs PNG to an <img
srccall. For example, the requirement of the original poster:

http://chart.apis.google.com/chart?c...chf=c,s,000000

Manual:
http://code.google.com/apis/chart/

--
Bart
Aug 2 '08 #4
bH
On Aug 2, 9:31*am, Bart Van der Donck <b...@nijlen.co mwrote:
Thomas 'PointedEars' Lahn wrote:
bH wrote:
I have been looking at javascript drawing from this website :
>http://www.cwdjr.net/geometricDraw/pentagon_draw.h tml"
and I am wondering why the author made it into two images : upper half
then lower half?.
There are no images. *Firebug shows there are but a number of generated 1px
high HTML `div' elements, a rather stupid design.
Is there a rule that says you can't do it in one set of calculated values
for all the points as the points are placed in the document.write( *)?
There is a rule that says: the right tool for the right purpose. *Theright
tool here is (standards-compliant) SVG (which is supported well enoughtto
be used in Wikipedia for all kinds of scalable graphics) or maybe
(proprietary) Canvas; certainly not plain HTML.

I would probably prefer a Google Chart that outputs PNG to an <img
srccall. For example, the requirement of the original poster:

http://chart.apis.google.com/chart?c...d=t:70,70,70,7...

Manual:http://code.google.com/apis/chart/

--
*Bart- Hide quoted text -

- Show quoted text -
Hi Bart,
The demo is really an eye popper. And it was easy to make color
and size adjustments. For me it was a first time to visit this
web site.

Thanks

bH
Aug 3 '08 #5
bH wrote:
On Aug 2, 9:31*am, Bart Van der Donck <b...@nijlen.co mwrote:
>http://chart.apis.google.com/chart?c...chf=c,s,000000

The demo is really an eye popper. And it was easy to make color
and size adjustments. For me it was a first time to visit this
web site.
Thanks. I think the other equivalents are also quite easy.

--------------------------------------------------------------------
pentagon.svg
http://www.w3.org/TR/SVG/shapes.html#PolygonElement
--------------------------------------------------------------------
<?xml version="1.0" standalone="yes "?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="400" height="400" style="backgrou nd-color: black"
xmlns="http://www.w3.org/2000/svg" version="1.1">
<polygon fill="red" stroke="red" stroke-width="1"
points="145,15 277,111 227,266 63,266 13,111" />
</svg>
--------------------------------------------------------------------

Problem is that MSIE doesn't know the .svg-extension, so it will offer
the file for download by default. One could do it in (the immensely
inpopular) VML, like e.g. Google Maps does.

--------------------------------------------------------------------
pentagon.htm for MSIE
http://msdn.microsoft.com/en-us/libr...80(VS.85).aspx
--------------------------------------------------------------------
<html>
<head>
<title>Red Pentagon in VML</title>
<style>
v\: * {
behavior:url(#d efault#VML);
display:inline-block
}
</style>
</head>
<body style="backgrou nd-color: black">
<xml:namespac e ns="urn:schema s-microsoft-com:vml" prefix="v"/>
<v:polyline strokecolor="re d" strokeweight="1 px" fillcolor="red"
points="145px,1 5px,277px,111px ,227px,266px,63 px,266px,13px,1 11px"
/>
</body>
</html>
--------------------------------------------------------------------

Walter Zorn has done investigations how to do it in javascript:
http://www.walterzorn.com/
http://www.walterzorn.com/jsgraphics/jsgraphics_e.htm

Generally, I think the Google Chart should be the best choice here.

Cheers

--
Bart
Aug 3 '08 #6
On Aug 1, 8:19*pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
maybe (proprietary) Canvas;
As "propietary " as any other w3c open standard can be : <http://
www.w3.org/TR/html5/the-canvas.html#the-canvas>

--Jorge.
Aug 3 '08 #7
Bart Van der Donck wrote:
Walter Zorn has done investigations how to do it in javascript:
http://www.walterzorn.com/
http://www.walterzorn.com/jsgraphics/jsgraphics_e.htm
It talks about "canvas", but eventually it is just a more sophisticated
`div' element nonsense.
PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Aug 3 '08 #8
bH
On Aug 3, 10:21*am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
Bart Van der Donck wrote:
Walter Zorn has done investigations how to do it in javascript:
http://www.walterzorn.com/
http://www.walterzorn.com/jsgraphics/jsgraphics_e.htm

It talks about "canvas", but eventually it is just a more sophisticated
`div' element nonsense.

PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
* * navigator.userA gent.indexOf('M SIE 5') != -1
* * && navigator.userA gent.indexOf('M ac') != -1
) *// Plone, register_functi on.js:16
Hi All,
Thanks for your efforts to present the "store house of graphic
options"
I would guess that it would take a while to "discover" those (+,+)and
(-,-)
of each.

bH

P.S Bart, up above, you wrote "One could do it in (the immensely
inpopular) VML" was that a typo for "unpopular" .
if it is, I would like to ask "why is it unpopular?"

Aug 3 '08 #9
On Aug 2, 2:19*am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
bH wrote:
I have been looking at javascript drawing from this website :
http://www.cwdjr.net/geometricDraw/pentagon_draw.h tml"
and I am wondering why the author made it into two images : upper half
then lower half?.

There are no images. *Firebug shows there are but a number of generated1px
high HTML `div' elements, a rather stupid design.

There is a rule that says: the right tool for the right purpose. *The right
tool here is (standards-compliant) SVG (which is supported well enought to
be used in Wikipedia for all kinds of scalable graphics)
SVG is unfortunately not well supported at all. On IE and Firefox <= 2
you'd need the Adobe SVG plugin to see SVG on web pages. Unfortunately
that plugin is nowhere near as polished as Adobe's Flash plugin. It
crashed both IE and Firefox the last time I tried it and when it works
the rendering was buggy for some of my SVG files.

For the record, Wikipedia does not *serve* SVG content. They just
allow you to upload SVG files which they'll automatically render to
PNG on their server. Saying SVG support on the web is good because you
can use them on Wikipedia is like saying MS Word doc file support on
the web is good because you can use then on Google Docs.
Aug 3 '08 #10

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

Similar topics

0
1505
by: Andrew James | last post by:
Gentlemen, I'm looking for a graphing or drawing python package that will allow me to draw complex geometric shapes. I need to be able to create shapes like cogwheels and Venn diagrams: http://encyclopedia.thefreedictionary.com/Venn The library must support alpha blending and the ability to return x,y co-ordinates for a shape, as I want to draw an imagemap on top of parts of the shape.
8
48023
by: Stefan Burger | last post by:
Those of you who are in need for drawing vector lines might be interested in the following code. DrawLine( x1, y1, x2, y2, color ) draws a vector line from any Point x1,y1 to any Point x2,y2 in any color (string format #RRGGBB) by using div-tags. regards Stefan ###############code starts here#########################
0
2791
by: Ron Adam | last post by:
I want to be able to easily create reusable shapes in Tkinter and be able to use them in mid level dialogs. So after some experimenting I've managed to get something to work. The following does pretty much what I need, but I think it can be improved on. So could anyone take a look and let me know what you think? Some of the things I want to add, but aren't exactly sure how at this time: Nested groups Use tags to be able to change sub...
4
2048
by: easily confused | last post by:
Ok so im going intomaking a tetris type program and was wondering how i would move the drawing after i have crated the shape for the shape i have this code .... Public Class Form1 Public Sub PictureBox1_Paint1(ByVal sender As System.Object, ByVal Block1 As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint Block1.Graphics.FillRectangle(Brushes.Blue, 0, 0, 25, 30) Block1.Graphics.FillRectangle(Brushes.Blue, 25, 0, 25, 30)
9
3167
by: davetelling | last post by:
I am not a programmer, I'm an engineer trying to make an interface to a product I'm designing. I have used C# to make a form that interrogates the unit via the serial port and receives the data. I want to be able to draw lines in a picturebox based upon certain data points I have received. I dragged a picturebox from the toolbar onto my form, but after having gone through the help files, looking online and trying a variety of things, I...
4
26975
by: RobinS | last post by:
I am drawing a rectangle on a picture that has already been drawn on the graphics area (a user control). It works something like this: //in the MouseDown event m_isDragging = true; m_oldX = e.X; //save original positions m_oldY = e.Y; //in the MouseMove event if (m_isDragging)
15
4021
by: javelin | last post by:
I need to be able to create a javascript based drawing/signature box, and be able to save it. Can someone refer me to a script that will allow this, or even a 3rd party package for sale? It can't be Java or ActiveX. Thank you.
7
2138
by: serave | last post by:
Hi i'm new in this group. I need some help with php. I need to draw any mathematical function i get through a form? Please help me
6
8012
by: charindal | last post by:
i am trying to create a program that is able to draw a housing plan. the user should be able to input the required meters then upon clicking a left,right,up, down button, the system draws a line in that direction. I have managed to do this but however how do i protect my painted window when it has been obscured by another window. i also would like to be able to click on corners and be able to draw interior walls from a point marked from a...
0
8213
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
8156
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
8653
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...
0
8597
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8306
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
7127
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
4065
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
1763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1460
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.