I’m converting a project from p5.js to processing and am struggling to find the equivalent in processing. I’m using the p5.js properties
var a = {};
so that I can later access and update this variable as such;
var b = steps
if(a[b]&&b<a[b]){
a[b] = steps;
}
However I dont understand how to achieve the same effect in processing.
1 Like
I understand Arraylists, these allow you to create a variable size array, and allows you to use the get method to retrieve the values and the add method to add values. However what I’m looking for is a way to implement the following functionality.
function super_path(){
if(pathfind3.toggle===1){
for(var i=nodestar.length-1;i>-1;i--){
var b = backupstar[i].original_id;
nodestar[i].imprinted_by[b] = true;
var next = nodestar[i].neighbourNode(true,b,backupstar[i]);
if(next){
//a++;
nodestar[i].highlight();
next[1].node_to_node_dist[b] = nodestar[i].node_to_node_dist[b] + next[0];
backupstar[i].nodesconnected[next[1].original_id] = next[1].node_to_node_dist[b];
if(!nodestar[i].path_ref[b]){
nodestar[i].path_ref[b] = [nodestar[i]]
}
next[1].path_ref[b] = [nodestar[i].path_ref[b],next[1]];
next[1].path_ref[b] = next[1].path_ref[b].flat();
backupstar[i].pathtable[next[1].original_id] = [next[1].path_ref[b]];
stackstar[i].push(nodestar[i]);
starhist[i].push(nodestar[i]);
trimStackStar(stackstar[i],b)
nodestar[i] = next[1];
}
else if(!next&&stackstar[i].length>0){
nodestar[i] = stackstar[i].pop();
}
else{
}}}
};
Backupstar[i] is used as a reference and each visited object is marked with the id contained in backupstar[i] and its distance to it. Backupstar[i] is also marked with all the cells which it has visited, and in this way I can check the distance from the original backupstar[i].
Using an array would not allow me to solve my problem, as the property which I’m creating contains both the cell id and distance. If I were using an array i understand that I could use a multidimensional array, ie 2 deep. But then i would not be able to use the include function to check the values it contained unless i iterated with a loop, which can become quite costly.
1 Like
Found the solution.
The HashMap type, acts almost exactly like the properties type in javascript;
HashMap<String,Integer> ca = new HashMap<String,Integer>();
https://processing.org/reference/HashMap.html
1 Like