Java tutorial
//package com.java2s; /* * Copyright 2016 Google Inc. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * Linearly interpolates a between two one-byte channels. If the value is outside the range of * 0-255 (either because the an input is outside the range, or the ratio is outside the range of * 0.0-1.0), the results will be clamped to 0-255. * * @param a The start color, or the result if the {@code ratio} is 0.0. * @param b The end color, or the result if the {@code ratio} is 1.0. * @param ratio The ratio of {@code b}'s influence in the result, between 0.0 to 1.0. * @return The computed blend value. */ private static int clampedLerp(int a, int b, float ratio) { int rawResult = a + (int) ((b - a) * ratio); return Math.max(Math.min(rawResult, 255), 0); } }