Give function a color/size depending on the value


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(){


std::string file = "tweets.json";


// Now parse the JSON
bool parsingSuccessful =;

if (parsingSuccessful)
    ofLogNotice("ofApp::setup") << result.getRawString();
    // now write pretty print
    if (!"example_output_pretty.json", true))
        ofLogNotice("ofApp::setup") << "example_output_pretty.json written unsuccessfully.";
        ofLogNotice("ofApp::setup") << "example_output_pretty.json written successfully.";
    // now write without pretty print
    if (!"example_output_fast.json", false))
        ofLogNotice("ofApp::setup") << "example_output_pretty.json written unsuccessfully.";
        ofLogNotice("ofApp::setup") << "example_output_pretty.json written successfully.";
    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
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() <<

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]

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!

I did this, but nothing happens although openframeworks seems to have no problem with the code,

if (tone_id == joy) {
joy = true;
ofSetColor(90, 10, 50);
ofDrawCircle(50, 30, 90);

I know this will not solve the problem, but just wondering if it’s at least on the right path?

Perhaps try
if (tone_id == "joy")
because tone_id is a string and a litteral string must be enclosed between double quotes : “joy”

That results in an error :confused:

which one ? :wink:

Value is not convertible to Int.

Hum, with
std::string tone_id
if (tone_id == "joy")
you can’t have this error on the line I suggest.
My advice is to take good care about the code you post to have good answers. I mean all the relevants parts of your code, not too much, and try to present it well formated. I know it isn’t always easy, but right now I feel it’s difficult to help :slightly_smiling_face: