circle.c (747B)
1 /* a scene with circle drawn by fillellipse(2) func */ 2 3 #include <u.h> 4 #include <libc.h> 5 #include <draw.h> 6 7 #include "noise.h" 8 9 #include "circle.h" 10 11 struct Circle_State { 12 Point c; 13 int r, dr; 14 Image *bg, *fill; 15 long t, nt; 16 } css; 17 18 void cs_init(void *) 19 { 20 css.dr = 50; 21 css.r = 50; 22 css.bg = display->black; 23 css.fill = display->white; 24 css.t = 0; 25 } 26 27 void cs_draw(void *) 28 { 29 css.c = addpt(Pt(css.r, css.r), screen->r.min); 30 draw(screen, screen->r, css.bg, nil, ZP); 31 fillellipse(screen, css.c, css.r, css.r, css.fill, ZP); 32 css.nt = time(nil); 33 34 if (css.nt - css.t > 2) { 35 css.t = css.nt; 36 css.r += css.dr; 37 if (css.r > 500) css.r = 50; 38 } 39 } 40 41 void cs_stop(void *) 42 { 43 44 } 45 46 Scene CircleScene = { 47 "a circle", 48 cs_init, 49 cs_draw, 50 cs_stop, 51 nil};