Lines Matching refs:sp

117 	spherestruct *sp;  in init_sphere()  local
120 sp = &spheres[MI_SCREEN(mi)]; in init_sphere()
122 if (sp->points != NULL) { in init_sphere()
123 (void) free((void *) sp->points); in init_sphere()
124 sp->points = (XPoint *) NULL; in init_sphere()
126 sp->width = MAX(MI_WIDTH(mi), 4); in init_sphere()
127 sp->height = MAX(MI_HEIGHT(mi), 4); in init_sphere()
128 if ((sp->points = (XPoint *) malloc(MIN(sp->width, sp->height) * in init_sphere()
135 sp->dirx = 1; in init_sphere()
136 sp->x = sp->radius; in init_sphere()
137 sp->shadowx = (LRAND() & 1) ? 1 : -1; in init_sphere()
138 sp->shadowy = (LRAND() & 1) ? 1 : -1; in init_sphere()
148 spherestruct *sp; in draw_sphere() local
152 sp = &spheres[MI_SCREEN(mi)]; in draw_sphere()
153 if (sp->points == NULL) in draw_sphere()
157 if ((sp->dirx && ABS(sp->x) >= sp->radius) || in draw_sphere()
158 (sp->diry && ABS(sp->y) >= sp->radius)) { in draw_sphere()
159 sp->radius = NRAND(MIN(sp->width / 2, sp->height / 2) - 1) + 1; in draw_sphere()
162 sp->dirx = (int) (LRAND() & 1) * 2 - 1; in draw_sphere()
163 sp->diry = 0; in draw_sphere()
165 sp->dirx = 0; in draw_sphere()
166 sp->diry = (int) (LRAND() & 1) * 2 - 1; in draw_sphere()
168 sp->x0 = NRAND(sp->width); in draw_sphere()
169 sp->y0 = NRAND(sp->height); in draw_sphere()
171 sp->x = -sp->radius * sp->dirx; in draw_sphere()
172 sp->y = -sp->radius * sp->diry; in draw_sphere()
175 sp->color = NRAND(MI_NPIXELS(mi)); in draw_sphere()
177 if (sp->dirx == 1) { in draw_sphere()
178 if (sp->x0 + sp->x < 0) in draw_sphere()
179 sp->x = -sp->x0; in draw_sphere()
180 } else if (sp->dirx == -1) { in draw_sphere()
181 if (sp->x0 + sp->x >= sp->width) in draw_sphere()
182 sp->x = sp->width - sp->x0 - 1; in draw_sphere()
184 if (sp->diry == 1) { in draw_sphere()
185 if (sp->y0 + sp->y < 0) in draw_sphere()
186 sp->y = -sp->y0; in draw_sphere()
187 } else if (sp->diry == -1) { in draw_sphere()
188 if (sp->y0 + sp->y >= sp->height) in draw_sphere()
189 sp->y = sp->height - sp->y0 - 1; in draw_sphere()
191 if (sp->dirx) { in draw_sphere()
192 sp->maxy = SQRT(sp->radius * sp->radius - sp->x * sp->x); in draw_sphere()
193 miny = -sp->maxy; in draw_sphere()
194 if (sp->y0 - sp->maxy < 0) in draw_sphere()
195 miny = -sp->y0; in draw_sphere()
196 maxy = sp->maxy; in draw_sphere()
198 if (sp->diry) { in draw_sphere()
199 sp->maxx = SQRT(sp->radius * sp->radius - sp->y * sp->y); in draw_sphere()
200 minx = -sp->maxx; in draw_sphere()
201 if (sp->x0 - sp->maxx < 0) in draw_sphere()
202 minx = -sp->x0; in draw_sphere()
203 maxx = sp->maxx; in draw_sphere()
205 if (sp->dirx) { in draw_sphere()
206 if (sp->y0 + sp->maxy >= sp->height) in draw_sphere()
207 maxy = sp->height - sp->y0; in draw_sphere()
209 if (sp->diry) { in draw_sphere()
210 if (sp->x0 + sp->maxx >= sp->width) in draw_sphere()
211 maxx = sp->width - sp->x0; in draw_sphere()
215 if (sp->dirx) in draw_sphere()
217 sp->x0 + sp->x, sp->y0 + miny, sp->x0 + sp->x, sp->y0 + maxy); in draw_sphere()
218 if (sp->diry) in draw_sphere()
220 sp->x0 + minx, sp->y0 + sp->y, sp->x0 + maxx, sp->y0 + sp->y); in draw_sphere()
223 XSetForeground(display, gc, MI_PIXEL(mi, sp->color)); in draw_sphere()
227 if (sp->dirx) { in draw_sphere()
228 sqrd = sp->radius * sp->radius - sp->x * sp->x; in draw_sphere()
229 nd = NX * sp->shadowx * sp->x; in draw_sphere()
230 for (sp->y = miny; sp->y <= maxy; sp->y++) in draw_sphere()
231 if ((NRAND(sp->radius * NR)) <= nd + NY * sp->shadowy * sp->y + in draw_sphere()
232 NZ * SQRT(sqrd - sp->y * sp->y)) { in draw_sphere()
233 sp->points[npts].x = sp->x + sp->x0; in draw_sphere()
234 sp->points[npts].y = sp->y + sp->y0; in draw_sphere()
238 if (sp->diry) { in draw_sphere()
239 sqrd = sp->radius * sp->radius - sp->y * sp->y; in draw_sphere()
240 nd = NY * sp->shadowy * sp->y; in draw_sphere()
241 for (sp->x = minx; sp->x <= maxx; sp->x++) in draw_sphere()
242 if ((NRAND(sp->radius * NR)) <= NX * sp->shadowx * sp->x + nd + in draw_sphere()
243 NZ * SQRT(sqrd - sp->x * sp->x)) { in draw_sphere()
244 sp->points[npts].x = sp->x + sp->x0; in draw_sphere()
245 sp->points[npts].y = sp->y + sp->y0; in draw_sphere()
249 XDrawPoints(display, MI_WINDOW(mi), gc, sp->points, npts, CoordModeOrigin); in draw_sphere()
250 if (sp->dirx == 1) { in draw_sphere()
251 sp->x++; in draw_sphere()
252 if (sp->x0 + sp->x >= sp->width) in draw_sphere()
253 sp->x = sp->radius; in draw_sphere()
254 } else if (sp->dirx == -1) { in draw_sphere()
255 sp->x--; in draw_sphere()
256 if (sp->x0 + sp->x < 0) in draw_sphere()
257 sp->x = -sp->radius; in draw_sphere()
259 if (sp->diry == 1) { in draw_sphere()
260 sp->y++; in draw_sphere()
261 if (sp->y0 + sp->y >= sp->height) in draw_sphere()
262 sp->y = sp->radius; in draw_sphere()
263 } else if (sp->diry == -1) { in draw_sphere()
264 sp->y--; in draw_sphere()
265 if (sp->y0 + sp->y < 0) in draw_sphere()
266 sp->y = -sp->radius; in draw_sphere()
273 spherestruct *sp; in free_sphere() local
277 sp = &spheres[MI_SCREEN(mi)]; in free_sphere()
279 if (sp->points) { in free_sphere()
280 (void) free((void *) sp->points); in free_sphere()
289 spherestruct *sp; in refresh_sphere() local
293 sp = &spheres[MI_SCREEN(mi)]; in refresh_sphere()
297 sp->x = -sp->radius; in refresh_sphere()