AniMathUtils.cpp 3.08 KB
//
//  AniMathUtils.cpp
//  SteveMaggieCpp
//
//  Created by Katarzyna Kalinowska-Górska on 10.05.2017.
//
//

#include <stdio.h>
#include "AniMathUtils.h"
#include <random>

// random generator

double AniMathUtils::getRandom(double min, double max){

    auto rng = _getRNG();
    std::uniform_real_distribution<> dist(min, max);
    return dist(rng);
}

int AniMathUtils::getRandomInt(int min, int max){

    auto rng = _getRNG();
    std::uniform_int_distribution<std::mt19937::result_type> dist6(min,max);
    return dist6(rng);
}

cocos2d::Color4F AniMathUtils::getRandomOpaqueColor(){
    auto r = AniMathUtils::getRandom(0, 1);
    auto g = AniMathUtils::getRandom(0, 1);
    auto b = AniMathUtils::getRandom(0, 1);
    return cocos2d::Color4F(r,g,b,1);
}

//void AniMathUtils::drawRoundedCorneredRect(cocos2d::DrawNode* drawNode, cocos2d::Rect rect, float cornerRadius, cocos2d::Color4F& color){
//
//    drawNode->drawLine(cocos2d::Vec2(rect.getMinX()+cornerRadius, rect.getMinY()), cocos2d::Vec2(rect.getMaxX()-cornerRadius, rect.getMinY()), color);
//    drawNode->drawLine(cocos2d::Vec2(rect.getMaxX(), rect.getMinY()+cornerRadius), cocos2d::Vec2(rect.getMaxX(), rect.getMaxY()-cornerRadius), color);
//    drawNode->drawLine(cocos2d::Vec2(rect.getMaxX()-cornerRadius, rect.getMaxY()), cocos2d::Vec2(rect.getMinX()+cornerRadius, rect.getMaxY()), color);
//    drawNode->drawLine(cocos2d::Vec2(rect.getMinX(), rect.getMaxY()-cornerRadius), cocos2d::Vec2(rect.getMinX(), rect.getMinY()+cornerRadius), color);
//
//    static float MagicConst = 0.552f;
//
//    drawNode->setLineWidth(1);
//
//    auto corner = cocos2d::Vec2(rect.getMinX(), rect.getMinY()); //bottom left
//    drawNode->drawCubicBezier(cocos2d::Vec2(corner.x, corner.y + cornerRadius), cocos2d::Vec2(corner.x, corner.y + cornerRadius*(1-MagicConst)), cocos2d::Vec2(corner.x + cornerRadius*(1-MagicConst), corner.y), cocos2d::Vec2(corner.x + cornerRadius, corner.y), 100, color);
//    corner = cocos2d::Vec2(rect.getMinX(), rect.getMaxY());
//    drawNode->drawCubicBezier(cocos2d::Vec2(corner.x, corner.y - cornerRadius), cocos2d::Vec2(corner.x, corner.y - cornerRadius*(1-MagicConst)), cocos2d::Vec2(corner.x + cornerRadius*(1-MagicConst), corner.y), cocos2d::Vec2(corner.x + cornerRadius, corner.y), 80, color);
//    corner = cocos2d::Vec2(rect.getMaxX(), rect.getMaxY());
//    drawNode->drawCubicBezier(cocos2d::Vec2(corner.x - cornerRadius, corner.y), cocos2d::Vec2(corner.x - cornerRadius*(1-MagicConst), corner.y), cocos2d::Vec2(corner.x, corner.y - cornerRadius*(1-MagicConst)), cocos2d::Vec2(corner.x, corner.y - cornerRadius), 50, color);
//    corner = cocos2d::Vec2(rect.getMaxX(), rect.getMinY());
//    drawNode->drawCubicBezier(cocos2d::Vec2(corner.x, corner.y + cornerRadius), cocos2d::Vec2(corner.x, corner.y + cornerRadius*(1-MagicConst)), cocos2d::Vec2(corner.x - cornerRadius*(1-MagicConst), corner.y), cocos2d::Vec2(corner.x - cornerRadius, corner.y), 30, color);
//
//}



///////////////////////////////////////
// private

std::mt19937 AniMathUtils::_getRNG(){
    std::mt19937 rng;
    rng.seed(std::random_device()());
    return rng;
}