We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
Recently I've been trying to make some programs that use a bit of calculus to make graphs of functions. I don't really know how to use APIs that much, and Processing doesn't seem to have too many resources to figure out how. I scrapped together this to test it out (Replace #### with an app id if you want to test it) :
// github.com/PhiLhoSoft/Processing/blob/master/_QuickExperiments/_Net/GoogleRequest/GoogleRequest.pde
import java.net.*;
String Query = "http://" + "api.wolframalpha.com/v2/query?input=derivative+of+x%5E4&appid=#########";
String[] results;
void setup() {
try {
URL url = new URL(Query);
URLConnection connection = url.openConnection();
results = loadStrings(connection.getInputStream());
}
catch (Exception e) {
e.printStackTrace();
}
printArray(results);
}
The problem is that it takes quite a bit of time to output a request (probably because of the 160 lines of data it gives back), so I'm thinking I'm seriously not using it right since other language's implementation of wolfram's API is so much cleaner and effective, like with Python's. I wonder if there's a better way about getting requests, since I have no idea really what I'm doing.
Thanks!
Answers
try insert noLoop and println at the end of draw.
what takes longer to execute, setup or draw?
OOPS! I accidentally copy and pasted the code from my main program and not a standalone example :P I replaced the main code so now it's the example I wanted to show.
The setup is the problem, as it's the getInputStream() I believe that's taking the most time (I'm not sure what else it could be).