By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,886 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

Drawing math shape

P: n/a
bH
Hi All,
I have been looking at javascript drawing from this website :

http://www.cwdjr.net/geometricDraw/pentagon_draw.html"

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.bgColor="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(anga) ;
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(phi) ;
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=\"position:absolute;
left:'+x+'px; top:'+y+'px; height: 1px; width:'+wd+'px;

background-color: rgb('+rd+','+gn+','+bl+'); z-index:1;
visibility:visible\"><\/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=\"position:absolute;
left:'+x+'px; top:'+y+'px; height: 1px; width:'+wd+'px;

background-color: rgb('+rd+','+gn+','+bl+'); z-index:1;
visibility:visible\"><\/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
Share this Question
Share on Google+
15 Replies


P: n/a
bH wrote:
I have been looking at javascript drawing from this website :

http://www.cwdjr.net/geometricDraw/pentagon_draw.html"

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

P: n/a
SAM
bH a écrit :
Hi All,
I have been looking at javascript drawing from this website :

http://www.cwdjr.net/geometricDraw/pentagon_draw.html"
In same idea :
<http://www.walterzorn.com/jsgraphics/jsgraphics_e.htm>
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

P: n/a
Thomas 'PointedEars' Lahn wrote:
bH wrote:
>I have been looking at javascript drawing from this website :
>http://www.cwdjr.net/geometricDraw/pentagon_draw.html"
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

P: n/a
bH
On Aug 2, 9:31*am, Bart Van der Donck <b...@nijlen.comwrote:
Thomas 'PointedEars' Lahn wrote:
bH wrote:
I have been looking at javascript drawing from this website :
>http://www.cwdjr.net/geometricDraw/pentagon_draw.html"
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

P: n/a
bH wrote:
On Aug 2, 9:31*am, Bart Van der Donck <b...@nijlen.comwrote:
>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="background-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(#default#VML);
display:inline-block
}
</style>
</head>
<body style="background-color: black">
<xml:namespace ns="urn:schemas-microsoft-com:vml" prefix="v"/>
<v:polyline strokecolor="red" strokeweight="1px" fillcolor="red"
points="145px,15px,277px,111px,227px,266px,63px,26 6px,13px,111px"
/>
</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

P: n/a
On Aug 1, 8:19*pm, Thomas 'PointedEars' Lahn <PointedE...@web.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

P: n/a
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 bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Aug 3 '08 #8

P: n/a
bH
On Aug 3, 10:21*am, Thomas 'PointedEars' Lahn <PointedE...@web.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 bugRiddenCrashPronePieceOfJunk = (
* * navigator.userAgent.indexOf('MSIE 5') != -1
* * && navigator.userAgent.indexOf('Mac') != -1
) *// Plone, register_function.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

P: n/a
On Aug 2, 2:19*am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
bH wrote:
I have been looking at javascript drawing from this website :
http://www.cwdjr.net/geometricDraw/pentagon_draw.html"
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

P: n/a
slebetman wrote:
Thomas 'PointedEars' Lahn wrote:
>bH wrote:
>>I have been looking at javascript drawing from this website :
http://www.cwdjr.net/geometricDraw/pentagon_draw.html" 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.

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.
IBTD.
On IE and Firefox <= 2 you'd need the Adobe SVG plugin to see SVG on web
pages.
You are correct about IE/MSHTML, but not about Firefox. SVG (and Canvas)
is at least partially supported in Firefox since version 1.5 "Deer Park"
(released 2005-11-29 CE) which uses Gecko 1.8.
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.
I have found it to be quite stable, and it was frequently mentioned as
development target here. But one should not install it where there is
built-in SVG support as both features would interfere with each other.
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. [...]
Unfortunately, I had observed this to be true earlier today.
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 3 '08 #11

P: n/a
bH wrote:
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?"
Yes, that was a typing mistake. I think the following reasons made VML
unpopular:

- There have always been many alternatives to VML: PGML, SVG, java,
javascript, PNG, GIF, JPG, Flash, UML.
- VML is proprietary; it only works with MSIE and not "on the web".
It's not likely that other browsers will ever adopt VML.
- Crappy MS-Office HTML conversions gave a rather bad name to VML,
MSXML and the like: tons of illegible code with many errors; and often
incompatible even across different versions of Internet Explorer.
- There was never a big need for VML; drawing vectors on-the-fly is
usually only for very specific applications.
- Microsoft does not have a good reputation supporting its current
technologies in future software releases.

--
Bart
Aug 3 '08 #12

P: n/a
Jorge wrote:
On Aug 1, 8:19 pm, Thomas 'PointedEars' Lahn <PointedE...@web.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>
| Status of this document
|
| This section describes the status of this document at the time of
| its publication. Other documents may supersede this document. [...]
|
| Implementors should be aware that this specification is not stable.
| Implementors who are not taking part in the discussions are likely
| to find the specification changing out from under them in
| incompatible ways. Vendors interested in implementing this
| specification before it eventually reaches the
| Candidate Recommendation stage should join the aforementioned
| mailing lists and take part in the discussions.
|
| The publication of this document by the W3C as a W3C Working Draft
| does not imply that all of the participants in the W3C HTML working
| group endorse the contents of the specification. Indeed, for any
| section of the specification, one can usually find many members of
| the working group or of the W3C as a whole who object strongly to
| the current text, the existence of the section at all, or the idea
| that the working group should even spend time discussing the concept
| of that section.

Probably someone has told you about that before.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Aug 4 '08 #13

P: n/a
On Aug 4, 5:18 pm, Thomas 'PointedEars' Lahn wrote:
<snip>
>| ... , for any section of the specification, one can usually
| find many members of the working group or of the W3C as a
| whole who object strongly to the current text, the existence
| of the section at all, or the idea that the working group
| should even spend time discussing the concept of that section.
<snip>

With a disclaimer like that it sounds like a fair percentage of the
W3C don't want to see this ever getting to the status of being a
recommendation.
Aug 4 '08 #14

P: n/a
On Aug 4, 7:04*pm, Henry <rcornf...@raindrop.co.ukwrote:
On Aug 4, 5:18 pm, Thomas 'PointedEars' Lahn wrote:
<snip>>| ... , for any section of the specification, one can usually
| find many members of the working group or of the W3C as a
| whole who object strongly to the current text, the existence
| of the section at all, or the idea that the working group
| should even spend time discussing the concept of that section.

<snip>

With a disclaimer like that it sounds like a fair percentage of the
W3C don't want to see this ever getting to the status of being a
recommendation.
Don't you know what's been going on between the W3C and the WHATWG ?

http://en.wikipedia.org/wiki/WHATWG

--Jorge.
Aug 4 '08 #15

P: n/a
On Aug 4, 6:18*pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:

<snip>

Essentially, it boils down to M$ vs. Opera+Mozilla+Apple.

--Jorge.
Aug 4 '08 #16

This discussion thread is closed

Replies have been disabled for this discussion.