根据函数的值绘制不同颜色/大小的圆圈

时间:2018-03-12 19:40:15

标签: c++ openframeworks

我正在尝试根据我的功能值绘制具有某些颜色和大小的圆圈。我在Openframeworks中正在研究这个问题。 我的函数来自我的bin / data文件夹中的json文件,它运行良好(我能够获取值并在画布上写入它们),它们的代码如下所示:

// 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();

因此,例如,如果tone_id具有值“joy”,我想绘制一个黄色的圆圈 大小会根据分数而变化,分数可以是0-1, 所以,如果得分是0.8,而tone_id是喜悦那么这意味着这句话是80%的快乐。

我即将绘制很多圆圈,大约100个(用5种不同的颜色),我想给它们50%的透明度,这样它们就不会重叠了,我怎么能在这里添加呢?< / p>

顺便说一句。如果有帮助,我正在使用音调分析器api。

谢谢!

0 个答案:

没有答案
相关问题