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