all groups > flash actionscript > december 2005 >
You're in the

flash actionscript

group:

Soccer Time


Soccer Time Egui
12/26/2005 8:22:16 PM
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.
Re: Soccer Time kglad
12/26/2005 11:59:35 PM
Re: Soccer Time Egui
12/27/2005 12:49:50 AM
Re: Soccer Time kglad
12/27/2005 2:15:39 AM
Re: Soccer Time Egui
12/27/2005 12:55:54 PM
fraction of minutes would be great
Re: Soccer Time kglad
12/28/2005 8:20:30 PM
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.
Re: Soccer Time Egui
12/29/2005 3:00:34 AM
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

Re: Soccer Time kglad
12/29/2005 3:17:40 AM
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.
Re: Soccer Time kglad
12/29/2005 8:26:56 PM
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.
AddThis Social Bookmark Button