Lines Matching refs:sp

115 free_sphere_screen(spherestruct *sp) {  in free_sphere_screen()  argument
116 if (sp == NULL) { in free_sphere_screen()
119 if (sp->points) { in free_sphere_screen()
120 free(sp->points); in free_sphere_screen()
123 sp = NULL; in free_sphere_screen()
129 spherestruct *sp; in init_sphere() local
132 sp = &spheres[MI_SCREEN(mi)]; in init_sphere()
134 if (sp->points != NULL) { in init_sphere()
135 free(sp->points); in init_sphere()
136 sp->points = (XPoint *) NULL; in init_sphere()
138 sp->width = MAX(MI_WIDTH(mi), 4); in init_sphere()
139 sp->height = MAX(MI_HEIGHT(mi), 4); in init_sphere()
140 if ((sp->points = (XPoint *) malloc(MIN(sp->width, sp->height) * in init_sphere()
147 sp->dirx = 1; in init_sphere()
148 sp->x = sp->radius; in init_sphere()
149 sp->shadowx = (LRAND() & 1) ? 1 : -1; in init_sphere()
150 sp->shadowy = (LRAND() & 1) ? 1 : -1; in init_sphere()
160 spherestruct *sp; in draw_sphere() local
164 sp = &spheres[MI_SCREEN(mi)]; in draw_sphere()
165 if (sp->points == NULL) in draw_sphere()
169 if ((sp->dirx && ABS(sp->x) >= sp->radius) || in draw_sphere()
170 (sp->diry && ABS(sp->y) >= sp->radius)) { in draw_sphere()
171 sp->radius = NRAND(MIN(sp->width / 2, sp->height / 2) - 1) + 1; in draw_sphere()
174 sp->dirx = (int) (LRAND() & 1) * 2 - 1; in draw_sphere()
175 sp->diry = 0; in draw_sphere()
177 sp->dirx = 0; in draw_sphere()
178 sp->diry = (int) (LRAND() & 1) * 2 - 1; in draw_sphere()
180 sp->x0 = NRAND(sp->width); in draw_sphere()
181 sp->y0 = NRAND(sp->height); in draw_sphere()
183 sp->x = -sp->radius * sp->dirx; in draw_sphere()
184 sp->y = -sp->radius * sp->diry; in draw_sphere()
187 sp->color = NRAND(MI_NPIXELS(mi)); in draw_sphere()
189 if (sp->dirx == 1) { in draw_sphere()
190 if (sp->x0 + sp->x < 0) in draw_sphere()
191 sp->x = -sp->x0; in draw_sphere()
192 } else if (sp->dirx == -1) { in draw_sphere()
193 if (sp->x0 + sp->x >= sp->width) in draw_sphere()
194 sp->x = sp->width - sp->x0 - 1; in draw_sphere()
196 if (sp->diry == 1) { in draw_sphere()
197 if (sp->y0 + sp->y < 0) in draw_sphere()
198 sp->y = -sp->y0; in draw_sphere()
199 } else if (sp->diry == -1) { in draw_sphere()
200 if (sp->y0 + sp->y >= sp->height) in draw_sphere()
201 sp->y = sp->height - sp->y0 - 1; in draw_sphere()
203 if (sp->dirx) { in draw_sphere()
204 sp->maxy = SQRT(sp->radius * sp->radius - sp->x * sp->x); in draw_sphere()
205 miny = -sp->maxy; in draw_sphere()
206 if (sp->y0 - sp->maxy < 0) in draw_sphere()
207 miny = -sp->y0; in draw_sphere()
208 maxy = sp->maxy; in draw_sphere()
210 if (sp->diry) { in draw_sphere()
211 sp->maxx = SQRT(sp->radius * sp->radius - sp->y * sp->y); in draw_sphere()
212 minx = -sp->maxx; in draw_sphere()
213 if (sp->x0 - sp->maxx < 0) in draw_sphere()
214 minx = -sp->x0; in draw_sphere()
215 maxx = sp->maxx; in draw_sphere()
217 if (sp->dirx) { in draw_sphere()
218 if (sp->y0 + sp->maxy >= sp->height) in draw_sphere()
219 maxy = sp->height - sp->y0; in draw_sphere()
221 if (sp->diry) { in draw_sphere()
222 if (sp->x0 + sp->maxx >= sp->width) in draw_sphere()
223 maxx = sp->width - sp->x0; in draw_sphere()
227 if (sp->dirx) in draw_sphere()
229 sp->x0 + sp->x, sp->y0 + miny, sp->x0 + sp->x, sp->y0 + maxy); in draw_sphere()
230 if (sp->diry) in draw_sphere()
232 sp->x0 + minx, sp->y0 + sp->y, sp->x0 + maxx, sp->y0 + sp->y); in draw_sphere()
235 XSetForeground(display, gc, MI_PIXEL(mi, sp->color)); in draw_sphere()
239 if (sp->dirx) { in draw_sphere()
240 sqrd = sp->radius * sp->radius - sp->x * sp->x; in draw_sphere()
241 nd = NX * sp->shadowx * sp->x; in draw_sphere()
242 for (sp->y = miny; sp->y <= maxy; sp->y++) in draw_sphere()
243 if ((NRAND(sp->radius * NR)) <= nd + NY * sp->shadowy * sp->y + in draw_sphere()
244 NZ * SQRT(sqrd - sp->y * sp->y)) { in draw_sphere()
245 sp->points[npts].x = sp->x + sp->x0; in draw_sphere()
246 sp->points[npts].y = sp->y + sp->y0; in draw_sphere()
250 if (sp->diry) { in draw_sphere()
251 sqrd = sp->radius * sp->radius - sp->y * sp->y; in draw_sphere()
252 nd = NY * sp->shadowy * sp->y; in draw_sphere()
253 for (sp->x = minx; sp->x <= maxx; sp->x++) in draw_sphere()
254 if ((NRAND(sp->radius * NR)) <= NX * sp->shadowx * sp->x + nd + in draw_sphere()
255 NZ * SQRT(sqrd - sp->x * sp->x)) { in draw_sphere()
256 sp->points[npts].x = sp->x + sp->x0; in draw_sphere()
257 sp->points[npts].y = sp->y + sp->y0; in draw_sphere()
261 XDrawPoints(display, MI_WINDOW(mi), gc, sp->points, npts, CoordModeOrigin); in draw_sphere()
262 if (sp->dirx == 1) { in draw_sphere()
263 sp->x++; in draw_sphere()
264 if (sp->x0 + sp->x >= sp->width) in draw_sphere()
265 sp->x = sp->radius; in draw_sphere()
266 } else if (sp->dirx == -1) { in draw_sphere()
267 sp->x--; in draw_sphere()
268 if (sp->x0 + sp->x < 0) in draw_sphere()
269 sp->x = -sp->radius; in draw_sphere()
271 if (sp->diry == 1) { in draw_sphere()
272 sp->y++; in draw_sphere()
273 if (sp->y0 + sp->y >= sp->height) in draw_sphere()
274 sp->y = sp->radius; in draw_sphere()
275 } else if (sp->diry == -1) { in draw_sphere()
276 sp->y--; in draw_sphere()
277 if (sp->y0 + sp->y < 0) in draw_sphere()
278 sp->y = -sp->radius; in draw_sphere()
300 spherestruct *sp; in refresh_sphere() local
304 sp = &spheres[MI_SCREEN(mi)]; in refresh_sphere()
308 sp->x = -sp->radius; in refresh_sphere()