I am writing a code on Ethereum transactions between couple of wallets. My goal is to make an animation to show that how the transactions are being done between these wallets. So I gave each wallet an X-Y coordination and I wrote a code which shows how the transaction is directed from a wallet to another one. My code works fine when I do that for one transaction at a time , but the problem is when I want to make some of the wallets to make transactions at the same time(as in real world it can happen ), the program doesn’t work. I pasted my code here. I will be glad if you guys can help me.
Table table; // Table object
float beginX;
float beginY;
float endX;
float endY;
float distX;`Preformatted text`
float distY;
float exponent = 4; // Determines the curve
float xDots = 0.0; // Current x-coordinate
float yDots = 0.0; // Current y-coordinate
float step = 0.01; // Size of each step along the path
float pct = 0.01; // Percentage traveled (0.0 to 1.0)
int p = 0;
int iteration = 0;
int multiplier;
void setup() {
size(1920, 1580); // HD size
background(255); // White background; black=(0)
frameRate(30);
//loadData();
// =IF(F3=F2,L2,RANDBETWEEN(1,1919)) =IF(F3=F2,L2,RANDBETWEEN(1,1079))
}
void draw() { // Load CSV file into a Table object. "header" option indicates file has header row; loadData
table = loadTable("Data_First1000B.csv", "header");
for (int p = 2; p<table.getRowCount(); p++) { //p<883; p<table.getRowCount()
TableRow row = table.getRow(p);
// You can access the fields via their column name (or index)
float x = row.getFloat("from_x");
float y = row.getFloat("from_y");
float w = row.getFloat("to_x");
float z = row.getFloat("to_y");
int rowz = row.getInt("row");
beginX = x; // Initial x-coordinate
beginY = y; // Initial y-coordinate
endX = w; // Final x-coordinate
endY = z; // Final y-coordinate
distX = endX - beginX; // X-axis distance to move
distY = endY - beginY; // Y-axis distance to move
pct=0;
while (pct < 1.0) {
println(rowz);
println(distX);
println(distY);
xDots = beginX + (pct * distX);
yDots = beginY + (pow(pct, exponent) * distY);
println(x, y, w, z);
println(pct);
println(xDots);
println(yDots);
fill(0, 255, 0); //green starting wallet
ellipse(beginX, beginY, 10, 10);
fill(255*pct, 0, 0); // red flow, starts tiny grows bigger
ellipse(xDots, yDots, pct*10, pct*10);
fill(0, 0, 255); // blue ending wallet
ellipse(endX, endY, 10, 10);
multiplier = round(pct*100000);
if (pct <= 0) {
if (p < 10) {
save("00000" + p + "_" + multiplier + "00000.png");
} else if (p < 100) {
save("0000" + p + "_" + multiplier + "00000.png");
} else {
save("000" + p + "_" + multiplier + "00000.png");
}
} else if (p < 10) {
if (multiplier < 10000) {
save("00000" + p + "_" + "00" + multiplier + ".png");
} else if (multiplier < 100000) {
save("00000" + p + "_" + "0" + multiplier + ".png");
} else {
save("00000" + p + "_" + multiplier + ".png");
}
} else if (p < 100) {
if (multiplier < 10000) {
save("0000" + p + "_" + "00" + multiplier + ".png");
} else if (multiplier < 100000) {
save("0000" + p + "_" + "0" + multiplier + ".png");
} else {
save("0000" + p + "_" + multiplier + ".png");
}
} else if (p < 1000) {
if (multiplier < 10000) {
save("000" + p + "_" + "00" + multiplier + ".png");
} else if (multiplier < 100000) {
save("000" + p + "_" + "0" + multiplier + ".png");
} else {
save("000" + p + "_" + multiplier + ".png");
}
}
pct += step;
}
}
}
First, you shouldn’t load your .csv table each time in the draw() function because it’s not efficient.
You can assign table in the setup() function so it is only loading once.
Can you give us your .csv file via the upload button? (so we can try your code)
It seems that the upload button only works for JPG files and I am not authorized to upload a .csv
can you give me an email address so that I can mail it to you maybe?
Right now, the animation has one stream of dots at any given time. The
“problem” is that multiple transactions happen at the same time (in the
same “block”). And I want to figure out how to
have multiple streams at the same time for all the transactions in the
same block.
If you look at the data, Block 5890000 has 67 transactions, then Block
5890001 has 60 transactions, and so on. That means, I need to figure
out how to have 67 streams of dots unfolding at the same time (like a
flower opening) for the first time period (Block 5890000), then 60
different streams all unfolding at the same time for the second time period and so on.
This is the whole idea. thank you your code is faster than me and I like it.
But the problem with your code is it goes line by line through all the transactions.
In the real world, multiple transactions can happen simultaneously.
What I want to do is,all the transactions in Block 5890000 happen at the same time, and then go to Block 5890001 which all the transactions within this block happen simultaneously and so on.
[/quote]
Joseph, that is brilliant, I can’t thank you enough. I really appreciate that you are making time to help me with this. You successfully managed to show all the transactions in each block at once. However do you think is there any way that we can show all the transactions in each block are being done gradually at the same time? I mean for example there are about 60 transactions in the block 5890000, and I am wondering if we can see all of them going from (beginX,beginY) to (endX,endY) dot by dot.
I think for now, you need to write your own code.
You have to do the animation for a group of transactions (from the same block).
If you want to do this dot by dot, you have to draw one dot per draw() loop.
hey thank you very much, but my main problem was that I could not do that in the first place. As my code does show all the transactions at the same time even though with more delay, I was more looking to seek help for the dot by dot part. But thank you anyway, I really appreciate it.