Пример #1
0
// Level07 Screen Update logic
void UpdateLevel07Screen(void)
{
    // Update Level07 screen variables here!
    framesCounter++;
    
    if (!done)
    {
        if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
        {
            if (CheckCollisionPointCircle(GetMousePosition(), leftBtnPos, btnRadius)) leftCircleActive = !leftCircleActive;
            else if (CheckCollisionPointCircle(GetMousePosition(), middleBtnPos, btnRadius)) middleCircleActive = !middleCircleActive;
            else if (CheckCollisionPointCircle(GetMousePosition(), rightBtnPos, btnRadius)) rightCircleActive = !rightCircleActive;
            
            if (rightCircleActive && CheckCollisionPointCircle(GetMousePosition(), leftCirclePos, circleRadius))
            {
                if (CheckColor(leftCircleColor, GRAY)) leftCircleColor = LIGHTGRAY;
                else leftCircleColor = GRAY;
            }
            
            if (middleCircleActive && CheckCollisionPointCircle(GetMousePosition(), middleCirclePos, circleRadius))
            {
                if (CheckColor(middleCircleColor, GRAY)) middleCircleColor = LIGHTGRAY;
                else middleCircleColor = GRAY;
            }
            
            if (rightCircleActive && leftCircleActive && CheckCollisionPointCircle(GetMousePosition(), rightCirclePos, circleRadius))
            {
                if (CheckColor(rightCircleColor, GRAY)) rightCircleColor = LIGHTGRAY;
                else rightCircleColor = GRAY;
            }
        }
    
        // Check all cicles done
        if (CheckColor(leftCircleColor, LIGHTGRAY) && CheckColor(middleCircleColor, LIGHTGRAY) && CheckColor(rightCircleColor, LIGHTGRAY) &&
            !leftCircleActive && !middleCircleActive && !rightCircleActive)
        {
            done = true;
            PlaySound(levelWin);
        }
    }
    
    if (done && !levelFinished)
    {
        levelTimeSec = framesCounter/60;
        levelFinished = true;
        framesCounter = 0;
    }
    
    if (levelFinished)
    {
        framesCounter++;
        
        if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true;
    }
}
std_msgs::ColorRGBA VisualizeDetectedObjects::ParseColor(const std::vector<double> &in_color)
{
  std_msgs::ColorRGBA color;
  float r,g,b,a;
  if (in_color.size() == 4) //r,g,b,a
  {
    color.r = CheckColor(in_color[0]);
    color.g = CheckColor(in_color[1]);
    color.b = CheckColor(in_color[2]);
    color.a = CheckAlpha(in_color[3]);
  }
  return color;
}
qint64 BitcoinUnits::factor(int unit, int nColorIn)
{
    if (!CheckColor(nColorIn))
    {
        return BASE_COIN;
    }
    int64_t u = COIN[nColorIn];
    switch(unit)
    {
    case BTC:
        u = COIN[nColorIn];
        break;
    case mBTC:
        u = COIN[nColorIn] / 1000;
        break;
    case uBTC:
        u = COIN[nColorIn] / 1000000;
        break;
    default:
        u = COIN[nColorIn];
    }
    if (u <= 0)
    {
        u = COIN[nColorIn];
    }
    return u;
}
Пример #4
0
void DataGen(int randnum_list[345])                 //generate the data, return the randnum list
{   
    int valid_count=0;
    int tmp=0;
    
    while(true)
    {
        tmp=randnum(1,1500);                        //required num from 0 to 9. but the randnum() function is not real rand. so the max is 15. larger than reguired.
        
        if(    1<=tmp&&tmp<= 100)tmp= 0;
        if(  101<=tmp&&tmp<= 200)tmp= 1;
        if(  201<=tmp&&tmp<= 300)tmp= 2;
        if(  301<=tmp&&tmp<= 400)tmp= 3;
        if(  401<=tmp&&tmp<= 500)tmp= 4;
        if(  501<=tmp&&tmp<= 600)tmp= 5;
        if(  601<=tmp&&tmp<= 700)tmp= 6;
        if(  701<=tmp&&tmp<= 800)tmp= 7;
        if(  801<=tmp&&tmp<= 900)tmp= 8;
        if(  901<=tmp&&tmp<=1000)tmp= 9;
        if( 1001<=tmp&&tmp<=1500)tmp=10;
        
        if(!CheckColor(tmp))continue;               //check the random number. if it is full, then continue.
        if(tmp>9)tmp=10;                            //if tmp is larger than 9, set it as 10
        randnum_list[valid_count++]=tmp;            //put tmp into randnum_list
        if(valid_count>344)break;                   //if randnum_list if full, then break
    }
}//end of DataGen(int)
int BitcoinUnits::decimals(int unit, int nColorIn)
{
    if (!CheckColor(nColorIn))
    {
        return 0;
    }
    int d = DECIMALS[nColorIn];
    switch(unit)
    {
    case BTC: return std::max(d, 0);
    case mBTC: return std::max(d - 3, 0);
    case uBTC: return std::max(d - 6, 0);
    default: return 0;
    }
}
int BitcoinUnits::amountDigits(int unit, int nColorIn)
{
    if (!CheckColor(nColorIn))
    {
        return 0;
    }
    int d = DIGITS[nColorIn];
    switch(unit)
    {
    case BTC: return d; // 21,000,000 (# digits, without commas)
    case mBTC: return d + 3; // 21,000,000,000
    case uBTC: return d + 6; // 21,000,000,000,000
    default: return 0;
    }
}
bool BitcoinUnits::valid(int unit, int nColorIn)
{
    if (unit == BitcoinUnits::BTC)
    {
       return true;
    }
    if (!CheckColor(nColorIn))
    {
       return false;
    }
    if (unit >= COLOR_UNITS[nColorIn])
    {
       return false;
    }
    return true;
}
QString TransactionDesc::TxOutToHTML(const CTxOut &txout, const CWallet* wallet)
{
    // individual tx do not affect any representation
    static const bool fMultiSig = true;

    QString strHTML;
    if (wallet->IsMine(txout, fMultiSig) & ISMINE_ALL)
    {
        std::pair<int, int64_t> cred= wallet->GetCredit(txout, fMultiSig);
        if (CheckColor(cred.first))
        {
            strHTML += "<b>" + tr("Credit") + ":</b> " +
                         FormatValue(cred.second, cred.first) + "<br>";
        }
    }
    return strHTML;
}
QString TransactionDesc::TxInToHTML(const CTxIn &txin, const CWallet* wallet)
{
    // individual tx do not affect any balance calculation
    static const bool fMultiSig = true;

    QString strHTML;
    if (wallet->IsMine(txin, fMultiSig) & ISMINE_ALL)
    {
        std::pair<int, int64_t> deb = wallet->GetDebit(txin, fMultiSig);
        if (CheckColor(deb.first))
        {
            strHTML += "<b>" + tr("Debit") + ":</b> " +
                         FormatValue(-deb.second, deb.first) + "<br>";
        }
    }
    return strHTML;
}
QList<BitcoinUnits::Unit> BitcoinUnits::availableUnits(int nColorIn)
{
    if (!CheckColor(nColorIn))
    {
        throw std::runtime_error(
               strprintf("availableUnts() : currency %d not valid", nColorIn).c_str());
    }
    if (COLOR_UNITS[nColorIn] < 0 || (COLOR_UNITS[nColorIn] - 1) >= BitcoinUnits::END_UNITS)
    {
        throw std::runtime_error(
               strprintf("availableUnts() : number of units for currency %d not valid", nColorIn).c_str());
    }
    QList<BitcoinUnits::Unit> unitlist;
    for (int i = 0; i < COLOR_UNITS[nColorIn]; ++i)
    {
        unitlist.append((BitcoinUnits::Unit) i);
    }
    return unitlist;
}
Пример #11
0
SEXP do_rgb(SEXP call, SEXP op, SEXP args, SEXP env)
{
    SEXP c, r, g, b, a, nam;
    int OP, i, l_max, nr, ng, nb, na;
    Rboolean max_1 = FALSE;
    double mV = 0.0; /* -Wall */

    checkArity(op, args);
    OP = PRIMVAL(op);
    if(OP) {/* op == 1:  rgb256() :*/
	PROTECT(r = coerceVector(CAR(args), INTSXP)); args = CDR(args);
	PROTECT(g = coerceVector(CAR(args), INTSXP)); args = CDR(args);
	PROTECT(b = coerceVector(CAR(args), INTSXP)); args = CDR(args);
	PROTECT(a = coerceVector(CAR(args), INTSXP)); args = CDR(args);
    }
    else {
	PROTECT(r = coerceVector(CAR(args), REALSXP)); args = CDR(args);
	PROTECT(g = coerceVector(CAR(args), REALSXP)); args = CDR(args);
	PROTECT(b = coerceVector(CAR(args), REALSXP)); args = CDR(args);
	PROTECT(a = coerceVector(CAR(args), REALSXP)); args = CDR(args);
	mV = asReal(CAR(args));			       args = CDR(args);
	max_1 = (mV == 1.);
    }

    nr = LENGTH(r); ng = LENGTH(g); nb = LENGTH(b); na = LENGTH(a);
    if (nr <= 0 || ng <= 0 || nb <= 0 || na <= 0) {
	UNPROTECT(4);
	return(allocVector(STRSXP, 0));
    }
    l_max = nr;
    if (l_max < ng) l_max = ng;
    if (l_max < nb) l_max = nb;
    if (l_max < na) l_max = na;

    PROTECT(nam = coerceVector(CAR(args), STRSXP)); args = CDR(args);
    if (length(nam) != 0 && length(nam) != l_max)
	errorcall(call, _("invalid names vector"));
    PROTECT(c = allocVector(STRSXP, l_max));

#define _R_set_c_RGBA(_R,_G,_B,_A)				\
    for (i = 0; i < l_max; i++)				\
	SET_STRING_ELT(c, i, mkChar(RGBA2rgb(_R,_G,_B,_A)))

    if(OP) { /* OP == 1:  rgb256() :*/
	_R_set_c_RGBA(CheckColor(INTEGER(r)[i%nr]),
		      CheckColor(INTEGER(g)[i%ng]),
		      CheckColor(INTEGER(b)[i%nb]),
		      CheckAlpha(INTEGER(a)[i%na]));
    }
    else if(max_1) {
	_R_set_c_RGBA(ScaleColor(REAL(r)[i%nr]),
		      ScaleColor(REAL(g)[i%ng]),
		      ScaleColor(REAL(b)[i%nb]),
		      ScaleAlpha(REAL(a)[i%na]));
    }
    else { /* maxColorVal not in {1, 255} */
	_R_set_c_RGBA(ScaleColor(REAL(r)[i%nr] / mV),
		      ScaleColor(REAL(g)[i%ng] / mV),
		      ScaleColor(REAL(b)[i%nb] / mV),
		      ScaleAlpha(REAL(a)[i%na] / mV));
    }
    if (length(nam) != 0)
	setAttrib(c, R_NamesSymbol, nam);
    UNPROTECT(6);
    return c;
}
Пример #12
0
static void SetCheckColor(FXWindow*w)
{
  FXColor c=w->getApp()->getForeColor();
  CheckColor(FXCheckButton);
}
Пример #13
0
// stealth addresses have the ticker suffix
bool IsStealthAddress(const std::string& qualAddress)
{
    std::string encodedAddress;

#if USE_QUALIFIED_ADDRESSES
    int nColor;
    if (!SplitQualifiedAddress(qualAddress, encodedAddress, nColor, fDebug))
    {
        if (fDebug)
        {
            printf("StealthAddress::IsStealthAddress: could not split address..\n");
        }
        return false;
    }
#else
    encodedAddress = qualAddress;
#endif

    data_chunk raw;
    
    if (!DecodeBase58(encodedAddress, raw))
    {
        if (fDebug)
        {
            printf("IsStealthAddress: DecodeBase58 falied.\n");
        }
        return false;
    };
    
    if (!VerifyChecksum(raw))
    {
        if (fDebug)
        {
            printf("IsStealthAddress: verify_checksum falied.\n");
        }
        return false;
    };
    
    if (raw.size() < N_COLOR_BYTES + 1 + 1 + 33 + 1 + 33 + 1 + 1 + 4)
    {
        if (fDebug)
        {
            printf("IsStealthAddress: too few bytes provided.\n");
        }
        return false;
    };
    
    
    uint8_t* p = &raw[0];
    int nColor = 0;
    for (int i = 0; i < N_COLOR_BYTES; ++i)
    {
         nColor += pow(256, (int) i) * ((int) *p);
         ++p;
    }

    if (!CheckColor(nColor))
    {
        if (fDebug)
        {
            printf("IsStealthAddress: Invalid currency %d.\n", nColor);
        }
    }

    uint8_t version = *p++;
    
    if (version != stealth_version_byte)
    {
        if (fDebug)
        {
            printf("IsStealthAddress version mismatch 0x%x != 0x%x.\n", version, stealth_version_byte);
        }
        return false;
    };
    
    return true;
};
Пример #14
0
// color information is stored strting in the second byte so that
// addresses for different colors have distinct starting sequences
bool CStealthAddress::SetEncoded(const std::string& encodedAddress)
{

    data_chunk raw;
    
    if (!DecodeBase58(encodedAddress, raw))
    {
        if (fDebug)
            printf("CStealthAddress::SetEncoded DecodeBase58 falied.\n");
        return false;
    };
    
    if (!VerifyChecksum(raw))
    {
        if (fDebug)
            printf("CStealthAddress::SetEncoded verify_checksum falied.\n");
        return false;
    };

    size_t nRawSize = raw.size();
    
    // see CStealthAddress::Encoded()
    // Put color first so that stealth addresses of different currencies look different
    // N_COLOR_BYTES, 1-version, 1-options, 33-scan_pubkey, 1-#spend_pubkeys,
    // 33-spend_pubkey, 1-#sigs, 1-?, 4 checksum
    if (nRawSize < N_COLOR_BYTES + 1 + 1 + 33 + 1 + 33 + 1 + 1 + 4)
    {
        if (fDebug)
            printf("CStealthAddress::SetEncoded() too few bytes provided.\n");
        return false;
    };

    uint8_t* p = &raw[0];
 
    // Stealth addresses store color as a simple index little bytes first.
    this->nColor = 0;
    for (int i = 0; i < N_COLOR_BYTES; ++i)
    {
         this->nColor += pow(256, (int) i) * ((int) *p);
         ++p;
    }

    if (!CheckColor(nColor))
    {
        printf("CStealthAddress::SetEncoded(): Color %d is not valid (1...%d).\n",
                                                             this->nColor, N_COLORS);
    }

    uint8_t version = *p++;
   
    if (version != stealth_version_byte)
    {
        printf("CStealthAddress::SetEncoded version mismatch 0x%x != 0x%x.\n", version, stealth_version_byte);
        return false;
    };

    options = *p++;
    
    scan_pubkey.resize(33);
    memcpy(&scan_pubkey[0], p, 33);
    p += 33;
    //uint8_t spend_pubkeys = *p++;
    p++;
    
    spend_pubkey.resize(33);
    memcpy(&spend_pubkey[0], p, 33);

    return true;
};