From 121bd7edc2ef105836304215d21aa733368f13f4 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 9 Nov 2019 11:37:35 +0100 Subject: Make pugl_gl3_test deterministic --- test/pugl_gl3_test.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'test/pugl_gl3_test.c') diff --git a/test/pugl_gl3_test.c b/test/pugl_gl3_test.c index 21db4b2..170f969 100644 --- a/test/pugl_gl3_test.c +++ b/test/pugl_gl3_test.c @@ -203,10 +203,10 @@ onExpose(PuglView* view) // Move rect around in an arbitrary way that looks cool rect->pos[0] = (float)(frame.width - rect->size[0]) * - (sinf((float)time * rect->size[0] / 100.0f) + 1.0f) / + (sinf((float)time * rect->size[0] / 64.0f) + 1.0f) / 2.0f; rect->pos[1] = (float)(frame.height - rect->size[1]) * - (cosf((float)time * rect->size[1] / 100.0f) + 1.0f) / + (cosf((float)time * rect->size[1] / 64.0f) + 1.0f) / 2.0f; drawRect(app, rect, proj); @@ -240,23 +240,22 @@ onEvent(PuglView* view, const PuglEvent* event) } static Rect* -makeRects(const size_t numRects, const int width, const int height) +makeRects(const size_t numRects) { - const int minSize = width / 32; - const int maxSize = width / 4; - const float boxAlpha = 0.6f; + const float minSize = (float)defaultWidth / 64.0f; + const float maxSize = (float)defaultWidth / 6.0f; + const float boxAlpha = 0.25f; Rect* rects = (Rect*)calloc(numRects, sizeof(Rect)); for (size_t i = 0; i < numRects; ++i) { - rects[i].pos[0] = (float)(rand() % width); - rects[i].pos[1] = (float)(rand() % height); - rects[i].size[0] = (float)minSize + rand() % (maxSize - minSize); - rects[i].size[1] = (float)minSize + rand() % (maxSize - minSize); - - rects[i].fillColor[1] = (rand() % numRects) / ((float)numRects - 0.4f); - rects[i].fillColor[2] = (rand() % numRects) / ((float)numRects - 0.4f); - rects[i].fillColor[3] = boxAlpha; - + const float s = (sinf(i) / 2.0f + 0.5f); + const float c = (cosf(i) / 2.0f + 0.5f); + + rects[i].size[0] = minSize + s * maxSize; + rects[i].size[1] = minSize + c * maxSize; + rects[i].fillColor[1] = s / 2.0f + 0.25f; + rects[i].fillColor[2] = c / 2.0f + 0.25f; + rects[i].fillColor[3] = boxAlpha; rects[i].borderColor[1] = rects[i].fillColor[1] + 0.4f; rects[i].borderColor[2] = rects[i].fillColor[1] + 0.4f; rects[i].borderColor[3] = boxAlpha; @@ -294,7 +293,7 @@ main(int argc, char** argv) // Create world, view, and rect data app.world = puglNewWorld(); app.view = puglNewView(app.world); - app.rects = makeRects(app.numRects, defaultWidth, defaultHeight); + app.rects = makeRects(app.numRects); // Set up world and view puglSetClassName(app.world, "PuglGL3Test"); -- cgit v1.2.1