Drawing math shape

B

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
 
T

Thomas 'PointedEars' Lahn

bH said:
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
 
S

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 :
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 ... ? !
 
B

Bart Van der Donck

Thomas said:
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) or maybe
(proprietary) Canvas; certainly not plain HTML.

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

http://chart.apis.google.com/chart?...70,70,70,70&chm=B,FF0000,0,0,5&chf=c,s,000000

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

Bart Van der Donck

bH said:
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/library/bb264280(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,266px,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
 
B

bH

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?"
 
S

slebetman

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.
 
T

Thomas 'PointedEars' Lahn

slebetman said:
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
 
B

Bart Van der Donck

bH said:
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.
 
T

Thomas 'PointedEars' Lahn

Jorge said:
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
 
H

Henry

On Aug 4, 5:18 pm, Thomas 'PointedEars' Lahn wrote:
| ... , 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top