void sidewaves (int iterations, int delay) { float origin_x, origin_y, distance, height, ripple_interval; int x,y,i; fill(0x00); for (i=0;i<iterations;i++) { origin_x = 3.5+sin((float)i/500)*4; origin_y = 3.5+cos((float)i/500)*4; for (x=0;x<8;x++) { for (y=0;y<8;y++) { distance = distance2d(origin_x,origin_y,x,y)/9.899495*8; ripple_interval =2; height = 4+sin(distance/ripple_interval+(float) i/50)*3.6; setvoxel(x,y,(int) height); setvoxel(x,y,(int) height); } } delay_ms(delay); fill(0x00); } }
void effect_rotate_random_pixels (int iterations, int delay, int pixels) { vertex points[pixels]; vertex rotated[pixels]; float fy, fx, fz; int x,y,z; int i,p; float rot_x = 0; float rot_y = 0; float rot_z = 0; vertex cube_center = {3.5, 3.5, 3.5}; for (i=0; i<pixels; i++) { x = rand()%1200-200; y = rand()%1200-200; z = rand()%1200-200; fx = (float)x/100; fy = (float)y/100; fz = (float)z/100; points[i].x = fx; points[i].y = fy; points[i].z = fz; setvoxel((int)points[i].x, (int)points[i].y, (int)points[i].z); delay_ms(100); } delay_ms(10000); for (i=0; i<iterations; i++) { rot_x = (float)i/75; rot_y = (float)i/150; rot_z = (float)i/200; for (p=0; p<pixels; p++) { rotated[p] = point_rotate_around_point (points[p], cube_center, rot_x, rot_y, rot_z); } fill(0x00); for (p=0; p<pixels; p++) { setvoxel((int)rotated[p].x, (int)rotated[p].y, (int)rotated[p].z); } delay_ms(delay); } fill(0x00); }
// Display a sine wave running out from the center of the cube. void ripples (int iterations, int delay) { float origin_x, origin_y, distance, height, ripple_interval; int x,y,i; fill(0x00); for (i=0;i<iterations;i++) { for (x=0;x<8;x++) { for (y=0;y<8;y++) { distance = distance2d(3.5,3.5,x,y)/9.899495*8; //distance = distance2d(3.5,3.5,x,y); ripple_interval =1.3; height = 4+sin(distance/ripple_interval+(float) i/50)*4; setvoxel(x,y,(int) height); } } delay_ms(delay); fill(0x00); } }
// Alter the state of a voxel in the cube buffer // This function was made in order to make set and clr versions // of other functions without writing two almost identical functions void altervoxel(int x, int y, int z, int state) { if (state == 1) { setvoxel(x,y,z); } else { clrvoxel(x,y,z); } }
void send_char2(char *char_data) { int8_t l, byte_index; for(l = 7; l >= 0; l--) { for(byte_index = 4; byte_index >= 0; byte_index--) { if(char_data[byte_index] & (1 << (7 - l))) { setvoxel(2 + byte_index, 0, l); } else { clrvoxel(2 + byte_index, 0, l); } } } }
void spheremove (int iterations, int delay) { fill(0x00); float origin_x, origin_y, origin_z, distance, diameter; origin_x = 0; origin_y = 3.5; origin_z = 3.5; diameter = 3; int x, y, z, i; for (i=0; i<iterations; i++) { origin_x = 3.5+sin((float)i/50)*2.5; origin_y = 3.5+cos((float)i/50)*2.5; origin_z = 3.5+cos((float)i/30)*2; diameter = 2+sin((float)i/150); for (x=0; x<8; x++) { for (y=0; y<8; y++) { for (z=0; z<8; z++) { distance = distance3d(x,y,z, origin_x, origin_y, origin_z); //printf("Distance: %f \n", distance); if (distance>diameter && distance<diameter+1) { setvoxel(x,y,z); } } } } delay_ms(delay); fill(0x00); } }
int main (int argc, char **argv) { cube_init(); pthread_t cube_thread; int iret, i, x; iret = pthread_create (&cube_thread, NULL, cube_updater, rs232_cube); while (1) { printf("Effect: sidewaves\n"); sidewaves(2000,100); printf("Effect: ripples\n"); ripples(2000,100); printf("Effect: linespin\n"); linespin(2000,100); printf("Effect: sinelines\n"); sinelines(2000,100); printf("Effect: spheremove\n"); spheremove(1500,100); printf("Effect: fireworks\n"); fireworks(7,50,1200); printf("Effect: gol_play\n"); for (i=0; i<10; i++) { for (x=0; x<20; x++) setvoxel(rand()%4,rand()%4,rand()%4); gol_play(50,1000); } } }
// Draws a plane on any diagonal angle // unsigned char anchor is the plane that is constant. ("x","y", or "z") void drawline_plane(int x2, int y2, int x1, int y1,unsigned char anchor){ int deltax = abs(x2 - x1); // The difference between the x's int deltay = abs(y2 - y1); // The difference between the y's int x = x1; // Start x off at the first pixel int y = y1; // Start y off at the first pixel int xinc1; int xinc2; int yinc1; int yinc2; int den; int num; int numadd; int numpixels; if (x2 >= x1) // The x-values are increasing { xinc1 = 1; xinc2 = 1; } else // The x-values are decreasing { xinc1 = -1; xinc2 = -1; } if (y2 >= y1) // The y-values are increasing { yinc1 = 1; yinc2 = 1; } else // The y-values are decreasing { yinc1 = -1; yinc2 = -1; } if (deltax >= deltay) // There is at least one x-value for every y-value { xinc1 = 0; // Don't change the x when numerator >= denominator yinc2 = 0; // Don't change the y for every iteration den = deltax; num = deltax / 2; numadd = deltay; numpixels = deltax; // There are more x-values than y-values } else // There is at least one y-value for every x-value { xinc2 = 0; // Don't change the x for every iteration yinc1 = 0; // Don't change the y when numerator >= denominator den = deltay; num = deltay / 2; numadd = deltax; numpixels = deltay; // There are more y-values than x-values } int curpixel; for (curpixel = 0; curpixel <= numpixels; curpixel++) { if (anchor == "z") { // Draw the current pixels setvoxel(x, y, 3); setvoxel(x, y, 2); setvoxel(x, y, 1); setvoxel(x, y, 0); } if (anchor == "x") { // Draw the current pixels setvoxel(x, 3, y); setvoxel(x, 2, y); setvoxel(x, 1, y); setvoxel(x, 0, y); } if (anchor == "y") { // Draw the current pixels setvoxel(3, y, x); setvoxel(2, y, x); setvoxel(1, y, x); setvoxel(0, y, x); } num += numadd; // Increase the numerator by the top of the fraction if (num >= den) // Check if numerator >= denominator { num -= den; // Calculate the new numerator value x += xinc1; // Change the x as appropriate y += yinc1; // Change the y as appropriate } x += xinc2; // Change the x as appropriate y += yinc2; // Change the y as appropriate } }
void launch_effect(int effect) { int i; unsigned char ii; fill(0x00); switch (effect) { case 0x00: effect_rain(100); break; case 1: sendvoxels_rand_z(20,220,2000); break; case 2: effect_random_filler(5,1); effect_random_filler(5,0); effect_random_filler(5,1); effect_random_filler(5,0); break; case 3: effect_z_updown(20,1000); break; case 4: effect_wormsqueeze (2, AXIS_Z, -1, 100, 1000); break; case 5: effect_blinky2(); break; case 6: for (ii=0;ii<8;ii++) { effect_box_shrink_grow (1, ii%4, ii & 0x04, 650); } effect_box_woopwoop(800,0); effect_box_woopwoop(800,1); effect_box_woopwoop(800,0); effect_box_woopwoop(800,1); break; case 7: effect_planboing (AXIS_Z, 600); effect_planboing (AXIS_X, 600); effect_planboing (AXIS_Y, 600); effect_planboing (AXIS_Z, 600); effect_planboing (AXIS_X, 600); effect_planboing (AXIS_Y, 600); fill(0x00); break; case 8: fill(0x00); effect_telcstairs(0,800,0xff); effect_telcstairs(0,800,0x00); effect_telcstairs(1,800,0xff); effect_telcstairs(1,800,0x00); delay_ms(1000); fill(0x00); effect_telcstairs(0,800,0xff); effect_telcstairs(0,800,0x00); effect_telcstairs(1,800,0xff); effect_telcstairs(1,800,0x00); break; case 9: effect_axis_updown_randsuspend(AXIS_Z, 550,5000,0); effect_axis_updown_randsuspend(AXIS_Z, 550,5000,1); effect_axis_updown_randsuspend(AXIS_Z, 550,5000,0); effect_axis_updown_randsuspend(AXIS_Z, 550,5000,1); effect_axis_updown_randsuspend(AXIS_X, 550,5000,0); effect_axis_updown_randsuspend(AXIS_X, 550,5000,1); effect_axis_updown_randsuspend(AXIS_Y, 550,5000,0); effect_axis_updown_randsuspend(AXIS_Y, 550,5000,1); break; case 10: effect_loadbar(700); break; case 11: effect_wormsqueeze (1, AXIS_Z, 1, 100, 1000); break; case 12: effect_smileyspin(2,1000,1); break; case 13: effect_stringfly2("HELLO WORLD!"); break; case 14: effect_smileyspin(3,1000,0); break; case 15: effect_boxside_randsend_parallel (AXIS_Z, 0 , 200,1); delay_ms(1500); effect_boxside_randsend_parallel (AXIS_Z, 1 , 200,1); delay_ms(1500); effect_boxside_randsend_parallel (AXIS_Z, 0 , 200,2); delay_ms(1500); effect_boxside_randsend_parallel (AXIS_Z, 1 , 200,2); delay_ms(1500); effect_boxside_randsend_parallel (AXIS_Y, 0 , 200,1); delay_ms(1500); effect_boxside_randsend_parallel (AXIS_Y, 1 , 200,1); delay_ms(1500); break; case 16: boingboing(250, 600, 0x01, 0x02); break; case 17: fill(0x00); // Create a random starting point for the Game of Life effect. for (i = 0; i < 20;i++) { setvoxel(rand()%4,rand()%4,rand()%4); } gol_play(20, 400); break; case 18: effect_pathspiral(100,500); break; case 19: effect_path_bitmap(700,2,3); break; case 20: effect_smileyspin(2,1000,1); break; case 21: effect_path_text(1000,"HI"); break; case 22: effect_rand_patharound(400,600); break; case 23: effect_wormsqueeze (1, AXIS_Z, -1, 100, 1000); break; case 24: effect_smileyspin(2,1000,2); break; case 25: effect_random_sparkle(); break; case 26: effect_wormsqueeze (1, AXIS_Z, -1, 100, 1000); break; case 27: boingboing(250, 600, 0x01, 0x03); break; // In case the effect number is out of range: default: effect_stringfly2("FAIL"); break; } }
void fireworks (int iterations, int n, int delay) { fill(0x00); int i,f,e; float origin_x = 3; float origin_y = 3; float origin_z = 3; int rand_y, rand_x, rand_z; float slowrate, gravity; // Particles and their position, x,y,z and their movement, dx, dy, dz float particles[n][6]; for (i=0; i<iterations; i++) { origin_x = rand()%4; origin_y = rand()%4; origin_z = rand()%2; origin_z +=5; origin_x +=2; origin_y +=2; // shoot a particle up in the air for (e=0;e<origin_z;e++) { setvoxel(origin_x,origin_y,e); delay_ms(600+500*e); fill(0x00); } // Fill particle array for (f=0; f<n; f++) { // Position particles[f][0] = origin_x; particles[f][1] = origin_y; particles[f][2] = origin_z; rand_x = rand()%200; rand_y = rand()%200; rand_z = rand()%200; // Movement particles[f][3] = 1-(float)rand_x/100; // dx particles[f][4] = 1-(float)rand_y/100; // dy particles[f][5] = 1-(float)rand_z/100; // dz } // explode for (e=0; e<25; e++) { slowrate = 1+tan((e+0.1)/20)*10; gravity = tan((e+0.1)/20)/2; for (f=0; f<n; f++) { particles[f][0] += particles[f][3]/slowrate; particles[f][1] += particles[f][4]/slowrate; particles[f][2] += particles[f][5]/slowrate; particles[f][2] -= gravity; setvoxel(particles[f][0],particles[f][1],particles[f][2]); } delay_ms(delay); fill(0x00); } } }