Open this JS Fiddle Link. There are two paths which are animating. the dark blue bar animates according to minutes passed & the smaller green bar animates according to seconds. I want to loop this animations when they complete their animation. How can I do that?
JS Fiddle Link
window.onload= function aa () {
var paper = Raphael(0, 0, 1900, 1900);
var date = new Date;
var hour = date.getHours();
var mins = date.getMinutes();
var secs = date.getSeconds();
var secl = (60*60*1000)-(secs*1000);
var minl = 60 - mins;
var crx = 318*(mins/60);//sets width according to minutes passed when window is loaded
var cry = 318*(secs/60);//sets width according to seconds passed when window is loaded
var sec1 = (60-secs)*1000;
var x=1;
var y=1;
var pathhh = "M"+x+","+y+" "+"h"+320+" "+"v"+270+" "+"h"+(-320)+"z";//bg
var curbox = paper.path(pathhh).attr({fill:'315-#0299fa-#0473ba'});
var pathh3 = "M"+(x+1)+","+(242+y)+" "+"h"+318+" "+"v"+27+" "+"h"+(-318)+"z";//black bar
var cur1box = paper.path(pathh3).attr({fill:'black'});
var pathfm = "M"+(x+1)+","+(243+y)+" "+"h"+crx+" "+"v"+20+" "+"h"+"-"+crx+"z";//minutes bar
var pathto = "M"+(x+1)+","+(243+y)+" "+"h"+318+" "+"v"+20+" "+"h"+(-318)+"z";
var cu2box = paper.path(pathfm).attr({fill:'#03558b',stroke:'none'});
cu2box.animate({path: pathto},secl);
var patgfm = "M"+(x+1)+","+(265+y)+" "+"h"+cry+" "+"v"+4+" "+"h"+"-"+cry+"z"; //seconds bar
var patgto = "M"+(x+1)+","+(265+y)+" "+"h"+318+" "+"v"+4+" "+"h"+(-318)+"z";
var cu3box = paper.path(patgfm).attr({fill:'#0db1af',stroke:'none'});
cu3box.animate({path: patgto},sec1);
};
I think this question is relevant, while not quite the same as yours. The question and the answer together contain the solution for your case: use the callback at the end of the animation, reset the path to the original and set the new animation.
Alternatively, use setInterval to reset the animation every minute/hour.
Related
I want to combine all the Landsat sensors from 1985 up today in Google Earth Engine, remove the clouds and calculate the time-series of the NBR index. As a new GEE user I have the following:
// find all data and filter them by date
var lst5 = ee.ImageCollection('LANDSAT/LT5_SR').filterDate('1984-10-01', '2011-10-01');
var lst7 = ee.ImageCollection('LANDSAT/LE7_SR').filterDate('2011-10-01', '2013-04-07');
var lst8 = ee.ImageCollection('LANDSAT/LC8_SR').filterDate('2013-04-07', '2018-05-01');
var lst7_08 = ee.ImageCollection('LANDSAT/LE7_SR').filterDate('2007-12-01', '2008-02-01');
var lst7_92 = ee.ImageCollection('LANDSAT/LT4_SR').filterDate('1992-01-02', '1992-04-01');
// Combine all landsat data, 1985 through 2015
var everything = ee.ImageCollection(lst5.merge(lst7));
everything = everything.merge(lst8);
everything = everything.merge(lst7_08);
everything = everything.merge(lst7_92);
var alltogether = ee.ImageCollection(everything.filterDate('1984-01-01', '2018-05-01'));
From this point, I do not know how to remove the clouds and calculate the NBR index (NBR index here) for every image in my final collection.
Can anyone help me?
Thank you.
EDIT:
I think that I need to map a normalizedDifference function over my collection in order to get the NBR index but I am not sure how to do this for my collection with the different sensors.
You've got quite a lot going on here, but here's what I think you want. You should check this very carefully to ensure it's behaving as intended:
// Function to cloud mask Landsat 8.
var maskL8SR = function(image) {
// Bits 3 and 5 are cloud shadow and cloud, respectively.
var cloudShadowBitMask = ee.Number(2).pow(3).int();
var cloudsBitMask = ee.Number(2).pow(5).int();
// Get the QA band.
var qa = image.select('pixel_qa');
// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0).and(
qa.bitwiseAnd(cloudsBitMask).eq(0));
return image
// Scale the data to reflectance and temperature.
.select(['B5', 'B7'], ['NIR', 'SWIR']).multiply(0.0001)
.addBands(image.select(['B11'], ['Thermal']).multiply(0.1))
.updateMask(mask);
};
// Function to cloud mask Landsats 5-7
var maskL57SR = function(image) {
var qa = image.select('pixel_qa');
// Second bit must be zero, meaning none to low cloud confidence.
var mask1 = qa.bitwiseAnd(ee.Number(2).pow(7).int()).eq(0).and(
qa.bitwiseAnd(ee.Number(2).pow(3).int()).lte(0)); // cloud shadow
// This gets rid of irritating fixed-pattern noise at the edge of the images.
var mask2 = image.select('B.*').gt(0).reduce('min');
return image
.select(['B4', 'B7'], ['NIR', 'SWIR']).multiply(0.0001)
.addBands(image.select(['B6'], ['Thermal']).multiply(0.1))
.updateMask(mask1.and(mask2));
};
// find all data and filter them by date
var lst5 = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')
.filterDate('1984-10-01', '2011-10-01')
.map(maskL57SR)
var lst7 = ee.ImageCollection('LANDSAT/LE07/C01/T1_SR')
.filterDate('2011-10-01', '2013-04-07')
.map(maskL57SR)
var lst8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterDate('2013-04-07', '2018-05-01')
.map(maskL8SR)
var lst7_08 = ee.ImageCollection('LANDSAT/LE07/C01/T1_SR')
.filterDate('2007-12-01', '2008-02-01')
.map(maskL57SR)
var lst7_92 = ee.ImageCollection('LANDSAT/LT04/C01/T1_SR')
.filterDate('1992-01-02', '1992-04-01')
.map(maskL57SR)
// Combine all landsat data, 1985 through 2015
var everything = ee.ImageCollection(lst5.merge(lst7));
everything = everything.merge(lst8);
everything = everything.merge(lst7_08);
everything = everything.merge(lst7_92);
// NBR:
var nbrFunction = function(image) {
image = ee.Image(image)
return image.addBands(image.expression(
'(nir - 0.0001 * swir * thermal) / ' +
'(nir + 0.0001 * swir * thermal)', {
nir: image.select(['NIR']),
swir: image.select(['SWIR']),
thermal: image.select(['Thermal'])
}).rename('NBR').clamp(-1, 1));
};
everything = everything.map(nbrFunction);
var check = ee.Image(everything.first());
Map.centerObject(check);
Map.addLayer(check);
The answer works great for SR imagery! Thanks! Sorry I can't just comment because I don't have 50 reputation yet, but I saw #Abhilash Singh Chauhan's question about why ee.Number(2).pow(3)... is used for the variables cloudshadow and clouds. I had the same question and I wanted to answer that it's because of the fact that the QA Pixel bands are Decimal integers that contain Binary information. So for example band 3 for surface reflectance LANDSAT products indicates the band for cloud shadow but the values are in binary. To get the values you need to convert the band to binary, hence 2^3 and similarly 2^5 for cloud values. I hope that clarifies the comment. you can check this here: https://www.usgs.gov/landsat-missions/landsat-4-7-surface-reflectance-quality-assessment
i am new in cocos2d-js here, i just created this code:`
var that = this;
that._dice
// add player
// create sprite sheet
cc.spriteFrameCache.addSpriteFrames(res.dice_plist);
var spriteSheet = new cc.SpriteBatchNode(res.diceRed_png);
that.addChild(spriteSheet, 2);
// init runningAction
var animFrames = [];
for (var i = 1; i < 7; i++) {
var str = "dieRed" + i + ".png";
var frame = cc.spriteFrameCache.getSpriteFrame(str);
animFrames.push(frame);
}
var animation = new cc.Animation(animFrames, 0.1);
that.runningAction = new cc.Repeat.create(new cc.Animate(animation), Math.random()*10);
var diceSprite = new cc.Sprite("#dieRed1.png");
diceSprite.visible = true;
console.log(this.getContentSize(diceSprite));
diceSprite.runAction(this.runningAction);
that._dice.push(diceSprite);
var size = cc.winSize;
spriteSheet.setPosition(size.width/6.5, size.height/1.20);
spriteSheet.setAnchorPoint(0.5, 0.5);
spriteSheet.addChild(diceSprite, 2);
`
and i would like to use the getFrames() feature to return the array of ccanimation frames. i'm just thinking to get the information of which picture are being animated on the screen there, for example, if the #dieRed1.png is being animated or visible on the screen, it would show value or return value of 1. i have tried to googled around and cannot find any other clue there. if there is any better method, i would love to see that as well. sorry for the english anyway, a bit confused how to arrange the words. thank you :)
Ok, so refering to
the official docs
{Array} getFrames()
Returns the array of animation frames
Which means you can just do:
var frames = animation.getFrames();
To get the array. And then you'll receive an array of cc.AnimationFrame.
To get sprite link do:
var frame = frames[0];//cc.AnimationFrame
var spriteFrame = frame.getSpriteFrame(); //cc.SpriteFrame
var texture = spriteFrame.getTexture(); // cc.Texture
And the texture itself should have the name attribute which may do the job.
I'm newbie in cocos-js.
I want to make a health bar in cocos JS and try this code. And i choose to use Progress Timer. But when i use this code, it just show the bar, no running action. What's wrong ?
var healthBar = cc.ProgressTimer.create(cc.Sprite.create("health_bar1.png"));
healthBar.setType(cc.PROGRESS_TIMER_TYPE_BAR);
healthBar.setBarChangeRate(cc.p(1,0));
healthBar.setMidpoint(cc.p(0,0));
this.addChild(healthBar, 1);
healthBar.setPosition(cc.winSize.width/2, cc.winSize.height/2);
var to1 = cc.progressTo(5, 100);
healthBar.runAction(to1);
This code is working for me very well:
var healthBar = cc.ProgressTimer.create(cc.Sprite.create("health_bar1.png"));
healthBar.setType(cc.ProgressTimer.TYPE_BAR);
healthBar.setBarChangeRate(cc.p(1,0));
healthBar.setMidpoint(cc.p(0,0));
healthBar.setPosition(cc.winSize.width/2, cc.winSize.height/2);
this.getParent().addChild(healthBar, 1);
var to1 = cc.progressTo(5, 100);
healthBar.runAction(to1);
I have a moveTo sprite action and I am trying to have the sprite animate while moving. It is a waling animation.
My trouble is I can make the sprite moveTo or animate but not both together so that when the sprite stops moving the animation goes back to the standing frame.
I am using cocos2d-js v3.0
this.sprite = new cc.Sprite.create("#player-stand-f-0");
this.sprite.setPosition(new cc.Point(300,300));
this.addChild(this.sprite);
var animFrames = [];
var str = "";
for (var i = 0; i < 5; i++) {
str = "player-walk-f-" + i;
var spriteFrame = cc.spriteFrameCache.getSpriteFrame(str);
var animFrame = new cc.AnimationFrame();
animFrame.initWithSpriteFrame(spriteFrame, 1, null);
animFrames.push(spriteFrame);
}
var animation = cc.Animation.create(animFrames, 0.025);
var animate = cc.animate(animation);
sprite_action = cc.MoveTo.create(2,cc.p(x,y));
this.sprite.runAction(sprite_action);
this.sprite.runAction(animate);
I have also tried the following but the walking would animate once and not continue until moveTo stops.
var seq = cc.sequence(animate, sprite_action);
If you use "cc.sequence" action it will animate first then move. But if you want to animate the sprite sheet while moving it, there are two ways to achieve that:Look into "cc.Spawn" action. It is used for the purpose just like you need. Another convenient method is to run two actions concurrently.. Below mentioned code will give you the idea.
// create sprite sheet
cc.SpriteFrameCache.getInstance().addSpriteFrames(spritesheet_plist); // add Spritesheet Plist
var SpriteSheet = cc.SpriteBatchNode.create(spritesheet_png); // add Spritesheet Png
this.addChild(SpriteSheet,1);
// Push the frames for animation
var animFrames = [];
for (var i = 0; i < 6; i++) {
var str = "sequence_" + i + ".png";
var frame = cc.SpriteFrameCache.getInstance().getSpriteFrame(str);
animFrames.push(frame);
}
// taadaa ...!! Animate the sprites
var animation = cc.Animation.create(animFrames, 0.06);
var sprite = cc.Sprite.createWithSpriteFrameName("sequence_0.png");
sprite.setAnchorPoint(0.5,0.5); // optional
sprite.setScale(1.0,1.0); // optional
sprite.setPosition(widhthPostion, heightPosition);
sprite.runAction(cc.RepeatForever.create(cc.Animate.create(animation)));
SpriteSheet.addChild(sprite,1);
// Move the sprite
var actionMove = cc.MoveTo.create(duration, cc.p(destinationX, destinationY));
sprite.runAction(actionMove);
Is it possible to give move effect on a UITextField.
var aminolabel:UITextField;
var aminoLabelMove:Move = new Move(aminolabel);
aminoLabelMove.xFrom = 0;
aminoLabelMove.xTo = 100
aminoLabelMove.duration = 1300;
aminoLabelMove.play();
UITextField could not have animations like move. Which internally calls transformX, transformY. Can have Face effect animation.
Solution
Add UITextField instance to a UIComponent and apply the move effect to the UIComponent.
Example
var aminolabel:UITextField;
var aminoLabelUI:UIComponent;
aminoLabelUI.addChild(aminolabel);
var aminoLabelMove:Move = new Move(aminoLabelUI);
aminoLabelMove.xFrom = 0;
aminoLabelMove.xTo = 100
aminoLabelMove.duration = 1300;
aminoLabelMove.play();