// To use this screen saver do NOT include it. // // Instead run: // // AdamFile("Elephant.HC"); //Press <CTRL-t>. /* Graphics Not Rendered in HTML */ //The sprite was created with <CTRL-r>. U0 ElephantTask(CDC *dc, I64 ss_cnts) { I64 x_last=RandRange(GR_WIDTH/4,3*GR_WIDTH/4); I64 y_last=RandRange(GR_HEIGHT/4,3*GR_HEIGHT/4); I64 x_dir=-1; I64 y_dir=-(KbdMsEvtTime%2) + 1 - KbdMsEvtTime%2; I64 rand_x, rand_y, x, y, r[16]; F64 angle; x=x_last; y=y_last; while (TRUE) { rand_x = RandRange(,10000); rand_y = RandRange(,10000); if (rand_x % 1000 < 1) { // 0.1 percent of time change elephant x direction x_dir = -x_dir; } if (rand_y % 1000 < 1) { // 0.1 percent of time change elephant y direction y_dir = -y_dir; } if (x<=0) x_dir=1; if (x>=GR_WIDTH) x_dir=-1; if (y<=0) y_dir=1; if (y>=GR_HEIGHT) y_dir=-1; x=x_last + 8*x_dir; // only move elephant in y direction 30 percent of time if (rand_y % 100 < 30) y=y_last + 8*y_dir; DCFill(dc,WHITE); Mat4x4IdentEqu(r); angle=0.5*Sin(tS/2); Mat4x4RotZ(r,angle); if (x>x_last) { DCSymmetrySet(dc,x,y,x,y-1); dc->flags|=DCF_SYMMETRY|DCF_JUST_MIRROR; } else dc->flags&=~(DCF_SYMMETRY|DCF_JUST_MIRROR); x_last=x; y_last=y; Sprite3Mat4x4B(dc,x,y,0,<1>,r); Sleep(0.5); } } // Window manager tries to call this as // many times per second as the frame rate. // // Every time it is called it increments // ss_cnts starting with 0 // // Here we just use it once to copy the // current screen and spawn a task to // draw the screen saved version. U0 ScreenSaverElephant(CDC *dc, I64 ss_cnts) { if (!ss_cnts) { MemCpy(dc->body,gr.dc2->body,GR_WIDTH*GR_HEIGHT); gr.scrn_saver_task=Spawn(&ElephantTask,dc,"Screen Saver Task"); } } gr.fp_draw_ss=&ScreenSaverElephant;