Code:
<script Language="JavaScript">
r=0
g=0
b=0
function pset(x,y,wi,he)
{
document.write ("<img src='../1x1.gif' style='z-index:-10; position:absolute; left:"+x+";top:"+y+";width:"+wi+";height:"+he+";background:rgb("+r+","+g+","+b+")'>")
}
kx=400
ky=400
x0=(window.screen.width-20)/2
y0=400
r=g=b=0
pset(x0-kx/2,y0,kx,2)
pset(x0,y0-ky/2,2,ky)
g=255
for(x=-kx/4;x<kx/4;x++)
{
y=x*x/kx*8
pset(x+x0,-y+y0,2,2)
}
g=0
r=255
for(x=-kx/2;x<kx/2;x++)
{
y=Math.sin(x/kx*20)*ky/10
pset(x+x0,-y+y0,2,2)
}
r=0
b=255
for(i=-100;i<100;i=i+0.5)
{
x=Math.cos(i/100*3.15)*kx/4
y=Math.sin(i/100*3.15)*ky/4
pset(x+x0,-y+y0,2,2)
}
</script>
1x1.gif is a 1 pixel square transparent gif. To download a copy from this server, right click on this and select "Save as..."
To see this code actually work, click here for a page with the javascript code embedded.
Also:
Questions:
I would like to use something like this to draw with.
If you make subsequent calls to this in an event, this function destroys the whole html.
How can this be avoided ?
James Newton replies: What do you mean by "destroys the whole html"? What event are you calling it from?+
Comments:
See also:
| file: /Techref/language/java/script/imgdraw.htm, 2KB, , updated: 2007/12/29 19:11, local time: 2012/2/9 04:56,
owner: JMN-EFP-786,
38.107.179.231:LOG IN |
| ©2012 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://www.ecomorder.com/techref/language/java/script/imgdraw.htm"> Drawing vector graphics in DHTML with Javascript</A> |
| Did you find what you needed? |
|
|
Robotics nuts!Check out http://users.frii.com/dlc/robotics/projects/botproj.htm from Dennis Clark. This guy ROCKS! He has made (and sells but also releases code, docs, etc...) for a number of cool little robotic modules including whiskers, IR proximity detect and remote control, Sonar proximity detect, PWM, Servo, compass. Most of these use the little PIC 12C508 controller which costs basically nothing and is soooo tiny.The 4 servos, 2400 baud serial servo controller is a wonder of magic and he sells the programmed chip for $8. Wow! |
.