uint8_t tick() { v1 += 3; v2 += 5; int rx = (cosi(v1 >> 2) >> 5) + 2; int ry = (sini(v2 >> 2) >> 5) + 2; int x, y; for(y = 0; y < LED_HEIGHT; y++) { for(x = 0; x < LED_WIDTH; x++) { int dx = x - rx; int dy = y - ry; int d = sqrti(dx * dx + dy * dy); int q = ( (sini(x * 8 + (v1)) + sini(y * 8 + (v2)) + sini(d << 5)) >> 2) + 128; int a = (q * 0xffff / 0x10000) >> 6; setLedXY(x, y, a); } } return 0; }
/* return t such that e(t) > sqrt(N), set *faet = odd prime divisors of e(t) */ static ulong compute_t(GEN N, GEN *e, GEN *faet) { /* 2^e b <= N < 2^e (b+1), where b >= 2^52. Approximating log_2 N by * log2(gtodouble(N)) ~ e+log2(b), the error is less than log(1+1/b) < 1e-15*/ double C = dbllog2(N) + 1e-6; /* > log_2 N */ ulong t; GEN B; /* Return "smallest" t such that f(t) >= C, which implies e(t) > sqrt(N) */ /* For N < 2^3515 ~ 10^1058 */ if (C < 3514.6) { t = compute_t_small(C); *e = compute_e(t, faet); return t; } B = sqrti(N); for (t = 8648640+840;; t+=840) { pari_sp av = avma; *e = compute_e(t, faet); if (cmpii(*e, B) > 0) break; avma = av; } return t; }
void Init(struct Gamestate* state) { EnableDebugOutput(DEBUG_USART); printf("Init\r\n"); InitializeLEDs(); SetLEDs(0x01); SetLEDs(0x07); #ifdef ACCELEROMETER /* InitializeAccelerometer(); printf("Init Accelerometer: %s\r\n", PingAccelerometer() > 0 ? "OKAY" : "FAILED"); CalibrateAccelerometer();*/ #endif for(int i=0;i<NumberOfStars;i++) { stars[i].x=GetRandomInteger()%360; stars[i].y=(GetRandomInteger()%200); int z=sqrti((NumberOfStars-1-i)*NumberOfStars)*1000/NumberOfStars; stars[i].dy=1;//6000*1200/(z+200); stars[i].f=(6-(z*7)/1000)+(GetRandomInteger()%6)*7; } }
void rpn_sqrt(calc_number_t *c) { if (calc.base == IDC_RADIO_DEC) { if (c->f < 0) calc.is_nan = TRUE; else c->f = sqrt(c->f); } else { c->i = sqrti(c->i); } }
// Takes axial values and assess current behavior uint8 assess_behavior(uint8 xax, uint8 yax, uint8 zax) { uint8 norm; uint8 stdv; norm = sqrti((xax*xax)+(yax*yax)+(zax*zax)); // Get lower (lie) and upper (fall) bounds stdv = update_SSE(norm); stdv = sqrti(stdv/iter); if(norm > FALLTHRESH*stdv) { return 2; // Potential fall } else if(norm < stdv/LIETHRESH) { return 1; // Abnormally low activity } return 0; // Normal behavior }
static struct commit_list *skip_away(struct commit_list *list, int count) { struct commit_list *cur, *previous; int prn, index, i; prn = get_prn(count); index = (count * prn / PRN_MODULO) * sqrti(prn) / sqrti(PRN_MODULO); cur = list; previous = NULL; for (i = 0; cur; cur = cur->next, i++) { if (i == index) { if (hashcmp(cur->item->object.sha1, current_bad_oid->hash)) return cur; if (previous) return previous; return list; } previous = cur; } return list; }
static void RunLEDFlow() { int8_t components[3]; ReadRawAccelerometerData(components); int32_t dx=components[0]-zero[0]; int32_t dy=components[1]-zero[1]; int32_t r=sqrti(dx*dx+dy*dy); dx=(dx<<12)/r; dy=(dy<<12)/r; x+=r*25; // x+=components[0]-zero[0]; // y+=components[1]-zero[1]; int leds=0; leds|=(((x+dx)>>14)&1)<<1; leds|=(((x-dx)>>14)&1)<<3; leds|=(((x+dy)>>14)&1)<<0; leds|=(((x-dy)>>14)&1)<<2; SetLEDs(leds); }
int main() { InitializeSystem(); SysTick_Config(HCLKFrequency()/100); InitializeLEDs(); SetLEDs(0x01); uint8_t *framebuffer1=(uint8_t *)0x20000000; uint8_t *framebuffer2=(uint8_t *)0x20010000; SetLEDs(0x03); memset(framebuffer1,0,320*200); memset(framebuffer2,0,320*200); SetLEDs(0x07); IntializeVGAScreenMode320x200(framebuffer1); #define NumberOfStars 1050 static struct Star { int x,y,dx,f; } stars[NumberOfStars]; for(int i=0;i<NumberOfStars;i++) { stars[i].x=(RandomInteger()%352-16)<<12; stars[i].y=RandomInteger()%200; int z=sqrti((NumberOfStars-1-i)*NumberOfStars)*1000/NumberOfStars; stars[i].dx=6000*1200/(z+200); stars[i].f=(6-(z*7)/1000)+(RandomInteger()%6)*7; } const RLEBitmap *sprites[7*6]={ &Star1_0,&Star2_0,&Star3_0,&Star4_0,&Star5_0,&Star6_0,&Star7_0, &Star1_1,&Star2_1,&Star3_1,&Star4_1,&Star5_1,&Star6_1,&Star7_1, &Star1_2,&Star2_2,&Star3_2,&Star4_2,&Star5_2,&Star6_2,&Star7_2, &Star1_3,&Star2_3,&Star3_3,&Star4_3,&Star5_3,&Star6_3,&Star7_3, &Star1_4,&Star2_4,&Star3_4,&Star4_4,&Star5_4,&Star6_4,&Star7_4, &Star1_5,&Star2_5,&Star3_5,&Star4_5,&Star5_5,&Star6_5,&Star7_5, }; Bitmap frame1,frame2; InitializeBitmap(&frame1,320,200,320,framebuffer1); InitializeBitmap(&frame2,320,200,320,framebuffer2); int frame=0; while(1) { WaitVBL(); Bitmap *currframe; if(frame&1) { currframe=&frame2; SetFrameBuffer(framebuffer1); } else { currframe=&frame1; SetFrameBuffer(framebuffer2); } ClearBitmap(currframe); for(int i=0;i<NumberOfStars;i++) { DrawRLEBitmap(currframe,sprites[stars[i].f], (stars[i].x>>12)-16,stars[i].y-16); stars[i].x-=stars[i].dx; if(stars[i].x<=-16<<12) { stars[i].x=(320+16)<<12; stars[i].y=RandomInteger()%200; stars[i].f=(stars[i].f%7)+(RandomInteger()%6)*7; } } frame++; } }
static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable ) { // Get the filter mlt_filter filter = mlt_frame_pop_service( frame ); mlt_properties properties = MLT_FILTER_PROPERTIES( filter ); mlt_position position = mlt_filter_get_position( filter, frame ); mlt_position length = mlt_filter_get_length2( filter, frame ); // Get the image *format = mlt_image_yuv422; int error = mlt_frame_get_image( frame, image, format, width, height, 1 ); // Only process if we have no error and a valid colour space if ( error == 0 ) { // Get the charcoal scatter value int x_scatter = mlt_properties_anim_get_double( properties, "x_scatter", position, length ); int y_scatter = mlt_properties_anim_get_double( properties, "y_scatter", position, length ); float scale = mlt_properties_anim_get_double( properties, "scale" ,position, length); float mix = mlt_properties_anim_get_double( properties, "mix", position, length); int invert = mlt_properties_anim_get_int( properties, "invert", position, length); // We'll process pixel by pixel int x = 0; int y = 0; // We need to create a new frame as this effect modifies the input uint8_t *temp = mlt_pool_alloc( *width * *height * 2 ); uint8_t *p = temp; uint8_t *q = *image; // Calculations are carried out on a 3x3 matrix int matrix[ 3 ][ 3 ]; // Used to carry out the matrix calculations int sum1; int sum2; float sum; int val; // Loop for each row for ( y = 0; y < *height; y ++ ) { // Loop for each pixel for ( x = 0; x < *width; x ++ ) { // Populate the matrix matrix[ 0 ][ 0 ] = get_Y( *image, *width, *height, x - x_scatter, y - y_scatter ); matrix[ 0 ][ 1 ] = get_Y( *image, *width, *height, x , y - y_scatter ); matrix[ 0 ][ 2 ] = get_Y( *image, *width, *height, x + x_scatter, y - y_scatter ); matrix[ 1 ][ 0 ] = get_Y( *image, *width, *height, x - x_scatter, y ); matrix[ 1 ][ 2 ] = get_Y( *image, *width, *height, x + x_scatter, y ); matrix[ 2 ][ 0 ] = get_Y( *image, *width, *height, x - x_scatter, y + y_scatter ); matrix[ 2 ][ 1 ] = get_Y( *image, *width, *height, x , y + y_scatter ); matrix[ 2 ][ 2 ] = get_Y( *image, *width, *height, x + x_scatter, y + y_scatter ); // Do calculations sum1 = (matrix[2][0] - matrix[0][0]) + ( (matrix[2][1] - matrix[0][1]) << 1 ) + (matrix[2][2] - matrix[2][0]); sum2 = (matrix[0][2] - matrix[0][0]) + ( (matrix[1][2] - matrix[1][0]) << 1 ) + (matrix[2][2] - matrix[2][0]); sum = scale * sqrti( sum1 * sum1 + sum2 * sum2 ); // Assign value *p ++ = !invert ? ( sum >= 16 && sum <= 235 ? 251 - sum : sum < 16 ? 235 : 16 ) : ( sum >= 16 && sum <= 235 ? sum : sum < 16 ? 16 : 235 ); q ++; val = 128 + mix * ( *q ++ - 128 ); val = val < 16 ? 16 : val > 240 ? 240 : val; *p ++ = val; } } // Return the created image *image = temp; // Store new and destroy old mlt_frame_set_image( frame, *image, *width * *height * 2, mlt_pool_release ); } return error; }
inline int32_t vector3d_modulus(const int32_t *v){ return sqrti(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); }