/* Test the example of a train moving along a 1-d track */ void test_train() { KalmanFilter f = alloc_filter(2, 1); /* The train state is a 2d vector containing position and velocity. Velocity is measured in position units per timestep units. */ set_matrix(f.state_transition, 1.0, 1.0, 0.0, 1.0); /* We only observe position */ set_matrix(f.observation_model, 1.0, 0.0); /* The covariance matrices are blind guesses */ set_identity_matrix(f.process_noise_covariance); set_identity_matrix(f.observation_noise_covariance); /* Our knowledge of the start position is incorrect and unconfident */ double deviation = 1000.0; set_matrix(f.state_estimate, 10 * deviation); set_identity_matrix(f.estimate_covariance); scale_matrix(f.estimate_covariance, deviation * deviation); /* Test with time steps of the position gradually increasing */ for (int i = 0; i < 10; ++i) { set_matrix(f.observation, (double) i); update(f); } /* Our prediction should be close to (10, 1) */ printf("estimated position: %f\n", f.state_estimate.data[0][0]); printf("estimated velocity: %f\n", f.state_estimate.data[1][0]); free_filter(f); }
int main() { int *m; int size; int i; while (1) { printf("Input an integer as matrix size: "); scanf("%d", &size); m = malloc(size * 4); set_matrix(m, size, 0, 1); printf("\n-----------------------------------\n"); printf("Spiral matrix (%d cols, %d rows):\n", size, size); for (i = 0; i < size * size; i++) { if (i % size == 0) printf("\n"); printf("%3d ", m[i]); } printf("\n-----------------------------------\n\n"); free(m); m = NULL; } return 0; }
static void Benchmark( float xdiff, float ydiff ) { int startTime, endTime; int draws; double seconds, fps, triPerSecond; printf("Benchmarking...\n"); draws = 0; startTime = glutGet(GLUT_ELAPSED_TIME); xrot = 0.0; do { xrot += xdiff; yrot += ydiff; set_matrix(); Display(); draws++; endTime = glutGet(GLUT_ELAPSED_TIME); } while (endTime - startTime < 5000); /* 5 seconds */ /* Results */ seconds = (double) (endTime - startTime) / 1000.0; triPerSecond = (numverts - 2) * draws / seconds; fps = draws / seconds; printf("Result: triangles/sec: %g fps: %g\n", triPerSecond, fps); }
bool RendCurve::render(unsigned long time) { if(!curve) return false; set_matrix(XFORM_WORLD, get_prs(time).get_xform_matrix()); mat.set_glmaterial(); if(mat.tex[TEXTYPE_DIFFUSE]) { set_texture(0, mat.tex[TEXTYPE_DIFFUSE]); enable_texture_unit(0); set_texture_coord_index(0, 0); set_texture_unit_color(0, TOP_MODULATE, TARG_TEXTURE, TARG_PREV); set_texture_unit_alpha(0, TOP_MODULATE, TARG_TEXTURE, TARG_PREV); } set_alpha_blending(true); set_zwrite(false); set_blend_func(src_blend, dst_blend); int line_count = curve->get_segment_count() * detail; scalar_t dx = 1.0 / (scalar_t)line_count; scalar_t t = dx; Vector3 prev_pos = (*curve)(0.0); for(int i=1; i<line_count; i++) { Vector3 pos = (*curve)(t); draw_line(Vertex(prev_pos, 0.0), Vertex(pos, 1.0), width, width); prev_pos = pos; t += dx; } set_alpha_blending(false); set_zwrite(true); disable_texture_unit(0); return true; }
main(int argc, char *argv[]){ unsigned long i; div_t results; int c, j; /* Initialize the array */ for(i=0;i<MAXSIZE/16;i++) { z[i]='\xFF'; } /* For loop is the main loop that controls the function of the program */ for(i=3;i<MAXSIZE; i+=2) if (is_prime(i)) set_matrix(i); /* Done, flush and close */ for (i=0; i<MAXSIZE/16;i++) putc(z[i], stdout); exit (0); }
main(int argc, char *argv[]){ unsigned long i; unsigned long max_num_to_check; div_t results; int c, j; /* Initialize the array */ for(i=0;i<MAXSIZE/16;i++) { z[i]='\xFF'; } /* For loop is the main loop that controls the function of the program */ max_num_to_check = sqrt(MAXSIZE)+1; for(i=3;i<max_num_to_check; i+=2) if (is_prime(i)){ set_matrix(i); printf("%d\n", i); } // for(i=1;i<10000; i++) // factors(i); /* Done, flush and close */ /* for (i=0; i<MAXSIZE/16;i++) putc(z[i], stdout); */ exit (0); }
void Matrix2DTranspose(Matrix2D *pResult, Matrix2D *pMtx) { int i, j; Matrix2D temp; for(i = 0; i < 3; ++i) for(j = 0; j < 3; ++j) temp.m[i][j] = pMtx->m[j][i]; set_matrix(pResult, &temp); }
GPSFilter::GPSFilter(double noise){ //KalmanFilter alloc_filter_velocity2d(double noise) { /* The state model has four dimensions: x, y, x', y' Each time step we can only observe position, not velocity, so the observation vector has only two dimensions. */ f = alloc_filter(4, 2); /* Assuming the axes are rectilinear does not work well at the poles, but it has the bonus that we don't need to convert between lat/long and more rectangular coordinates. The slight inaccuracy of our physics model is not too important. */ double v2p = 0.001; set_identity_matrix(f.state_transition); set_seconds_per_timestep(1.0); /* We observe (x, y) in each time step */ set_matrix(f.observation_model, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0); /* Noise in the world. */ double pos = 0.000001; set_matrix(f.process_noise_covariance, pos, 0.0, 0.0, 0.0, 0.0, pos, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0); /* Noise in our observation */ set_matrix(f.observation_noise_covariance, pos * noise, 0.0, 0.0, pos * noise); /* The start position is totally unknown, so give a high variance */ set_matrix(f.state_estimate, 0.0, 0.0, 0.0, 0.0); set_identity_matrix(f.estimate_covariance); double trillion = 1000.0 * 1000.0 * 1000.0 * 1000.0; scale_matrix(f.estimate_covariance, trillion); //return f; }
void AudioProcessor::set_state(const AudioProcessorState *state) { if (!state) return; // Channel order set_input_order(state->input_order); set_output_order(state->output_order); // Master gain set_master(state->master); // AGC set_auto_gain(state->auto_gain); set_normalize(state->normalize); set_attack(state->attack); set_release(state->release); // DRC set_drc(state->drc); set_drc_power(state->drc_power); // Matrix // (!) Auto matrix option must be set before setting the matrix // because when auto matrix is on, mixer rejects the new matrix. set_auto_matrix(state->auto_matrix); set_matrix(state->matrix); // Automatrix options set_normalize_matrix(state->normalize_matrix); set_voice_control(state->voice_control); set_expand_stereo(state->expand_stereo); // Automatrix levels set_clev(state->clev); set_slev(state->slev); set_lfelev(state->lfelev); // Input/output gains set_input_gains(state->input_gains); set_output_gains(state->output_gains); // SRC set_src_quality(state->src_quality); set_src_att(state->src_att); // Eqalizer set_eq(state->eq); if (state->eq_master_bands) set_eq_bands(CH_NONE, state->eq_master_bands, state->eq_master_nbands); for (int ch = 0; ch < CH_NAMES; ch++) if (state->eq_bands[ch]) set_eq_bands(ch, state->eq_bands[ch], state->eq_nbands[ch]); // Bass redirection set_bass_redir(state->bass_redir); set_bass_freq(state->bass_freq); set_bass_channels(state->bass_channels); // Delays set_delay(state->delay); set_delay_units(state->delay_units); set_delays(state->delays); // Dithering set_dithering(state->dithering); }
void Matrix2DConcat(Matrix2D *pResult, Matrix2D *pMtx0, Matrix2D *pMtx1) { Matrix2D hold = {0}; int i,j; for(i = 0; i < 3; ++i) for(j = 0; j < 3; ++j) hold.m[i][j] = (pMtx0->m[i][0] * pMtx1->m[0][j]) + (pMtx0->m[i][1] * pMtx1->m[1][j]) + (pMtx0->m[i][2] * pMtx1->m[2][j]); set_matrix(pResult, &hold); }
void draw_objects(simulation_t *simulation, buffer_t *buffer, shader_t *shader, GLfloat camera[16]) { GLfloat modelview[16]; for (unsigned int i = 0; i < simulation->count; i++) { particle_t particle = simulation->src_buf[i]; vec3f p = particle.position; load_identity(modelview); translate(modelview, p.x, p.y, p.z); scale(modelview, particle.radius, particle.radius, particle.radius); multiply_matrix(modelview, camera, modelview); set_matrix(shader, MODELVIEW_MATRIX, modelview); glColor3f(particle.r, particle.g, particle.b); draw_vbo(buffer); } }
main(int argc, char *argv[]){ unsigned long i; div_t results; int c, j; /* Initialize the file, quit if we cannot write all the way to the end Because this takes so long on huge databases, I am going to initialize the first several primes as I go along. I mean, everyone knows that 2, 3, 5, and 7 are prime... */ z[0]=0; z[1]=0; z[2]=1; z[3]=1; z[4]=0; for(i=5;i<MAXSIZE;i++,i++) { c=1; for (j=0; j<NUMPRIMES; j++) { results=div(i, known_primes[j]); if (results.rem<1){ if (i>known_primes[j]) c=0; } } z[i]=c; z[i+1]=0; } for (j=0; j<NUMPRIMES; j++) printf("%d\n", known_primes[j]); /* For loop is the main loop that controls the function of the program */ for(i=31;i<MAXSIZE; i++,i++) if (is_prime(i)) set_matrix(i); /* Done, flush and close */ exit (0); }
void sum(int n1, int m1, int n2, int m2) { if (n1 != n2 || m1 != m2) { printf("Impossimatrix to add"); return ; } new_matrix(n1, m1, ptr_out3); int N = n1, M = m1; for (int i = 0; i < n1; ++i) { for (int j = 0; j < m1; ++j) { double x = get_matrix(n1, m1, i, j, ptr_out1); x += get_matrix(n2, m2, i, j, ptr_out2); set_matrix(N, M, i, j, x); } } }
int gretl_array_append_matrix (gretl_array *A, gretl_matrix *m, int copy) { int err = 0; if (A == NULL) { err = E_DATA; } else if (A->type != GRETL_TYPE_MATRICES) { err = E_TYPES; } else { err = array_extend_content(A, 1); if (!err) { err = set_matrix(A, A->n - 1, m, copy); } } return err; }
void prod(int n1, int m1, int n2, int m2) { if (n2 != m1) { printf("Impossimatrix to multiply"); return ; } new_matrix(n1, m2, ptr_out3); int N = n1; int M = m2; //c[i][j] = a[i][k] * b[k][j] for (int i = 0; i < n1; ++i) { for (int j = 0; j < m2; ++j) { double x = 0; for (int k = 0; k < m1; ++k) { x += get_matrix(n1, m1, i, k, ptr_out1) * get_matrix(n2, m2, k, j, ptr_out2) ; } set_matrix(N, M, i, j, x); } } }
int gretl_array_set_matrix (gretl_array *A, int i, gretl_matrix *m, int copy) { int err = 0; if (A == NULL) { err = E_DATA; } else if (A->type != GRETL_TYPE_MATRICES) { err = E_TYPES; } else if (i < 0 || i >= A->n) { gretl_errmsg_sprintf(_("Index value %d is out of bounds"), i+1); err = E_DATA; } else { gretl_matrix_free(A->data[i]); err = set_matrix(A, i, m, copy); } return err; }
void on_resize(int width, int height) { int x0, y0; float* m; x0 = 0; y0 = 0; glViewport(x0, y0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); // gluPerspective( 80.0, 1.0, 0.1, 10.0 ); m = malloc(16*sizeof(float)); set_matrix( m, 1.60744584, 0.01951438, 0.05250012, 0., 0., 2.40880443, 0.07234515, 0. , 0., 0., -1.00020002, -0.20002, 0., 0., -1., 0.); glLoadMatrixf(m); free(m); }
void set_matrix(int *m, int size, int offset, int num) { int origin = offset + size * offset; int partical_size = size - offset * 2; int i, j; if (partical_size == 0) return; // 0x0 else if (partical_size == 1) { // 1x1 m[origin] = num; return; } for (j = 0; j < partical_size - 1; j++) m[origin + j * size] = num++; for (i = 0; i < partical_size - 1; i++) m[origin + i + (partical_size - 1) * size] = num++; for (j = partical_size - 1; j > 0; j--) m[origin + partical_size - 1 + j * size] = num++; for (i = partical_size - 1; i > 0; i--) m[origin + i] = num++; set_matrix(m, size, offset + 1, num); }
unsigned int remove_not_factorized( unsigned int** exponents, mpz_t* reduced_q_a, mpz_t* q_a, unsigned int howmany, unsigned int primes_num ) { unsigned int i; unsigned int j; unsigned int k = 0; for(i = 0; i < howmany; ++i) { if(mpz_cmp_ui(reduced_q_a[i], 1) == 0) { mpz_set(q_a[k], q_a[i]); for(j = 0; j < primes_num; ++j) set_matrix(exponents, k, j, get_matrix(exponents, i, j)); ++k; } } return k; }
static void SpecialKey( int key, int x, int y ) { (void) x; (void) y; switch (key) { case GLUT_KEY_LEFT: yrot -= 15.0; break; case GLUT_KEY_RIGHT: yrot += 15.0; break; case GLUT_KEY_UP: xrot += 15.0; break; case GLUT_KEY_DOWN: xrot -= 15.0; break; default: return; } set_matrix(); glutPostRedisplay(); }
/***********************************************************************//** * @brief Set parameters and tests **************************************************************************/ void TestGMatrixSparse::set(void) { // Set test name name("GMatrixSparse"); // Append tests append(static_cast<pfunction>(&TestGMatrixSparse::alloc_matrix), "Test matrix allocation"); append(static_cast<pfunction>(&TestGMatrixSparse::assign_values), "Test value assignment"); append(static_cast<pfunction>(&TestGMatrixSparse::copy_matrix), "Test matrix copying"); append(static_cast<pfunction>(&TestGMatrixSparse::matrix_operations), "Test matrix operations"); append(static_cast<pfunction>(&TestGMatrixSparse::matrix_arithmetics), "Test matrix arithmetics"); append(static_cast<pfunction>(&TestGMatrixSparse::matrix_functions), "Test matrix functions"); append(static_cast<pfunction>(&TestGMatrixSparse::matrix_compare), "Test matrix comparisons"); append(static_cast<pfunction>(&TestGMatrixSparse::matrix_cholesky), "Test matrix Cholesky decomposition"); append(static_cast<pfunction>(&TestGMatrixSparse::matrix_print), "Test matrix printing"); // Set members m_test = set_matrix(); v_test = set_vector(); m_bigger = GMatrixSparse(g_rows+1, g_cols+1); // Return return; }
/************************************************************************** Main ***************************************************************************/ int main (void) { uint8_t color = UNIQUE_COLORS -1; uint8_t row = 0; uint8_t col = 0; uint8_t quad = 0; uint8_t binary_cnt = 0; uint8_t wdt_cnt = 0; uint8_t update_cnt = 0; initialize_AVR(); SET_FLAG(SET_LEDS); chase_sequence = SMILEY; DISABLE_SERVOS(); quad_flags = 0xFF; turn_off_matrices(); // Turn On TWI TWI_RESET_WITH_ACK(); /********************************************** * MAIN LOOP * - Handle Chase Sequences **********************************************/ for(;;) { //------------------------- // Handle Color Loops //------------------------- if (FLAG_IS_SET(INCREMENT_COLOR)) { if (++color == UNIQUE_COLORS) color = 1; CLEAR_FLAG(INCREMENT_COLOR); } else if (FLAG_IS_SET(DECREMENT_COLOR)) { if (--color == 0) color = UNIQUE_COLORS -1; CLEAR_FLAG(DECREMENT_COLOR); } //------------------------- // Reset Chase Sequence //------------------------- if (FLAG_IS_SET(RESET_CHASE)) { wdt_cnt = 0; chase_sequence = LOOP_QUAD; CLEAR_FLAG(RESET_CHASE); CLEAR_FLAG(PASSIVE_MODE); ENABLE_SERVOS(); } //------------------------- // Handle Chase Sequences //------------------------- switch (chase_sequence) { //------------------------- // Constant On at the last color //------------------------- case ALL_CONSTANT: break; //------------------------- // Loop through all colors //------------------------- case LOOP_ALL: SET_FLAG(DECREMENT_COLOR); set_matrix(0, color); set_matrix(1, color); _delay_ms(100); break; //------------------------- // Color wheel - one color transistion per revolution //------------------------- case QUAD_WHEEL: if (quad == 0) { set_quadrant(0, 3, COL_BLACK); set_quadrant(1, 3, COL_BLACK); } else { set_quadrant(0, quad-1, COL_BLACK); set_quadrant(1, quad-1, COL_BLACK); } set_quadrant(0, quad, color); set_quadrant(1, quad, color); if (++quad == QUADS) { SET_FLAG(DECREMENT_COLOR); quad = 0; } _delay_ms(50); break; //------------------------- // Color wheel - change colors with quadrants //------------------------- case QUAD_WHEEL2: SET_FLAG(DECREMENT_COLOR); if (quad == 0) { set_quadrant(0, 3, COL_BLACK); set_quadrant(1, 3, COL_BLACK); } else { set_quadrant(0, quad-1, COL_BLACK); set_quadrant(1, quad-1, COL_BLACK); } set_quadrant(0, quad, color); set_quadrant(1, quad, color); if (++quad == QUADS) { quad = 0; } _delay_ms(50); break; //------------------------- // Loop through all colors in Quadrant(s) //------------------------- case LOOP_QUAD: SET_FLAG(DECREMENT_COLOR); set_quadrants(color); _delay_ms(100); break; //------------------------- // Binary Counter - by Columns //------------------------- case BINARY_COLS: for (col = 0; col < COLUMNS; ++col) { if (binary_cnt & _BV(col)) set_column(0, col, COL_BLUE); else set_column(0, col, COL_BLACK); } ++binary_cnt; _delay_ms(250); break; //------------------------- // Binary Counter - by Row //------------------------- case BINARY_ROWS: for (row = 0; row < ROWS; ++row) { if (binary_cnt & _BV(row)) set_row(0, row, COL_RED); else set_row(0, row, COL_BLACK); } ++binary_cnt; _delay_ms(250); break; //------------------------- // Display all colors //------------------------- case ALL_COLORS: if (FLAG_IS_SET(SET_LEDS)) { for (col = 0; col < COLUMNS; ++col) { for (row = 0; row < ROWS; ++row) { if (color < UNIQUE_COLORS) { set_led(0, col, row, color); ++color; } else set_led(0, col, row, COL_BLACK); } } CLEAR_FLAG(SET_LEDS); } break; //------------------------- // Smiley Faces //------------------------- case SMILEY: if (FLAG_IS_SET(SET_LEDS)) { turn_off_matrices(); // Border #define FACE_COLOR COL_OLIVE set_row(0, 0, FACE_COLOR); set_row(0, 7, FACE_COLOR); set_column(0, 0, FACE_COLOR); set_column(0, 7, FACE_COLOR); set_row(1, 0, FACE_COLOR); set_row(1, 7, FACE_COLOR); set_column(1, 0, FACE_COLOR); set_column(1, 7, FACE_COLOR); // Eyes set_led(0, 1, 1, COL_WHITE); set_led(0, 1, 2, COL_WHITE); set_led(0, 2, 1, COL_WHITE); set_led(0, 2, 2, COL_BLUE); set_led(0, 1, 5, COL_WHITE); set_led(0, 1, 6, COL_WHITE); set_led(0, 2, 5, COL_WHITE); set_led(0, 2, 6, COL_BLUE); set_led(1, 1, 1, COL_WHITE); set_led(1, 1, 2, COL_WHITE); set_led(1, 2, 2, COL_WHITE); set_led(1, 2, 1, COL_GREEN); set_led(1, 1, 5, COL_WHITE); set_led(1, 1, 6, COL_WHITE); set_led(1, 2, 6, COL_WHITE); set_led(1, 2, 5, COL_GREEN); // Nose set_led(0, 3, 4, FACE_COLOR); set_led(0, 4, 3, FACE_COLOR); set_led(0, 4, 4, FACE_COLOR); set_led(1, 3, 3, FACE_COLOR); set_led(1, 4, 3, FACE_COLOR); set_led(1, 4, 4, FACE_COLOR); // Mouth set_led(0, 5, 1, COL_CORAL); set_led(0, 6, 2, COL_CORAL); set_led(0, 6, 3, COL_CORAL); set_led(0, 6, 4, COL_CORAL); set_led(0, 6, 5, COL_CORAL); set_led(0, 5, 6, COL_CORAL); set_led(1, 5, 1, COL_CORAL); set_led(1, 6, 2, COL_CORAL); set_led(1, 6, 3, COL_CORAL); set_led(1, 6, 4, COL_CORAL); set_led(1, 6, 5, COL_CORAL); set_led(1, 5, 6, COL_CORAL); CLEAR_FLAG(SET_LEDS); SET_FLAG(UPDATE_LEDS); } // Look back and forth if (FLAG_IS_SET(UPDATE_LEDS)) { set_led(0, 2, 2, COL_WHITE); set_led(0, 2, 1, COL_BLUE); set_led(0, 2, 6, COL_WHITE); set_led(0, 2, 5, COL_BLUE); set_led(1, 2, 1, COL_WHITE); set_led(1, 2, 2, COL_GREEN); set_led(1, 2, 5, COL_WHITE); set_led(1, 2, 6, COL_GREEN); _delay_ms(200); set_led(0, 2, 1, COL_WHITE); set_led(0, 2, 2, COL_BLUE); set_led(0, 2, 5, COL_WHITE); set_led(0, 2, 6, COL_BLUE); set_led(1, 2, 2, COL_WHITE); set_led(1, 2, 1, COL_GREEN); set_led(1, 2, 6, COL_WHITE); set_led(1, 2, 5, COL_GREEN); update_cnt = SMILEY_EYE_DELAY; CLEAR_FLAG(UPDATE_LEDS); } break; //------------------------- // Set matrix to white //------------------------- case ALL_WHITE: if (FLAG_IS_SET(SET_LEDS)) { set_matrix(0, COL_WHITE); CLEAR_FLAG(SET_LEDS); } break; //------------------------- // Turn off all LEDs //------------------------- case ALL_OFF: default: if (FLAG_IS_SET(SET_LEDS)) { turn_off_matrices(); CLEAR_FLAG(SET_LEDS); } break; //------------------------- // Test - Test corner LEDs //------------------------- case TEST_CORNERS: set_led(0, 7, 0, COL_BLACK); set_led(0, 0, 0, COL_RED); set_led(0, 4, 4, COL_RED); set_led(1, 7, 7, COL_BLACK); set_led(1, 0, 7, COL_RED); set_led(1, 4, 3, COL_RED); _delay_ms(200); set_led(0, 0, 0, COL_BLACK); set_led(0, 0, 7, COL_BLUE); set_led(0, 4, 4, COL_BLUE); set_led(1, 0, 7, COL_BLACK); set_led(1, 0, 0, COL_BLUE); set_led(1, 4, 3, COL_BLUE); _delay_ms(200); set_led(0, 0, 7, COL_BLACK); set_led(0, 7, 7, COL_YELLOW); set_led(0, 4, 4, COL_YELLOW); set_led(1, 0, 0, COL_BLACK); set_led(1, 7, 0, COL_YELLOW); set_led(1, 4, 3, COL_YELLOW); _delay_ms(200); set_led(0, 7, 7, COL_BLACK); set_led(0, 7, 0, COL_GREEN); set_led(0, 4, 4, COL_GREEN); set_led(1, 7, 0, COL_BLACK); set_led(1, 7, 7, COL_GREEN); set_led(1, 4, 3, COL_GREEN); _delay_ms(200); break; } //------------------------- // Update Timer - 10ms increments //------------------------- if (update_cnt > 0) { _delay_ms(10); if (--update_cnt == 0) { SET_FLAG(UPDATE_LEDS); } } //------------------------- // WatchDog Timer //------------------------- if (wdt_cnt < WDT_MAX) { if (++wdt_cnt == WDT_MAX) { DISABLE_SERVOS(); SET_FLAG(SET_LEDS); SET_FLAG(PASSIVE_MODE); chase_sequence = SMILEY; } } } // End of Main Loop } // End of Main
void app_bitman() { char data[16]; decode_left2right("0098e41f1fe49800", data); decode_left2right("0884e43e3ee48408", data + 8); const struct Frame fr[BITMAN_MAX_PTN] = { { { 0x08, 0x84, 0xE4, 0x1E, 0x1E, 0xE4, 0x84, 0x08 }, 400 } , { { 0x00, 0x98, 0xE4, 0x1F, 0x1F, 0xE4, 0x98, 0x00 }, 600 } , { { 0x08, 0x84, 0xE4, 0x1E, 0x1E, 0xE4, 0x84, 0x08 }, 600 } , { { 0x00, 0x98, 0xE4, 0x1F, 0x1F, 0xE4, 0x98, 0x00 }, 600 } , { { 0x00, 0x84, 0xE4, 0x14, 0x1E, 0xEE, 0x84, 0x08 }, 400 } , { { 0x00, 0x42, 0x72, 0x14, 0x1E, 0xFE, 0x84, 0x18 }, 200 } , { { 0x06, 0x04, 0x04, 0x09, 0x1E, 0xEC, 0x8E, 0x36 }, 200 } , { { 0x06, 0x64, 0x24, 0x3D, 0x0D, 0x7E, 0x0C, 0x0C }, 200 } , { { 0x66, 0x24, 0x24, 0x18, 0x99, 0x7E, 0x18, 0x00 }, 400 } , { { 0x66, 0x24, 0x24, 0x5A, 0x5A, 0x3C, 0x18, 0x18 }, 600 } , { { 0x66, 0x24, 0x24, 0x18, 0x99, 0x7E, 0x18, 0x00 }, 600 } , { { 0x66, 0x24, 0x24, 0x5A, 0x5A, 0x3C, 0x18, 0x18 }, 600 } , { { 0x66, 0x24, 0x24, 0x18, 0xB0, 0x7E, 0x30, 0x00 }, 400 } , { { 0x60, 0x26, 0x24, 0xBC, 0xB0, 0x78, 0x36, 0x00 }, 200 } , { { 0x60, 0x20, 0xA0, 0x90, 0x78, 0xF7, 0xD1, 0x08 }, 200 } , { { 0x00, 0x22, 0x2E, 0x28, 0xF8, 0xFF, 0x21, 0x18 }, 200 } , { { 0x10, 0x21, 0x27, 0x78, 0x78, 0x27, 0x21, 0x10 }, 400 } , { { 0x00, 0x19, 0x27, 0xF8, 0xF8, 0x27, 0x19, 0x00 }, 600 } , { { 0x10, 0x21, 0x27, 0x78, 0x78, 0x27, 0x21, 0x10 }, 600 } , { { 0x00, 0x19, 0x27, 0xF8, 0xF8, 0x27, 0x19, 0x00 }, 600 } , { { 0x10, 0x21, 0x77, 0x78, 0x28, 0x27, 0x21, 0x00 }, 400 } , { { 0x18, 0x21, 0x7F, 0x78, 0x28, 0x4E, 0x42, 0x00 }, 200 } , { { 0x6C, 0x71, 0x37, 0x78, 0x90, 0x20, 0x20, 0x60 }, 200 } , { { 0x30, 0x30, 0x7E, 0xB0, 0xBC, 0x24, 0x26, 0x60 }, 200 } , { { 0x00, 0x18, 0x7E, 0x99, 0x18, 0x24, 0x24, 0x66 }, 400 } , { { 0x18, 0x18, 0x3C, 0x5A, 0x5A, 0x24, 0x24, 0x66 }, 600 } , { { 0x00, 0x18, 0x7E, 0x99, 0x18, 0x24, 0x24, 0x66 }, 600 } , { { 0x18, 0x18, 0x3C, 0x5A, 0x5A, 0x24, 0x24, 0x66 }, 600 } , { { 0x00, 0x0C, 0x7E, 0x0D, 0x18, 0x24, 0x24, 0x66 }, 400 } , { { 0x00, 0x6C, 0x1E, 0x0D, 0x3D, 0x24, 0x64, 0x06 }, 200 } , { { 0x10, 0x8B, 0xEF, 0x1E, 0x09, 0x05, 0x04, 0x06 }, 200 } , { { 0x18, 0x84, 0xFF, 0x1F, 0x14, 0x74, 0x44, 0x00 }, 200 } }; // int ptn = 0; int exit_triger = 0; int exit_count = 0; int nframe = 0; // 実行中のフレーム番号 int cnt = 0; // RUN時のwaitカウンタ set_matrix(data); playMML("CDE2CDE2"); // Bitman_Title added by 後田浩さん Thanks ! for (;;) { FILL("191A3C5898242466"); // title FLUSH(); if (ux_btn()) break; } set_systick(0); for (;;) { WAIT(10); if (!ux_state()) break; if (get_systick() > 10000) return; } // end_of_Bitman_Title playMML("C16"); set_systick(0); set_matrix(fr[nframe].frame); for (;;) { WAIT(1); cnt++; if (cnt >= fr[nframe].waitms) { // 待ち時間を過ぎたら cnt = 0; playMML("<C16"); // 次に接続されているマトリクスに送るデータ xprintf("MATLED SHOW "); for (int j = 0 ; j < 8 ; j++) xprintf("%02X", fr[nframe].frame[j]); xprintf("\n"); // 次のフレームに切り替え nframe++; if (nframe == BITMAN_MAX_PTN || fr[nframe].waitms == 0) nframe = 0; // ループして最初から set_matrix(fr[nframe].frame); } if (ux_state()) { // ボタンが押されていたら if (exit_count == 1) return; if (exit_triger == get_systick()) exit_count++; if (exit_triger == 0) { playMML("C16"); exit_triger = get_systick(); no_sleep(); } } if (!ux_state()) { // ボタンが離されていたら exit_triger = 0; } if (get_systick() > 10000) set_systick(0); } }
void pdf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform) { internal_t*i = (internal_t*)dev->internal; int t,size=img->width*img->height; int has_alpha=0; for(t=0;t<size;t++) { if(img->data[t].a!=255) { has_alpha=1; break; } } double w = sqrt(matrix->m00*matrix->m00+matrix->m01*matrix->m01); double h = sqrt(matrix->m10*matrix->m10+matrix->m11*matrix->m11); double l1 = w*img->width; double l2 = h*img->height; double dpi_x = 72.0 / w; double dpi_y = 72.0 / h; double dpi = dpi_x>dpi_y?dpi_x:dpi_y; gfximage_t*rescaled_image = 0; if(i->config_maxdpi && dpi > i->config_maxdpi) { int newwidth = img->width*i->config_maxdpi/dpi; int newheight = img->height*i->config_maxdpi/dpi; rescaled_image = gfximage_rescale(img, newwidth, newheight); msg("<notice> Downscaling %dx%d image (dpi %f, %.0fx%.0f on page) to %dx%d (dpi %d)", img->width, img->height, dpi, l1, l2, newwidth, newheight, i->config_maxdpi); img = rescaled_image; } if(i->config_mindpi && dpi < i->config_mindpi && img->width>1 && img->height>1) { msg("<error> Found image of size %dx%d with dpi %f, minimum allowed dpi is %d", img->width, img->height, dpi, i->config_mindpi); exit(1); } char tempfile[128]; mktempname(tempfile, "jpg"); gfximage_save_jpeg(img, tempfile, 96); int imgid=-1; if(has_alpha) { char tempfile2[128]; mktempname(tempfile2, "jpg"); int t; int size = img->width*img->height; unsigned char*alpha = malloc(size); for(t=0;t<size;t++) { alpha[t] = img->data[t].a; } jpeg_save_gray(alpha, img->width, img->height, 97, tempfile2); free(alpha); int maskid = PDF_load_image(i->p, "jpeg", tempfile2, 0, "mask"); unlink(tempfile2); char masked[80]; if(maskid<0) { msg("<error> Couldn't process mask jpeg of size %dx%d: error code %d", img->width, img->height, maskid); return; } sprintf(masked, "masked %d", maskid); imgid = PDF_load_image(i->p, "jpeg", tempfile, 0, masked); } else { imgid = PDF_load_image(i->p, "jpeg", tempfile, 0, ""); } if(imgid<0) { msg("<error> Couldn't process jpeg of size %dx%d: error code %d, file %s", img->width, img->height, imgid, tempfile); return; } unlink(tempfile); char options[80]; set_matrix(i, matrix->m00, matrix->m01, matrix->m10, matrix->m11); /* an image's (0,0) is at the lower left corner */ double x=matrix->tx + i->config_xpad + matrix->m10*img->height; double y=matrix->ty + i->config_ypad + matrix->m11*img->height; double tx,ty; transform_back(i, x, y, &tx, &ty); PDF_place_image(i->p, imgid, tx, ty, 1.0); PDF_close_image(i->p, imgid); if(rescaled_image) gfximage_free(rescaled_image); }
unsigned int sieve( mpz_t n, unsigned int* factor_base, unsigned int base_dim, pair* solutions, unsigned int** exponents, mpz_t* As, unsigned int poly_val_num, unsigned int max_fact, unsigned int intervals ) { unsigned int i; unsigned int** expo2; init_matrix(&expo2, intervals, base_dim); word** is_used_expo2; init_matrix_l(&is_used_expo2, 1, (intervals / N_BITS) + 1); for(i = 0; i < ((intervals / N_BITS) + 1); ++i) { set_matrix_l(is_used_expo2, 0, i, 0); } mpz_t n_root; mpz_t intermed; mpz_init(n_root); mpz_init(intermed); mpz_sqrt(n_root, n); unsigned char go_on = 1; unsigned int fact_count = 0; unsigned int j, k; mpz_t* evaluated_poly; init_vector_mpz(&evaluated_poly, poly_val_num); word** is_used; init_matrix_l(&is_used, 1, (poly_val_num / N_BITS) + 1); for(i = 0; i < ((poly_val_num / N_BITS) + 1); ++i) { set_matrix_l(is_used, 0, i, 0); } max_fact += base_dim; // Trovo poly_val_num valori del polinomio (A + s)^2 - n, variando A for(i = 0; i < poly_val_num; ++i) { mpz_add_ui(intermed, n_root, i); mpz_mul(intermed, intermed, intermed); mpz_sub(evaluated_poly[i], intermed, n); mpz_add_ui(As[i], n_root, i); } // Per ogni primo nella base di fattori for(i = 0; i < base_dim && go_on; ++i) { // Provo tutte le possibili fattorizzazioni nella base di fattori for(j = solutions[i].sol1; j < poly_val_num && go_on; j += factor_base[i]) { // Divido e salvo l'esponente va bene while(mpz_divisible_ui_p(evaluated_poly[j], factor_base[i])) { // Se non sono mai stati usati gli esponenti if(get_k_i(is_used, 0, j) == 0) { for(k = 0; k < base_dim; ++k) set_matrix(exponents, j, k, 0); set_k_i(is_used, 0, j, 1); } set_matrix(exponents, j, i, get_matrix(exponents, j, i) + 1); // ++exponents[j][i]; mpz_divexact_ui(evaluated_poly[j], evaluated_poly[j], factor_base[i]); } if(mpz_cmp_ui(evaluated_poly[j], 1) == 0) { ++fact_count; if(fact_count >= max_fact) { go_on = 0; } } } // Faccio la stessa cosa con entrambe le soluzioni, a meno che non stia usando 2 if(factor_base[i] != 2) { for(j = solutions[i].sol2; j < poly_val_num && go_on; j += factor_base[i]) { while(mpz_divisible_ui_p(evaluated_poly[j], factor_base[i])) { // Se non sono mai stati usati gli esponenti if(get_k_i(is_used, 0, j) == 0) { for(k = 0; k < base_dim; ++k) set_matrix(exponents, j, k, 0); set_k_i(is_used, 0, j, 1); } set_matrix(exponents, j, i, get_matrix(exponents, j, i) + 1); // ++exponents[j][i]; mpz_divexact_ui(evaluated_poly[j], evaluated_poly[j], factor_base[i]); } if(mpz_cmp_ui(evaluated_poly[j], 1) == 0) { ++fact_count; if(fact_count >= max_fact) { go_on = 0; } } } } } mpz_clear(n_root); mpz_clear(intermed); remove_not_factorized(exponents, evaluated_poly, As, poly_val_num, base_dim); // finalize_vector_mpz(&evaluated_poly, poly_val_num); // Si noti che questa istruzione apparentemente innocua porta all'uscita di demoni dal naso del programmatore return fact_count; }
static void Key( unsigned char key, int x, int y ) { (void) x; (void) y; switch (key) { case 27: exit(0); case 'f': ModeMenu((state ^ FOG_MASK) & FOG_MASK); break; case 's': ModeMenu((state ^ SHADE_MASK) & SHADE_MASK); break; case 't': ModeMenu((state ^ STIPPLE_MASK) & STIPPLE_MASK); break; case 'l': ModeMenu((state ^ LIGHT_MASK) & (LIT|UNLIT)); break; case 'm': ModeMenu((state ^ MATERIAL_MASK) & MATERIAL_MASK); break; case 'c': ModeMenu((state ^ CLIP_MASK) & CLIP_MASK); break; case 'v': ModeMenu((LOCKED|IMMEDIATE|DRAW_ELTS|TRIANGLES) & allowed); break; case 'V': ModeMenu(UNLOCKED|IMMEDIATE|GLVERTEX|STRIPS); break; case 'b': Benchmark(5.0, 0); break; case 'B': Benchmark(0, 5.0); break; case 'i': dist += .25; set_matrix(); glutPostRedisplay(); break; case 'I': dist -= .25; set_matrix(); glutPostRedisplay(); break; case '-': case '_': plane[3] += 2.0; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClipPlane(GL_CLIP_PLANE0, plane); set_matrix(); glutPostRedisplay(); break; case '+': case '=': plane[3] -= 2.0; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClipPlane(GL_CLIP_PLANE0, plane); set_matrix(); glutPostRedisplay(); break; case ' ': Init(0,0); break; } }
static void Init(int argc, char *argv[]) { GLfloat fogColor[4] = {0.5,1.0,0.5,1.0}; xrot = 0; yrot = 0; dist = -6; plane[0] = 1.0; plane[1] = 0.0; plane[2] = -1.0; plane[3] = 0.0; glClearColor(0.0, 0.0, 1.0, 0.0); glEnable( GL_DEPTH_TEST ); glEnable( GL_VERTEX_ARRAY_EXT ); glEnable( GL_NORMAL_ARRAY_EXT ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum( -1.0, 1.0, -1.0, 1.0, 5, 25 ); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClipPlane(GL_CLIP_PLANE0, plane); InitMaterials(); set_matrix(); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); /* Green fog is easy to see */ glFogi(GL_FOG_MODE,GL_EXP2); glFogfv(GL_FOG_COLOR,fogColor); glFogf(GL_FOG_DENSITY,0.15); glHint(GL_FOG_HINT,GL_DONT_CARE); { static int firsttime = 1; if (firsttime) { firsttime = 0; compactify_arrays(); expand_arrays(); make_tri_indices(); if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) { printf("Error: couldn't load texture image\n"); exit(1); } } } ModeMenu(SHADE_SMOOTH| LIT| POINT_FILTER| NO_USER_CLIP| NO_MATERIALS| NO_FOG| NO_STIPPLE| IMMEDIATE| STRIPS| UNLOCKED| GLVERTEX); if (PrintInfo) { printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); } }
void pdf_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix) { internal_t*i = (internal_t*)dev->internal; if(!font) return; gfxglyph_t*glyph = &font->glyphs[glyphnr]; char as_shape = 0; if(!type3 && !ttf) {msg("<warning> No type3 enabled. Drawing char %d as shape", glyphnr);as_shape=1;} if(glyphnr>256-32) {msg("<warning> Drawing char %d as shape (not < 224)", glyphnr);as_shape=1;} if(as_shape) { reset_matrix(i); PDF_setrgbcolor_fill(i->p, color->r/255.0, color->g/255.0, color->b/255.0); gfxline_t*line2 = gfxline_clone(glyph->line); gfxline_transform(line2, matrix); if(mkline(line2, i->p, i->config_xpad, i->config_ypad, 1.0, 1)) { PDF_fill(i->p); } gfxline_free(line2); } else { assert(gfxfontlist_hasfont(i->fontlist, font)); int fontid = (int)(ptroff_t)gfxfontlist_getuserdata(i->fontlist, font->id); gfxmatrix_t m = *matrix; m.m00*=64; m.m01*=64; m.m10*=64; m.m11*=64; if(ttf) { m.m10 = -m.m10; m.m11 = -m.m11; } if(!(fabs(m.m00 - i->m00) < 1e-6 && fabs(m.m01 - i->m01) < 1e-6 && fabs(m.m10 - i->m10) < 1e-6 && fabs(m.m11 - i->m11) < 1e-6)) { set_matrix(i, m.m00, m.m01, m.m10, m.m11); } double tx, ty; transform_back(i, m.tx+i->config_xpad, m.ty+i->config_ypad, &tx, &ty); PDF_setfont(i->p, fontid, ttf?16.0:1.0); PDF_setrgbcolor_fill(i->p, color->r/255.0, color->g/255.0, color->b/255.0); char name[32]; sprintf(name, "%c", glyphnr+32); if(fabs(tx - i->lastx) > 0.001 || ty != i->lasty) { PDF_show_xy2(i->p, name, strlen(name), tx, ty); } else { PDF_show2(i->p, name, strlen(name)); } i->lastx = tx + glyph->advance; i->lasty = ty; } }
static void reset_matrix(internal_t*i) { set_matrix(i, 1.0, 0.0, 0.0, 1.0); }
static void draw_main(double x, double y, const char *string, struct rectangle *box) { #ifdef HAVE_FT2BUILD_H FT_Library library; FT_Face face; FT_Matrix matrix; /*FT_UInt glyph_index; */ FT_Vector pen; FT_Error ans; const char *filename; const char *encoding; int font_index; unsigned char *out; int outlen; /* get file name */ filename = font_get_freetype_name(); encoding = font_get_encoding(); font_index = font_get_index(); /* set freetype */ ans = FT_Init_FreeType(&library); if (ans) { /* DEBUG_LOG("Text3 error: ft init\n"); */ return; } ans = FT_New_Face(library, filename, font_index, &face); if (ans == FT_Err_Unknown_File_Format) { /* DEBUG_LOG("Text3 error: ft new face 1\n"); */ FT_Done_FreeType(library); return; } else if (ans) { /* DEBUG_LOG("Text3 error: ft new face 2\n"); */ FT_Done_FreeType(library); return; } /* ans = FT_Set_Pixel_Sizes(face,10,10); */ /* ans = FT_Set_Char_Size(face,text_size_x*64,text_size_y*64,0,0); */ /* ans = FT_Set_Char_Size(face,10*64,0,72,0); */ /* ans = FT_Set_Char_Size(face,text_size_x*64,text_size_y*64,72,72); */ ans = FT_Set_Char_Size(face, (int)(text_size_x * 64), (int)(text_size_y * 64), 100, 100); if (ans) { /* DEBUG_LOG("Text3 error: ft set size\n"); */ FT_Done_Face(face); FT_Done_FreeType(library); return; } /* init point */ pen.x = x * 64; /* pen.y = 0; */ pen.y = (screen_height - y) * 64; /* convert string to:shift-jis from:encoding */ outlen = convert_str(encoding, string, &out); /* set matrix */ set_matrix(&matrix); /* draw */ draw_text(face, &pen, &matrix, out, outlen, 0, box); /* release */ release_convert_str(out); /* FT_done */ FT_Done_Face(face); FT_Done_FreeType(library); #endif }