void RainbowSegment::randomize(uint8_t ci){ isStatic = (bool)random8(0,1); changeOnBeat = true; this -> randomizeColor(ci); hueStep[ci] = random8(-20,20); beatStep[ci] = random8(-120,120); }
void Matrix::initParticle(uint8_t i) { particle[i].y = m_height + random8(5); particle[i].x = random8(m_width); particle[i].delaySetting = random8(8, 16); particle[i].delay = particle[i].delaySetting; }
// This function generates a random palette that's a gradient // between four different colors. The first is a dim hue, the second is // a bright hue, the third is a bright pastel, and the last is // another bright hue. This gives some visual bright/dark variation // which is more interesting than just a gradient of different hues. void SetupRandomPalette() { currentPalette = CRGBPalette16( CHSV( random8(), 255, 32), CHSV( random8(), 255, 255), CHSV( random8(), 128, 255), CHSV( random8(), 255, 255)); }
void Segment::randomize() { Serial.println("Randomizing!"); this->configure( 0.5 + (1 * (random8(1000) / 1000.0)), 0.3 + (1 * (random8(1000) / 1000.0)), 0, 0, 0, googleColors[random8(16)]); }
void choose_new_shape(nstate *state) { state->current_shape.type = state->next_shape.type; state->current_shape.orientation = state->next_shape.orientation; state->current_shape.colour = state->next_shape.colour; state->current_shape.x = (WELL_WIDTH / 2) - 2; state->current_shape.y = WELL_NOTVISIBLE - shape_sizes[state->next_shape.type] [state->next_shape.orientation][1] - 1; state->next_shape.type = random8(MAXSHAPES - 1); state->next_shape.orientation = random8(MAXORIENTATIONS - 1); state->next_shape.colour = block_colours[random8(MAX_BLOCK_COLOUR)]; }
// This function returns a uniformly distributed integer in the range of // of [0,max). The added complexity of this function is required to ensure // a uniform distribution since the naive modulus max (% max) introduces // bias for all values of max that are not powers of two. // // The loops below are needed, because there is a small and non-uniform chance // That the division below will yield an answer = max, so we just get // the next random value until answer < max. Which prevents the introduction // of bias caused by the division process. This is why we can't use the // simpler modulus operation which introduces significant bias for divisors // that aren't a power of two uint32_t EntropyClass::random(uint32_t max) { uint32_t slice; if (max < 2) retVal=0; else { retVal = WDT_MAX_32INT; if (max <= WDT_MAX_8INT) // If only byte values are needed, make best use of entropy { // by diving the long into four bytes and using individually slice = WDT_MAX_8INT / max; while (retVal >= max) retVal = random8() / slice; } else if (max <= WDT_MAX_16INT) // If only word values are need, make best use of entropy { // by diving the long into two words and using individually slice = WDT_MAX_16INT / max; while (retVal >= max) retVal = random16() / slice; } else { slice = WDT_MAX_32INT / max; while (retVal >= max) retVal = random() / slice; } } return(retVal); }
void RandomScroll::run(Sign &sign, uint8_t layer){ sign.textChanged = true; char random_char = char(' ' + random8(95) ); sign.pushChar(random_char); sign.setCharacters(); }
static void pfinit(field_t pf) { coord_t x, y; #ifndef BITSTUFFED for (y = YSIZE; y--;) { for (x = XSIZE; x--;) { setcell(pf, x, y, (random8() & 1) ? alive : dead); } } #else for (y = 0; y < FIELD_YSIZE; ++y) { for (x = 0; x < FIELD_XSIZE; ++x) { pf[y][x] = random8(); } } #endif }
// This is called from the constructor, so if you put a Serial.println() here, you're gonna have a bad time void seed(uint8_t chance) { for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { if (random8() < chance) { (*currState)[x][y] = hue; } } } }
PatternBase::PatternBase(CRGB *l,int16_t nl) { PalleteServer* PS = PalleteServer::getInstance(); currentPallete =PS->changePallete(random8(30)); leds=l; brightness =100; FastLED.setBrightness(brightness); if (nl==-1){ nl = NUM_LEDS; //If it was unitialized set to maximum. This allows multiple parts with seperate patterns } numLeds =nl; brightNessBPM = 1.0 /(random() %10+1); }
void FlamesLegMode::fire2012() { // Step 1. Cool down every cell a little for (int i = 0; i < _pixelCount; i++) _heat[i] = qsub8(_heat[i], random8(0, ((_cooling * 10) / _pixelCount) + 2)); // Step 2. Heat from each cell drifts 'up' and diffuses a little for (int k = _pixelCount - 3; k > _half; k--) _heat[k] = (_heat[k - 1] + _heat[k - 2] + _heat[k - 2] ) / 3; for (int k = 0; k < (_half - 3); k++) _heat[k] = (_heat[k + 1] + _heat[k + 2] + _heat[k + 2] ) / 3; // Step 3. Randomly ignite new 'sparks' of _heat near the bottom //if (random8() < SPARKING) if ((_currentTime - _lastStepTime) < 200) { for (int i = _half - 6; i < (_half + 6); i++) _heat[i] = 230; } else if (random8() < _sparking) { int y_back = random8(_half, _half + 6); int y_front = random8(_half - 6, _half); _heat[y_back] = qadd8(_heat[y_back], random8(160, 256)); _heat[y_front] = qadd8(_heat[y_front], random8(160, 256)); } // Step 4. Map from _heat cells to LED colors for (int j = 0; j < _pixelCount; j++) _pixels[j] = heatColor(_heat[j]); }
uint16_t fire2012(uint16_t tick, uint32_t color) { // Fire2012 by Mark Kriegsman, July 2012 // as part of "Five Elements" shown here: http://youtu.be/knWiGsmgycY // adapted from example included with fastLED if(tick == 0) { random16_add_entropy( random()); static byte heat[NUM_LEDS]; // Array of temperature readings at each simulation cell // Step 1. Cool down every cell a little for( int i = 0; i < NUM_LEDS; i++) { heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2)); } // Step 2. Heat from each cell drifts 'up' and diffuses a little for( int k= NUM_LEDS - 1; k >= 2; k--) { heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3; } // Step 3. Randomly ignite new 'sparks' of heat near the bottom if( random8() < SPARKING) { int y = random8(7); heat[y] = qadd8( heat[y], random8(160,255) ); } // Step 4. Map from heat cells to LED colors for(uint16_t j = 0; j < NUM_LEDS; j++) { CRGB hColor = HeatColor(heat[j]); uint32_t red = hColor.red; uint32_t green = hColor.green; uint32_t blue = hColor.blue; uint32_t intColor = (red<<16)+(green<<8)+blue; setLedColor(j, HeatColor(heat[j])); } } return 4; }
void Rule31Pattern::updateLeds() { uint8_t temp = beatsin8(1,10,20); CRGB color = ColorFromPalette(*currentPallete, 10, 255, LINEARBLEND); for (uint8_t i =0; i<numLeds;i++){ //if (random8()%temp ==0) { color = ColorFromPalette(*currentPallete, random8(255)/*cellColors[i]*/, 255, LINEARBLEND); leds[i]=color;//ColorFromPalette(*currentPallete, cellColors[i], 255, LINEARBLEND); } } CRGB last =leds[numLeds-1]; for (int i = 1; i <numLeds-1; i++) { //leds[i] = (leds[i - 1] +leds[i] +leds[i+1])/3; } leds[0] = last; //updateCells(); }
ret_t dongleInit() { // USART initialization // Communication Parameters: 8 Data, 1 Stop, No Parity // USART Receiver: On // USART Transmitter: On // USART0 Mode: Asynchronous // USART Baud Rate: 38400 UCSR0A=0x00; UCSR0B=0x18; UCSR0C=0x06; UBRR0H=0x00; UBRR0L=0x0C; dongleDebugPrint("DEBUG=dongleInit: Serial port ready.\n"); /* Turn ON nfr module */ INIT_NW_STACK(); gID = (uint16_t)random8(); dongleDebugPrint("DEBUG=dongleInit: Ready to stablish peer to peer conections. gID = %d\n",gID); return SUCCESS; }
void RainbowLegMode::setup(LWConfigs *c, char const *n, int i2c_channel, ADXL345 *adxl, byte count, byte half, CRGB *p) { _lastStartHue = 0; _increment = (float)255/(float)count; if (_setup_complete) return; // <cgerstle> should probably be doing this in a super constructor... _config = c; _legName = n; _channel = i2c_channel; _adxl = adxl; _pixelCount = count; _half = half; _pixels = p; _perlinZ = (double) random8() / (double) 25500; _setup_complete = true; }
void draw(EffectControls controls) { random16_add_entropy(controls.rawMic); // Skip every second frame otherwise we go too fast // if (frame++ & 0x01) { // copyToLedsArray(currState); // return; // } if (frame++ == 1 || controls.optionButton) { seed(random8(DENSITY)); } // Serial.println("Current state:"); // for (int x = 0; x < WIDTH; x++) { // for (int y = 0; y < HEIGHT; y++) { // Serial.print(" "); Serial.print((*currState)[x][y]); // } // Serial.println(); // } // Serial.println(); // Update the nextState array with the next generation (skip 0, our sentinel value) if (++hue == 0) { hue = 1; } // Serial.print("Hue for this generation = "); Serial.println(hue); for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { // Serial.print("draw() x = "); Serial.print(x); Serial.print(", y = "); Serial.println(y); if (alive(x, y)) { // Serial.println("It lives!"); if ((*currState)[x][y] == 0) { // it's new, so give it the current hue (*nextState)[x][y] = hue; } else { // it's old, so give it the existing hue (*nextState)[x][y] = (*currState)[x][y]; } } else { // Serial.println("It dies!"); (*nextState)[x][y] = 0; } // Serial.println("Going around again?"); } } // Serial.println("Next state:"); // for (int x = 0; x < WIDTH; x++) { // for (int y = 0; y < HEIGHT; y++) { // Serial.print(" "); Serial.print((*nextState)[x][y]); // } // Serial.println(); // } // Serial.println(); // Copy nextState into leds array copyToLedsArray(nextState); // make nextState our new currentState, ready for the next generation uint8_t (*tempState)[WIDTH][HEIGHT] = currState; currState = nextState; nextState = tempState; };
void Layer::initEffect() { orientation = getEffectOrientation(effect); if (orientation == ORIENTATION_NIL) orientation = static_cast<Orientation>(random8(NUM_ORIENTATIONS)); effectInit(effect)(meta, pixelCount()); }
void Layer::setRandomEffect() { setEffect( random8(AUTO_EFFECT_NUM) ); }
// Randomly pick next image effect and trans effect indices: void Layer::transitionStart() { setTransition( random8(TRANSITION_NUM) ); }
void RandomWipe::begin() { _thsv.h = random8(); _trgb = _thsv; }
uint8_t prng_get_byte(void){ return random8(); }
void PinTest(void) { u8 err, tmp; err=0; // проверка ножки UART TX PORTD|=(1<<PD3); _delay_loop_1(3); if (!(PIND&(1<<PD3))) err|=0x01; PORTD&=~(1<<PD3); DDRD|=(1<<PD3); _delay_loop_1(3); if (PIND&(1<<PD3)) err|=0x02; DDRD&=~(1<<PD3); if (err) // проблемы с ножкой UART TX { // хаотически мигаем св.диодом DDRB|=(1<<PB7); while (1) { PORTB&=~(1<<PB7); // led off if (random8()&0x01) PORTB|=(1<<PB7); // led on _delay_loop_2(0x6c00); } } // проблем с ножки UART TX нет - directuart_init(); // - задействуем UART без буфера FIFO directuart_crlf(); directuart_crlf(); directuart_crlf(); print_msg(msg_title1); print_short_vers(); print_mlmsg(mlmsg_pintest); // проверка ножек. 1 этап. PORTA=0b01010101; DDRA =0b10101010; PORTB=0b10000010; DDRB =0b00000101; PORTC=0b00010101; DDRC =0b00001010; PORTD|= (1<<PD5); DDRD &=~(1<<PD5); PORTE|= (1<<PE0); DDRE &=~(1<<PE0); PORTE&=~(1<<PE1); DDRE |= (1<<PE1); PORTG=0b00010101; DDRG =0b00001010; _delay_loop_2(276); // 100 us err=0; tmp=PINA; if (tmp!=0b01010101) err|=0x01; tmp=PINB; if ((tmp&0b10000111)!=0b10000000) err|=0x02; tmp=PINC; if ((tmp&0b00011111)!=0b00010101) err|=0x04; if (!(PIND&(1<<PD5))) err|=0x08; tmp=PINE; if ((tmp&0b00000011)!=0b00000001) err|=0x10; tmp=PING; if ((tmp&0b00011111)!=0b00010101) err|=0x20; // проверка ножек. 2 этап. PORTA=0b10101010; DDRA =0b01010101; PORTB=0b00000101; DDRB =0b10000010; PORTC=0b00001010; DDRC =0b00010101; PORTD&=~(1<<PD5); DDRD |= (1<<PD5); PORTE&=~(1<<PE0); DDRE |= (1<<PE0); PORTE|= (1<<PE1); DDRE &=~(1<<PE1); PORTG=0b00001010; DDRG =0b00010101; _delay_loop_2(276); // 100 us tmp=PINA; if (tmp!=0b10101010) err|=0x01; tmp=PINB; if ((tmp&0b10000111)!=0b00000101) err|=0x02; tmp=PINC; if ((tmp&0b00011111)!=0b00001010) err|=0x04; if (PIND&(1<<PD5)) err|=0x08; tmp=PINE; if ((tmp&0b00000011)!=0b00000010) err|=0x10; tmp=PING; if ((tmp&0b00011111)!=0b00001010) err|=0x20; // итог, печать результата if (err) { u16 ptr; ptr=0x0020; while (ptr<0x003c) *(u8*)(ptr++)=0; ptr=0x0061; while (ptr<0x0066) *(u8*)(ptr++)=0; print_mlmsg(mlmsg_pintest_error); if (err&0x01) print_msg(msg_pintest_pa); if (err&0x02) print_msg(msg_pintest_pb); if (err&0x04) print_msg(msg_pintest_pc); if (err&0x08) print_msg(msg_pintest_pd); if (err&0x10) print_msg(msg_pintest_pe); if (err&0x20) print_msg(msg_pintest_pg); print_mlmsg(mlmsg_halt); while (1) {} } else { print_mlmsg(mlmsg_pintest_ok); } }