1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.systemui.surfaceeffects.turbulencenoise 17 18 import android.graphics.Color 19 import java.util.Random 20 21 /** Turbulence noise animation configuration. */ 22 data class TurbulenceNoiseAnimationConfig( 23 /** The number of grids that is used to generate noise. */ 24 val gridCount: Float = DEFAULT_NOISE_GRID_COUNT, 25 26 /** Multiplier for the noise luma matte. Increase this for brighter effects. */ 27 val luminosityMultiplier: Float = DEFAULT_LUMINOSITY_MULTIPLIER, 28 29 /** Initial noise offsets. */ 30 val noiseOffsetX: Float = random.nextFloat(), 31 val noiseOffsetY: Float = random.nextFloat(), 32 val noiseOffsetZ: Float = random.nextFloat(), 33 34 /** 35 * Noise move speed variables. 36 * 37 * Its sign determines the direction; magnitude determines the speed. <ul> 38 * 39 * ``` 40 * <li> [noiseMoveSpeedX] positive: right to left; negative: left to right. 41 * <li> [noiseMoveSpeedY] positive: bottom to top; negative: top to bottom. 42 * <li> [noiseMoveSpeedZ] its sign doesn't matter much, as it moves in Z direction. Use it 43 * to add turbulence in place. 44 * ``` 45 * 46 * </ul> 47 */ 48 val noiseMoveSpeedX: Float = 0f, 49 val noiseMoveSpeedY: Float = 0f, 50 val noiseMoveSpeedZ: Float = DEFAULT_NOISE_SPEED_Z, 51 52 /** Color of the effect. */ 53 val color: Int = DEFAULT_COLOR, 54 /** Background color of the effect. */ 55 val screenColor: Int = DEFAULT_SCREEN_COLOR, 56 val width: Float = 0f, 57 val height: Float = 0f, 58 val maxDuration: Float = DEFAULT_MAX_DURATION_IN_MILLIS, 59 val easeInDuration: Float = DEFAULT_EASING_DURATION_IN_MILLIS, 60 val easeOutDuration: Float = DEFAULT_EASING_DURATION_IN_MILLIS, 61 val pixelDensity: Float = 1f, 62 /** 63 * Variants in noise. Higher number means more contrast; lower number means less contrast but 64 * make the noise dimmed. You may want to increase the [lumaMatteBlendFactor] to compensate. 65 * Expected range [0, 1]. 66 */ 67 val lumaMatteBlendFactor: Float = DEFAULT_LUMA_MATTE_BLEND_FACTOR, 68 /** 69 * Offset for the overall brightness in noise. Higher number makes the noise brighter. You may 70 * want to use this if you have made the noise softer using [lumaMatteBlendFactor]. Expected 71 * range [0, 1]. 72 */ 73 val lumaMatteOverallBrightness: Float = DEFAULT_LUMA_MATTE_OVERALL_BRIGHTNESS, 74 /** Whether to flip the luma mask. */ 75 val shouldInverseNoiseLuminosity: Boolean = false, 76 ) { 77 companion object { 78 const val DEFAULT_MAX_DURATION_IN_MILLIS = 30_000f // Max 30 sec 79 const val DEFAULT_EASING_DURATION_IN_MILLIS = 750f 80 const val DEFAULT_LUMINOSITY_MULTIPLIER = 1f 81 const val DEFAULT_NOISE_GRID_COUNT = 1.2f 82 const val DEFAULT_NOISE_SPEED_Z = 0.3f 83 const val DEFAULT_COLOR = Color.WHITE 84 const val DEFAULT_LUMA_MATTE_BLEND_FACTOR = 1f 85 const val DEFAULT_LUMA_MATTE_OVERALL_BRIGHTNESS = 0f 86 const val DEFAULT_SCREEN_COLOR = Color.BLACK 87 private val random = Random() 88 } 89 } 90