// --- Methods inherited from Texmap --- RGBA Smoke::EvalColor(ShadeContext& sc) { float d; Point3 p, dp; if (gbufID) sc.SetGBufferID(gbufID); xyzGen->GetXYZ(sc, p, dp); if (size == 0.0f) size = 1.0f; d = SmokeFunc(p/size, iter); // If we have sub-texmaps and they are enabled, get the colors from // the sub-texmaps, otherwise get them from the color swatch RGBA c0 = (mapOn[0]&&subTex[0]) ? subTex[0]->EvalColor(sc): col[0]; RGBA c1 = (mapOn[1]&&subTex[1]) ? subTex[1]->EvalColor(sc): col[1]; Col24 c; Col24 col1 = Col24FromColor(c0); Col24 col2 = Col24FromColor(c1); lerp_color(&c, &col1, &col2, d); return ColorFromCol24(c); }
// --- Methods inherited from Texmap --- RGBA Water::EvalColor(ShadeContext& sc) { float d; float q[3]; Point3 p, dp; if (gbufID) sc.SetGBufferID(gbufID); xyzGen->GetXYZ(sc, p, dp); q[0] = p.x; q[1] = p.y; q[2] = p.z; d = ScalarWave(q); if (d>1.0f) d = 1.0f; // If we have sub-texmaps and they are enabled, get the colors from // the sub-texmaps, otherwise get them from the color swatch RGBA c0 = (mapOn[0]&&subTex[0]) ? subTex[0]->EvalColor(sc): col[0]; RGBA c1 = (mapOn[1]&&subTex[1]) ? subTex[1]->EvalColor(sc): col[1]; Col24 c; Col24 col1 = Col24FromColor(c0); Col24 col2 = Col24FromColor(c1); lerp_color(&c, &col1, &col2, d); return ColorFromCol24(c); }
// --- Methods inherited from Texmap --- RGBA Stucco::EvalColor(ShadeContext& sc) { float f; Point3 p, dp; if (gbufID) sc.SetGBufferID(gbufID); xyzGen->GetXYZ(sc, p, dp); if (size == 0.0f) size = 0.0001f; p /= size; float scl = compscl(dp, size); f = Func(p, scl); // If we have sub-texmaps and they are enabled, get the colors from // the sub-texmaps, otherwise get them from the color swatch RGBA c0 = (mapOn[0]&&subTex[0]) ? subTex[0]->EvalColor(sc): col[0]; RGBA c1 = (mapOn[1]&&subTex[1]) ? subTex[1]->EvalColor(sc): col[1]; Col24 c; Col24 col1 = Col24FromColor(c0); Col24 col2 = Col24FromColor(c1); lerp_color(&c, &col1, &col2, f); return ColorFromCol24(c); }
static void update_particle(particle *p) { const generator_data *data = p->data; double factor = p->time_alive / p->time_to_live; double time = time_elapsed; p->velocity = vector_scale(p->velocity, 1 - data->deceleration * time); p->position = vector_add(p->position, vector_scale(p->velocity, time)); p->time_alive += time; p->radius = data->start_radius + factor * data->end_radius; p->color = lerp_color(data->start_color, data->end_color, factor); }
static void mainloop(void) { SDL_Event event; int Px; int Py; double x0; double y0; double x; double y; const double ratio = (double) WINDOW_WIDTH / (double) WINDOW_HEIGHT; const double baserange = 3.0; double step = 0.1; bool output_params = false; if (ishift == 0.0) { xrange = ratio * baserange; yrange = baserange; } goto start; while (SDL_WaitEvent(&event)) { switch (event.type) { case SDL_QUIT: return; case SDL_WINDOWEVENT: if (event.window.type == SDL_WINDOWEVENT_EXPOSED) break; continue; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_LEFT: output_params = true; ishift -= step; break; case SDLK_RIGHT: output_params = true; ishift += step; break; case SDLK_UP: output_params = true; jshift -= step; break; case SDLK_DOWN: output_params = true; jshift += step; break; case SDLK_EQUALS: case SDLK_PLUS: output_params = true; xrange /= 2.0; yrange /= 2.0; step /= 2.0; break; case SDLK_MINUS: output_params = true; xrange *= 2.0; yrange *= 2.0; step *= 2.0; break; case SDLK_8: iterations = min_iterations; genpalette(); printf("%d iterations\n", iterations); break; case SDLK_0: iterations *= 2; genpalette(); printf("%d iterations\n", iterations); break; case SDLK_9: if (iterations > min_iterations) { iterations /= 2; genpalette(); printf("%d iterations\n", iterations); } break; } if (output_params) printf("%lf %lf %lf %lf\n", ishift, jshift, xrange, yrange); output_params = false; break; default: continue; } start: SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); SDL_RenderClear(renderer); for (Py = 0; Py < WINDOW_HEIGHT; ++Py) { for (Px = 0; Px < WINDOW_WIDTH; ++Px) { x0 = (double) Px * xrange / (double) WINDOW_WIDTH - (xrange / 2.0) + ishift; y0 = (double) Py * yrange / (double) WINDOW_HEIGHT - (yrange / 2.0) + jshift; x = 0.0; y = 0.0; double iter = 0.0; while ((x*x + y*y) < (2 << 16) && iter < iterations) { double xtemp = x*x - y*y + x0; y = 2*x*y + y0; x = xtemp; iter = iter + 1; } if (iter < iterations) { double zn = sqrt(x*x + y*y); double nu = log(log(zn) / log(2)) / log(2); iter = iter + 1 - nu; } SDL_Color col1 = palette[(int) iter]; SDL_Color col2 = palette[(int) (iter + 1.0)]; double rem = fmod(iter, 1.0); SDL_Color col = lerp_color(&col1, &col2, rem); SDL_SetRenderDrawColor(renderer, col.r, col.g, col.b, col.a); SDL_RenderDrawPoint(renderer, Px, Py); } } SDL_RenderPresent(renderer); } errx(EXIT_FAILURE, "SDL_WaitEvent: %s", SDL_GetError()); }