Hey!
I’m trying to draw circles with certain colors and sizes depending on the value of my functions.
My functions come from a json file in my bin/data folder, which is working well (I am able to fetch the values and write them on the canvas) and my code now looks like this:
using namespace std;
int main();
int joy_circle = 0;
float value = 0;
int sentence_id = 0;
int size = 0;
int posX = 0;
void update(int score);
ofTrueTypeFont myfont;
string enterString;
//--------------------------------------------------------------
void ofApp::setup(){
ofSetFrameRate(60);
std::string file = "tweets.json";
myfont.load("verdana.ttf",30);
// Now parse the JSON
bool parsingSuccessful = result.open(file);
if (parsingSuccessful)
{
ofLogNotice("ofApp::setup") << result.getRawString();
// now write pretty print
if (!result.save("example_output_pretty.json", true))
{
ofLogNotice("ofApp::setup") << "example_output_pretty.json written unsuccessfully.";
}
else
{
ofLogNotice("ofApp::setup") << "example_output_pretty.json written successfully.";
}
// now write without pretty print
if (!result.save("example_output_fast.json", false))
{
ofLogNotice("ofApp::setup") << "example_output_pretty.json written unsuccessfully.";
}
else
{
ofLogNotice("ofApp::setup") << "example_output_pretty.json written successfully.";
}
}
else
{
ofLogError("ofApp::setup") << "Failed to parse JSON" << endl;
}
}
//--------------------------------------------------------------
void ofApp::update(){
}
//--------------------------------------------------------------
void ofApp::draw(){
// Making a definition for tonenames and drawing it on the canvas
ofSetColor(0);
myfont.drawString("Tone: ", 100, 100);
std::string tone_name = result["sentences_tone"][8]["tones"][0]["tone_name"].asString();
myfont.drawString(tone_name, 250, 100);
std::string joy = result["sentences_tone"][0]["tones"][0]["tone_name"].asString();
int sentence_id = result["sentences_tone"][sentence_id]["tones"][sentence_id].asInt();
std::stringstream ss;
ss << "tone_name = " << result["sentences_tone"][0]["tones"][0]["tone_name"].asString() << std::endl;
ss << "score = " << result["sentences_tone"][0]["tones"][0]["score"].asString() <<
std::endl;
ofDrawBitmapString(ss.str(), 50, 50);
//Making functions for the graphics
std::string tone_id = result["sentences_tone"][sentence_id]["tones"][sentence_id]["tone_id"].asString();
std::string score = result["sentences_tone"][sentence_id]["tones"][sentence_id]
["score"].asString();
So, for example if the tone_id has the value “joy” i want to draw a circle that is yellow and
the size would change depending on the score, the score can be whatever from 0-1,
if the score is 0.8 and tone_id is joy then that means the sentence is 80% joyful.
I am about to draw a lot of circles, about 100 (in 5 different colors) and i’m thinking of giving them a 50% transparency so they don’t overlap, how would i add that in this also?
btw. i’m using the tone analyzer api if that helps
Thank you!