to paint spirals

S

steel

hi at all

do you know how is it possiple to paint a logarithmic SPIRAL with javascrpr?

Thank in advance
 
L

Lasse Reichstein Nielsen

steel said:
do you know how is it possiple to paint a logarithmic SPIRAL with javascrpr?

Paint it on what?
JavaScript itself has no standard means of output. In an HTML setting you
can use either canvas or svg as output (depending on client capabilities).
Computing the points of the spiral shoukd easy.

/L
 
S

steel

"rf"
wrote:
I do not want directly to paint a spiral but i need to move a little image
along a spiral
Therefore I need a function to return spiral points
Where can I found source code to do that please?
 
L

Lasse Reichstein Nielsen

steel said:
I need only points

where can I found code please?

The formula for a logarithmic spiral is:
f(t) = (ae^bt cos(t), ae^bt sin(t))

To create something like that in Javascript:

function LogarithmicSpiral(a,b) {
return function spiral(t) {
var r = Math.pow(a * Math.E, b * t);
return {x: r * Math.cos(t), y: r * Math.sin(t)};
}
}

so to get the points, pick an a and b:

var spiral = LogartihmicSpiral(2,4);
for (var t = 0; t < 100; t += 0.01) {
var point = spiral(t);
// do something with point
}

/L
 
T

Thomas 'PointedEars' Lahn

Lasse said:
The formula for a logarithmic spiral is:
f(t) = (ae^bt cos(t), ae^bt sin(t))

f(t) = (ae^(bt) cos(t), ae^(bt) sin(t))
To create something like that in Javascript:

function LogarithmicSpiral(a,b) {
return function spiral(t) {
var r = Math.pow(a * Math.E, b * t);

var r = a * Math.exp(b * t);
return {x: r * Math.cos(t), y: r * Math.sin(t)};
}
}

so to get the points, pick an a and b:

var spiral = LogartihmicSpiral(2,4);
^^^

var spiral = LogarithmicSpiral(2, 4);
 
R

rf

steel said:
"rf"
wrote:

I do not want directly to paint a spiral but i need to move a little
image along a spiral

So your original question was irrelevant. Pulling teeth is it going to be?
See what PE said.
Therefore I need a function to return spiral points

Then write one.
Where can I found source code to do that please?

Under your pillow?



Have you ever heard of this new fangled thing called Google?

You type in what you want to know, in this case "javascript logarithmic
spiral" and you get about 1600 answers. Many of them *give* you the source
code for free.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
do you know how is it possiple to paint a logarithmic SPIRAL with javascrpr?

This will draw a spiral, at least in IE7 & FF3. You'll need to make it
logarithmic. There are probably better ways of drawing.


<div ID="XXX"
style="position:relative; margin:auto; width:440px; height:440px;
border:7px solid white; background:silver; ">
</div>

<script type-"text/javascript">

XX = document.getElementById("XXX")

for (var J=0 ; J<3000 ; J++) {
var Dg = document.createElement("div")
var DS = Dg.style
DS.position = "absolute"
DS.height = DS.width = "3px"
DS.background = "blue"
var X = J/15 * Math.sin(J/50)
var Y = J/15 * Math.cos(J/50)
DS.left = 220 + X + "px"
DS.top = 220 + Y + "px"
XX.appendChild(Dg) }

</script>

Optimise the spacing so that successive points do not greatly overlap.
Do not use many more points.
 

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

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,252
Latest member
MeredithPl

Latest Threads

Top