I have 13 images shown in page ,one of them is fixed and others changed depend on some data ,i made 12 if statement and it works ,but is there way to create one if statement with for loop like thus :
for (int i = 2; i >= 13; i++)
{
if (m_id >= i)
{
"image" + i.Source = ImageSource.FromFile("months" + i + ".png");
}
else
{
"image" + i.Source = ImageSource.FromFile("months"+i+"closed.png");
}
}
You should put all Images in an Array like
List<Image> Images = new List<Image>() {image2,image3,...,image13 };
And set the ImageSource like
for(int i=2;i<=13;i++)
{
Image image = Images[i - 2];
if (m_id >= i)
{
image.Source = ImageSource.FromFile("months" + i + ".png");
}
else
{
image.Source = ImageSource.FromFile("months"+i+"closed.png");
}
}
Related
Below I have some code I have running for a spreadsheet. Right now it takes a min or two to run through the script. I was wondering if anyone has any suggestions on how to re-work my code to run a little faster.
What the code does is search on a tab in the sheet called "set up" for check-marked items in a list that I would like included in my "Master Sheet". Then go to my sheet which contains all of the information that I would like copied and pasted over according to what is check marked on my set-up page. Then copy and paste those line items to the master sheet.
function allToMaster(){
var sss = SpreadsheetApp.getActive();
var ssAll = sss.getSheetByName("FF All");
var ssMaster = sss.getSheetByName("FF Master");
var ssSetup = sss.getSheetByName("FF Setup");
ssMaster.clear();
var masterCounter = 2;
ssAll.getRange("P:P").clear();
var sourceRange = ssAll.getRange(1,1,1,15);
sourceRange.copyTo(ssMaster.getRange(1,1));
//get last row of FF All
var lastRowAll = ssAll.getLastRow();
var lastRowMaster = ssMaster.getLastRow();
ssAll.getRange("P2:P" + lastRowAll).setFormula("=index('FF Setup'!B:B,match(B2,'FF Setup'!C:C,0))");
ssMaster.setRowHeightsForced(2, 500, 26);
for (i=2;i<=lastRowAll;i++){
if (ssAll.getRange(i,1).getBackground() == "#a8d08d"){
var sourceRange = ssAll.getRange(i,1,1,15);
sourceRange.copyTo(ssMaster.getRange(masterCounter,1));
masterCounter++;
} else if (ssAll.getRange(i,1).getBackground() == "#e2efd9"){
var sourceRange = ssAll.getRange(i,1,1,15);
sourceRange.copyTo(ssMaster.getRange(masterCounter,1));
masterCounter++;
} else {
if (ssAll.getRange("P" + i).getValue() == true) {
var sourceRange = ssAll.getRange(i,1,1,15);
sourceRange.copyTo(ssMaster.getRange(masterCounter,1));
ssMaster.setRowHeightsForced(masterCounter, 1, 136);
masterCounter++;
}
}
}
ssAll.getRange("P:P").clear();
//Clear Empty Subtitles
var lastRowMaster = ssMaster.getLastRow();
for (i=2;i<=lastRowMaster;i++){
if (ssMaster.getRange(i,1).getBackground() == "#e2efd9"){
if(ssMaster.getRange((i+1),1).getBackground() == "#e2efd9" || ssMaster.getRange((i+1),1).getBackground() == "#a8d08d"){
ssMaster.deleteRow(i);
ssMaster.insertRowAfter(500);
i=i-1;
}
}
}
//Clear Empty Titles
var lastRowMaster = ssMaster.getLastRow();
for (i=2;i<=lastRowMaster;i++){
if (ssMaster.getRange(i,1).getBackground() == "#a8d08d"){
if(ssMaster.getRange((i+1),1).getBackground() == "#a8d08d"){
ssMaster.deleteRow(i);
ssMaster.insertRowAfter(500);
i=i-1;
}
}
}
//Find the row with "Delivery"
var deliveryRow = getRowOf("DELIVERY", "FF All", 1);
var sourceRange = ssAll.getRange(deliveryRow,1,(lastRowAll - deliveryRow + 1),15);
var masterCounter = ssMaster.getLastRow()
sourceRange.copyTo(ssMaster.getRange(masterCounter,1));
masterCounter = masterCounter + lastRowAll - deliveryRow - 2;
//.setFormula('=SUMA(J264:J275)');
// ssMaster.getRange(masterCounter, 10).setFormula("=sum(J2:J" + (masterCounter - 1) + ")");
//ssMaster.getRange(masterCounter, 11).setFormula("=sum(K2:K" + (masterCounter - 1) + ")");
//ssMaster.getRange(masterCounter, 13).setFormula("=sum(M2:M" + (masterCounter - 1) + ")");
//ssMaster.getRange(masterCounter, 15).setFormula("=M" + masterCounter + " - K" + masterCounter);
}
function getRowOf(value, sheet, col){
var dataArr = SpreadsheetApp.getActive().getSheetByName(sheet).getRange(4, col, 3500, 1).getValues();
for(var j = 0; j < dataArr.length; j ++){
var currVal = dataArr[j][0];
if(currVal == value){
return j+4;
break;
}
}
return 0;
}
You need to change the loops as they are doing several calls to Class SpreadsheetApp on each iteration.
Regarding the first loop,
for (i=2;i<=lastRowAll;i++){
if (ssAll.getRange(i,1).getBackground() == "#a8d08d"){
var sourceRange = ssAll.getRange(i,1,1,15);
sourceRange.copyTo(ssMaster.getRange(masterCounter,1));
masterCounter++;
} else if (ssAll.getRange(i,1).getBackground() == "#e2efd9"){
var sourceRange = ssAll.getRange(i,1,1,15);
sourceRange.copyTo(ssMaster.getRange(masterCounter,1));
masterCounter++;
} else {
if (ssAll.getRange("P" + i).getValue() == true) {
var sourceRange = ssAll.getRange(i,1,1,15);
sourceRange.copyTo(ssMaster.getRange(masterCounter,1));
ssMaster.setRowHeightsForced(masterCounter, 1, 136);
masterCounter++;
}
}
}
Instead of getting the background of one cell at a time (ssAll.getRange(i,1).getBackground()), before the loop get the backgrounds of all the cells before the loop, i.e.
const backgrounds = ssAll.getRange(2,1,lastRowAll).getBackgrounds();
then replace ssAll.getRange(i,1).getBackground() by backgrounds[i-1][0].
Do the something similar about ssAll.getRange("P" + i).getValue(), before the loop get the all values of the P column:
const values = ssAll.getRange("P" + i + ":P" + lastRowAll).getValues()
then replace ssAll.getRange("P" + i).getValue() by values[i-1][0]`.
It might be also possible to optimize further the first loop depending on if you really need to copy the ranges (besides values, include borders, background, notes, etc.) or if you only need the values.
Another option is to use the Advances Sheets Services but this implies to make a completely different implementation.
So I'm working on a collision system based off: this blog,
although with some minor changes, as I had some issues with that code, and its working pretty good for all cases, except coming up from below,
here are some screenshots(green is before resolution, red is after): and here is the problem:
this is my code (sorry its messy and unoptimized, I was planning to rewrite it once I understood the algorithm):
public function ResolveCollision(a : CollisionComponent, b : CollisionComponent)
{
var aAABB = new AABB(new Point(a.GetBounds().x, a.GetBounds().y),
new Point(a.GetBounds().x + a.GetBounds().width,
a.GetBounds().y + a.GetBounds().height));
var bAABB = new AABB(new Point(b.GetBounds().x, b.GetBounds().y),
new Point(b.GetBounds().x + b.GetBounds().width,
a.GetBounds().y + a.GetBounds().height));
var direction : Point = new Point();
direction.x = aAABB.topLeft.x - bAABB.topLeft.x;
direction.y = aAABB.topLeft.y - bAABB.topLeft.y;
var end : AABB = new AABB();
end.bottomRight.x = Math.min(aAABB.bottomRight.x, bAABB.bottomRight.x);
end.bottomRight.y = Math.min(aAABB.bottomRight.y, bAABB.bottomRight.y);
end.topLeft.x = Math.max(aAABB.topLeft.x, bAABB.topLeft.x);
end.topLeft.y = Math.max(aAABB.topLeft.y, bAABB.topLeft.y);
var overlap : Point = new Point();
overlap.x = end.bottomRight.x - end.topLeft.x;
overlap.y = end.bottomRight.y - end.topLeft.y;
var moveAxis : Int; //0:x, 1:y
if (overlap.x < overlap.y)
{
moveAxis = 0;
}
else
{
moveAxis = 1;
}
if (moveAxis == 0)
{
a.Move(new Point(sign(direction.x) * overlap.x, 0));
}
else if (moveAxis == 1)
{
a.Move(new Point(0, sign(direction.y) * overlap.y));
}
}
private function sign(i : Float) : Int
{
if (i < 0)
{
return -1;
}
else if ( i > 0)
{
return 1;
}
else
{
return 0;
}
}
if anyone could point me to the problem, that would be great, if not, I feel like I understand it well enough to write it in a simpler way, and possibly figure out the cause...
thanks,
Nico
oops it was a dumb mistake in the AABB creation (where of course I didn't check), I was initializing some of the "b" boxes properties to those of the "a" box:
var bAABB = new AABB(new Point(b.GetBounds().x, b.GetBounds().y),
new Point(b.GetBounds().x + b.GetBounds().width,
**a.GetBounds()**.y + **a.GetBounds()**.height));
Using processing I am trying to run a script that will process a folder full of frames.
The script is a combination of PixelSortFrames and SortThroughSeamCarving.
I am new to processing and what I want does not seems to be working. I would like the script to run back through and choose the following file in the folder to be processed. At the moment it stops at the end and does not return to start on next file (there are three other modules also involved).
Any help would be much appreciated. :(
/* ASDFPixelSort for video frames v1.0
Original ASDFPixelSort by Kim Asendorf <http://kimasendorf.com>
https://github.com/kimasendorf/ASDFPixelSort
Fork by dx <http://dequis.org> and chinatsu <http://360nosco.pe>
// Main configuration
String basedir = ".../Images/Seq_002"; // Specify the directory in which the frames are located. Use forward slashes.
String fileext = ".jpg"; // Change to the format your images are in.
int resumeprocess = 0; // If you wish to resume a previously stopped process, change this value.
boolean reverseIt = true;
boolean saveIt = true;
int mode = 2; // MODE: 0 = black, 1 = bright, 2 = white
int blackValue = -10000000;
int brightnessValue = -1;
int whiteValue = -6000000;
// -------
PImage img, original;
float[][] sums;
int bottomIndex = 0;
String[] filenames;
int row = 0;
int column = 0;
int i = 0;
java.io.File folder = new java.io.File(dataPath(basedir));
java.io.FilenameFilter extfilter = new java.io.FilenameFilter() {
boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(fileext);
}
};
void setup() {
if (resumeprocess > 0) {i = resumeprocess - 1;frameCount = i;}
size(1504, 1000); // Resolution of the frames. It's likely there's a better way of doing this..
filenames = folder.list(extfilter);
size(1504, 1000);
println(" " + width + " x " + height + " px");
println("Creating buffer images...");
PImage hImg = createImage(1504, 1000, RGB);
PImage vImg = createImage(1504, 1000, RGB);
// draw image and convert to grayscale
if (i +1 > filenames.length) {println("Uh.. Done!"); System.exit(0);}
img = loadImage(basedir+"/"+filenames[i]);
original = loadImage(basedir+"/"+filenames[i]);
image(img, 0, 0);
filter(GRAY);
img.loadPixels(); // updatePixels is in the 'runKernals'
// run kernels to create "energy map"
println("Running kernals on image...");
runKernels(hImg, vImg);
image(img, 0, 0);
// sum pathways through the image
println("Getting sums through image...");
sums = getSumsThroughImage();
image(img, 0, 0);
loadPixels();
// get start point (smallest value) - this is used to find the
// best seam (starting at the lowest energy)
bottomIndex = width/2;
// bottomIndex = findStartPoint(sums, 50);
println("Bottom index: " + bottomIndex);
// find the pathway with the lowest information
int[] path = new int[height];
path = findPath(bottomIndex, sums, path);
for (int bi=0; bi<width; bi++) {
// get the pixels of the path from the original image
original.loadPixels();
color[] c = new color[path.length]; // create array of the seam's color values
for (int i=0; i<c.length; i++) {
try {
c[i] = original.pixels[i*width + path[i] + bi]; // set color array to values from original image
}
catch (Exception e) {
// when we run out of pixels, just ignore
}
}
println(" " + bi);
c = sort(c); // sort (use better algorithm later)
if (reverseIt) {
c = reverse(c);
}
for (int i=0; i<c.length; i++) {
try {
original.pixels[i*width + path[i] + bi] = c[i]; // reverse! set the pixels of the original from sorted array
}
catch (Exception e) {
// when we run out of pixels, just ignore
}
}
original.updatePixels();
}
// when done, update pixels to display
updatePixels();
// display the result!
image(original, 0, 0);
if (saveIt) {
println("Saving file...");
//filenames = stripFileExtension(filenames);
save("results/SeamSort_" + filenames + ".tiff");
}
println("DONE!");
}
// strip file extension for saving and renaming
String stripFileExtension(String s) {
s = s.substring(s.lastIndexOf('/')+1, s.length());
s = s.substring(s.lastIndexOf('\\')+1, s.length());
s = s.substring(0, s.lastIndexOf('.'));
return s;
}
This code works by processing all images in the selected folder
String basedir = "D:/things/pixelsortframes"; // Specify the directory in which the frames are located. Use forward slashes.
String fileext = ".png"; // Change to the format your images are in.
int resumeprocess = 0; // If you wish to resume a previously stopped process, change this value.
int mode = 1; // MODE: 0 = black, 1 = bright, 2 = white
int blackValue = -10000000;
int brightnessValue = -1;
int whiteValue = -6000000;
PImage img;
String[] filenames;
int row = 0;
int column = 0;
int i = 0;
java.io.File folder = new java.io.File(dataPath(basedir));
java.io.FilenameFilter extfilter = new java.io.FilenameFilter() {
boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(fileext);
}
};
void setup() {
if (resumeprocess > 0) {i = resumeprocess - 1;frameCount = i;}
size(1920, 1080); // Resolution of the frames. It's likely there's a better way of doing this..
filenames = folder.list(extfilter);
}
void draw() {
if (i +1 > filenames.length) {println("Uh.. Done!"); System.exit(0);}
row = 0;
column = 0;
img = loadImage(basedir+"/"+filenames[i]);
image(img,0,0);
while(column < width-1) {
img.loadPixels();
sortColumn();
column++;
img.updatePixels();
}
while(row < height-1) {
img.loadPixels();
sortRow();
row++;
img.updatePixels();
}
image(img,0,0);
saveFrame(basedir+"/out/"+filenames[i]);
println("Frames processed: "+frameCount+"/"+filenames.length);
i++;
}
essentially I want to do the same thing only with a different image process but my code is not doing this to all with in the folder... just one file.
You seem to be confused about what the setup() function does. It runs once, and only once, at the beginning of your code's execution. You don't have any looping structure for processing the other files, so it's no wonder that it only processes the first one. Perhaps wrap the entire thing in a for loop? It looks like you kind of thought about this, judging by the global variable i, but you never increment it to go to the next image and you overwrite its value in several for loops later anyway.
I'm trying to generate some random data points for my Highcharts series, but I'm having issues with the data function. Here's my code (simplified from Fiddle):
series : {
name : 'Total Mentions',
type:'spline',
lineWidth:1,
data : (function() {
var arr = [];
for(var i = 0; i < 500; i++) {
var date = randomDate(new Date(2004, 0, 9), new Date());
var randNum = Math.round(Math.random()*100);
var finalDate = "Date.UTC(" + date.getFullYear() + ", " + date.getDate() + ", " + date.getMonth() + ")";
arr.push([finalDate, randNum]);
}
return arr;
})()
},
[...etc...],
The format that should be coming out should look like this:
[Date.UTC(2008, 23, 8),56],
[Date.UTC(2012, 12, 6),21],
[Date.UTC(2008, 22, 10),16],
[Date.UTC(2009, 17, 7),25],
[...etc...],
Right now, my page isn't loading the chart. The page will load infinitely, as if it's not recognizing the data.
Any thoughts?
You should push date in millisec in array, like this;
arr.push([date.getTime(), randNum]);
arr.sort(function (a,b) { if (a[0] < b[0]) return -1; if (a[0] > b[0]) return 1;
return 0; })
return arr;
I've created a fiddle at; http://jsfiddle.net/hkskoglund/cnTqS/4/
Try catching other syntax errors in the console in Chrome devtools.
I have an array of urls of images, from which i have to first download the images then show in sliding.
But i want to download images asynchronously. I am using 3 images at a time like in the below code :
var imageViewArray = [];
var nextImageIndex;
var imageNameArray=[];
for (var i = 0; i < 3; i++) {
var imageView1 = Titanium.UI.createImageView({
});
imageViewArray[i] = imageView1;
}
var scrollingView = Titanium.UI.createScrollableView({
views : imageViewArray,
width : 310,
height : 450,
top : 5,
left : 5,
borderWidth : 2,
borderColor : '#000'
});
scrollingView.addEventListener('scroll', function(e) {
Ti.API.info("C=" + e.currentPage);
Ti.API.info("N=" + nextImageIndex);
if (e.currentPage == 2 && nextImageIndex < imageNameArray.length - 2) {
//Setting the current page to 1 will allow the smooth swipe functionality
scrollingView.currentPage = 1;
nextImageIndex += 1;
var vw = scrollingView.views[0];
imageViewArray[0] = scrollingView.views[1];
imageViewArray[1] = scrollingView.views[2];
scrollingView.removeView[vw];
vw.image = imageNameArray[nextImageIndex + 1];
imageViewArray[2] = vw;
scrollingView.views = imageViewArray;
} else if (e.currentPage == 0 && nextImageIndex > 1) {
nextImageIndex -= 1;
scrollingView.currentPage = 1;
var vw = scrollingView.views[2];
imageViewArray[1] = scrollingView.views[0];
imageViewArray[2] = scrollingView.views[1];
scrollingView.removeView[vw];
vw.image = imageNameArray[nextImageIndex - 1];
imageViewArray[0] = vw;
scrollingView.views = imageViewArray;
}
});
scrollingView.views[0].image = imageNameArray[0];
scrollingView.views[1].image = imageNameArray[1];
scrollingView.views[2].image = imageNameArray[2];
nextImageIndex = 1;
Can anyone tell me where shall i need to download th eimages from the urls.
Thanks
Firstly, download at least 3 images to start with when you load this view. Then in your scroll event you'll download more images.
Q: Why are you removing views from the scrollview?