static void calculate_pie(void) { WINT XStart, YStart, XEnd, YEnd; RECT rect; WINT temp; HPEN hOldPen; HBRUSH hOldBrush; do { rect.left = get_rand(0, xMax); rect.top = get_rand(0, yMax); rect.right = get_rand(0, xMax); rect.bottom = get_rand(0, yMax); if (rect.left > rect.right) { temp = rect.left; rect.left = rect.right; rect.right = temp; } if (rect.top > rect.bottom) { temp = rect.top; rect.top = rect.bottom; rect.bottom = temp; } XStart = get_rand(rect.left, rect.right); YStart = get_rand(rect.top, rect.bottom); XEnd = get_rand(rect.left, rect.right); YEnd = get_rand(rect.top, rect.bottom); hOldPen = SelectObject(hMemDC, create_pen()); hOldBrush = SelectObject(hMemDC, create_brush()); SetBkColor(hMemDC, colors[get_rand(0, num_colors)]); SetBkMode(hMemDC, get_rand(1,3)); SetROP2(hMemDC, get_rand(1,17)); Pie(hMemDC, rect.left, rect.top, rect.right, rect.bottom, XStart, YStart, XEnd, YEnd); DeleteObject(SelectObject(hMemDC, hOldPen)); DeleteObject(SelectObject(hMemDC, hOldBrush)); if (TestSemaphore(&PainterRequired) < 0) { InvalidateRect(hWnd, &rect, FALSE); UpdateWindow(hWnd); } } while ((TestSemaphore(&DemoRun)) && (!TestSemaphore(&SingleRun))); if (!TestSemaphore(&SingleRun)); Signal(&Done); }
static void calculate_polygon(void) { WINT points, i; RECT rect; POINT p[9]; HPEN hOldPen; HBRUSH hOldBrush; do { rect.left = 0x7fff; rect.top = 0x7fff; rect.right = 0; rect.bottom = 0; points = get_rand(2, 9); for (i=0; i<points; i++) { p[i].x = get_rand(0, xMax); p[i].y = get_rand(0, yMax); if (p[i].x < rect.left) rect.left = p[i].x; if (p[i].x > rect.right) rect.right = p[i].x; if (p[i].y < rect.top) rect.top = p[i].y; if (p[i].y > rect.bottom) rect.bottom = p[i].y; } hOldPen = SelectObject(hMemDC, create_pen()); hOldBrush = SelectObject(hMemDC, create_brush()); SetBkColor(hMemDC, colors[get_rand(0, num_colors)]); SetBkMode(hMemDC, get_rand(1,3)); SetPolyFillMode(hMemDC, get_rand(1,3)); SetROP2(hMemDC, get_rand(1,17)); Polygon(hMemDC, &p[0], points); DeleteObject(SelectObject(hMemDC, hOldPen)); DeleteObject(SelectObject(hMemDC, hOldBrush)); if (TestSemaphore(&PainterRequired) < 0) { InvalidateRect(hWnd, &rect, FALSE); UpdateWindow(hWnd); } } while ((TestSemaphore(&DemoRun)) && (!TestSemaphore(&SingleRun))); if (!TestSemaphore(&SingleRun)); Signal(&Done); }
static void calculate_fillrect(void) { RECT rect; WINT temp; HBRUSH hBrush; do { rect.left = get_rand(0, xMax); rect.top = get_rand(0, yMax); rect.right = get_rand(0, xMax); rect.bottom = get_rand(0, yMax); if (rect.left > rect.right) { temp = rect.left; rect.left = rect.right; rect.right = temp; } if (rect.top > rect.bottom) { temp = rect.top; rect.top = rect.bottom; rect.bottom = temp; } SetBkColor(hMemDC, colors[get_rand(0, num_colors)]); SetBkMode(hMemDC, get_rand(1,3)); hBrush = create_brush(); FillRect(hMemDC, &rect, hBrush); DeleteObject(hBrush); if (TestSemaphore(&PainterRequired) < 0) { InvalidateRect(hWnd, &rect, FALSE); UpdateWindow(hWnd); } } while ((TestSemaphore(&DemoRun)) && (!TestSemaphore(&SingleRun))); if (!TestSemaphore(&SingleRun)); Signal(&Done); }
void ifs_render (AffElement **elements, gint num_elements, gint width, gint height, gint nsteps, IfsComposeVals *vals, gint band_y, gint band_height, guchar *data, guchar *mask, guchar *nhits, gboolean preview) { gint i, k, n; gdouble x, y; gdouble r, g, b; gint ri, gi, bi; guint32 p0, psum; gdouble pt; guchar *ptr; guint32 *prob; gdouble *fprob; gint subdivide; guchar *brush = NULL; gint brush_size = 1; gdouble brush_offset = 0.0; if (preview) subdivide = 1; else subdivide = vals->subdivide; /* compute the probabilities and transforms */ fprob = g_new (gdouble, num_elements); prob = g_new (guint32, num_elements); pt = 0.0; for (i = 0; i < num_elements; i++) { aff_element_compute_trans(elements[i], width * subdivide, height * subdivide, vals->center_x, vals->center_y); fprob[i] = fabs( elements[i]->trans.a11 * elements[i]->trans.a22 - elements[i]->trans.a12 * elements[i]->trans.a21); /* As a heuristic, if the determinant is really small, it's probably a line element, so increase the probability so it gets rendered */ /* FIXME: figure out what 0.01 really should be */ if (fprob[i] < 0.01) fprob[i] = 0.01; fprob[i] *= elements[i]->v.prob; pt += fprob[i]; } psum = 0; for (i = 0; i < num_elements; i++) { psum += (guint32) -1 * (fprob[i] / pt); prob[i] = psum; } prob[i - 1] = (guint32) -1; /* make sure we don't get bitten by roundoff */ /* create the brush */ if (!preview) brush = create_brush (vals, &brush_size, &brush_offset); x = y = 0; r = g = b = 0; /* n is used to limit the number of progress updates */ n = nsteps / 32; /* now run the iteration */ for (i = 0; i < nsteps; i++) { if (!preview && ((i % n) == 0)) gimp_progress_update ((gdouble) i / (gdouble) nsteps); p0 = g_random_int (); k = 0; while (p0 > prob[k]) k++; aff2_apply (&elements[k]->trans, x, y, &x, &y); aff3_apply (&elements[k]->color_trans, r, g, b, &r, &g, &b); if (i < 50) continue; ri = (gint) (255.0 * r + 0.5); gi = (gint) (255.0 * g + 0.5); bi = (gint) (255.0 * b + 0.5); if ((ri < 0) || (ri > 255) || (gi < 0) || (gi > 255) || (bi < 0) || (bi > 255)) continue; if (preview) { if ((x < width) && (y < (band_y + band_height)) && (x >= 0) && (y >= band_y)) { ptr = data + 3 * (((gint) (y - band_y)) * width + (gint) x); *ptr++ = ri; *ptr++ = gi; *ptr = bi; } } else { if ((x < width * subdivide) && (y < height * subdivide) && (x >= 0) && (y >= 0)) { gint ii; gint jj; gint jj0 = floor (y - brush_offset - band_y * subdivide); gint ii0 = floor (x - brush_offset); gint jjmin = 0; gint iimin = 0; gint jjmax; gint iimax; if (ii0 < 0) iimin = - ii0; else iimin = 0; if (jj0 < 0) jjmin = - jj0; else jjmin = 0; if (jj0 + brush_size >= subdivide * band_height) jjmax = subdivide * band_height - jj0; else jjmax = brush_size; if (ii0 + brush_size >= subdivide * width) iimax = subdivide * width - ii0; else iimax = brush_size; for (jj = jjmin; jj < jjmax; jj++) for (ii = iimin; ii < iimax; ii++) { guint m_old; guint m_new; guint m_pix; guint n_hits; guint old_scale; guint pix_scale; gint index = (jj0 + jj) * width * subdivide + ii0 + ii; n_hits = nhits[index]; if (n_hits == 255) continue; m_pix = brush[jj * brush_size + ii]; if (!m_pix) continue; nhits[index] = ++n_hits; m_old = mask[index]; m_new = m_old + m_pix - m_old * m_pix / 255; mask[index] = m_new; /* relative probability that old colored pixel is on top */ old_scale = m_old * (255 * n_hits - m_pix); /* relative probability that new colored pixel is on top */ pix_scale = m_pix * ((255 - m_old) * n_hits + m_old); ptr = data + 3 * index; *ptr = ((old_scale * (*ptr) + pix_scale * ri) / (old_scale + pix_scale)); ptr++; *ptr = ((old_scale * (*ptr) + pix_scale * gi) / (old_scale + pix_scale)); ptr++; *ptr = ((old_scale * (*ptr) + pix_scale * bi) / (old_scale + pix_scale)); } } } } /* main iteration */ if (!preview ) gimp_progress_update (1.0); g_free (brush); g_free (prob); g_free (fprob); }