flash actionscript:
Ive got a timer to countdown to 45 minutes. I have 3/4 of a round clock (wedged) which need to fill while the clock is ticking. When the firs period completes watch should be full. This is for a childrens soccer club web page. Really would appreciate help.
fraction of minutes would be great
if you want to display minutes only you can use: function clockFillF(m,x, y, r) { ang = Math.PI*m/30-Math.PI/2; if (!prevX) { _root.createEmptyMovieClip("mc1", _root.getNextHighestDepth()); prevX = x; prevY = y-r; } currX = r*Math.cos(ang)+x; currY = r*Math.sin(ang)+y; with (mc1) { beginFill(0xff0000); moveTo(x, y); lineTo(currX, currY); curveTo((currX+prevX)/2, (currY+prevY)/2, prevX, prevY); lineTo(x, y); endFill(); } prevX = currX; prevY = currY; m++; } where m is the minutes elapsed, x,y,r are the x,y coordinates of your clock's center and r is its radius. if you want to display seconds use: function clockFillF(s,x, y, r) { ang = Math.PI*s/1800-Math.PI/2; if (!prevX) { _root.createEmptyMovieClip("mc1", _root.getNextHighestDepth()); prevX = x; prevY = y-r; } currX = r*Math.cos(ang)+x; currY = r*Math.sin(ang)+y; with (mc1) { beginFill(0xff0000); moveTo(x, y); lineTo(currX, currY); curveTo((currX+prevX)/2, (currY+prevY)/2, prevX, prevY); lineTo(x, y); endFill(); } prevX = currX; prevY = currY; m++; } where s is seconds elapsed and the other parameters are the same as above.
Great kglad but a few questions It seems the function draws a triangle How would I update every second? How can the rounded exterior be achivied
it draws the sector of a circle, not a triangle. to update every second you could use use: s = 1; clockI = setInterval(clockF, 1000, 100, 100, 50); function clockF(x, y, r) { clockFillF(s, x, y, r); s++; } function clockFillF(s, x, y, r) { ang = Math.PI*s/1800-Math.PI/2; if (!prevX) { _root.createEmptyMovieClip("mc1", _root.getNextHighestDepth()); prevX = x; prevY = y-r; } currX = r*Math.cos(ang)+x; currY = r*Math.sin(ang)+y; with (mc1) { beginFill(0xff0000); moveTo(x, y); lineTo(currX, currY); curveTo((currX+prevX)/2, (currY+prevY)/2, prevX, prevY); lineTo(x, y); endFill(); } prevX = currX; prevY = currY; m++; } but i can't imagine it's necessary to update the drawing every second which is relatively cpu intensive compared with updating 2 or 3 times per minute. you might try less frequent updates to see the effect.
actually, it does draw a triangle, but because of the large number of triangles the drawing is not distinguishable from a circle. however, if you want a more accurate depiction you can use the following: s = 1; clockI = setInterval(clockF, 1000, 100, 100, 50); function clockF(x, y, r) { clockFillF(s, x, y, r); s++; } function clockFillF(s, x, y, r) { ang = Math.PI*s/1800-Math.PI/2; if (!prevX) { _root.createEmptyMovieClip("mc1", _root.getNextHighestDepth()); prevX = x; prevY = y-r; } currX = r*Math.cos(ang)+x; currY = r*Math.sin(ang)+y; t1 = tangentF(x, y, r, prevX, prevY); t2 = tangentF(x, y, r, currX, currY); int = intersectF(t1[0], t1[1], t2[0], t2[1]); with (mc1) { beginFill(0xff0000); moveTo(x, y); lineTo(currX, currY); curveTo(int[0], int[1], prevX, prevY); lineTo(x, y); endFill(); } prevX = currX; prevY = currY; } function tangentF(centerX, centerY, r, ptX, ptY) { if (centerY != ptY) { var m = (-ptX+centerX)/(Math.sqrt(r*r-(ptX-centerX)*(ptX-centerX))); } else { m = 1000000000; } if (ptY<centerY) { m = -m; } var b = ptY-m*ptX; return [m, b]; } function intersectF(m1, b1, m2, b2) { if (m1 != m2) { var x = (b2-b1)/(m1-m2); var y = m1*x+b1; } else { m1 -= 1; m2 += 1; var x = (b2-b1)/(m1-m2); var y = m1*x+b1; } return [x, y]; } but again, it's not necessary or desirable to update the clock every second. every 30 second updates should be adequate.
Don't see what you're looking for? Try a search.
|