// Draws the specified filled rectangle. public void FillRectangle(Rectangle2F rect, Color color, double depth = 0.0) { rect.X = GMath.Round(rect.X); rect.Y = GMath.Round(rect.Y); DrawImage(white1x1, rect, Vector2F.Zero, 0.0, color, SpriteEffects.None, depth); //DrawImage(white1x1, rect.Center + 0.5, new Vector2D(0.5, 0.5), rect.Size, 0, color, SpriteEffects.None, depth); }
public override void Draw(Graphics2D g) { g.ResetTranslation(); // Draw the room. if (isBeginningFade) { OldRoomControl.Draw(g); } else { NewRoomControl.Draw(g); } // Draw the fade. int t = timer; int delay = TRANSITION_SWITCH_FADE_DELAY / 2; if (!isBeginningFade) { t = (TRANSITION_FADE_DURATION - delay) - t; } float opacity = t / (float)(TRANSITION_FADE_DURATION - delay); opacity = GMath.Clamp(opacity, 0.0f, 1.0f); g.FillRectangle(GameSettings.SCREEN_BOUNDS, fadeColor * opacity); }
// Translates the position of the string based on the translation and precision settings. private Vector2 NewStringPos(Vector2F position, SpriteFont font, string text, Align alignment) { Vector2F stringSize = font.MeasureString(text); bool intAlign = (alignment & Align.Int) != 0; if (((alignment & Align.Left) != 0) == ((alignment & Align.Right) != 0)) { position.X -= (intAlign ? (int)(stringSize.X / 2.0f) : (stringSize.X / 2.0f)); } else if ((alignment & Align.Right) != 0) { position.X -= stringSize.X; } if (((alignment & Align.Top) != 0) == ((alignment & Align.Bottom) != 0)) { position.Y -= (intAlign ? (int)(stringSize.Y / 2.0f) : (stringSize.Y / 2.0f)); } else if ((alignment & Align.Bottom) != 0) { position.Y -= stringSize.Y; } if (useTranslation) { return(UseIntegerPrecision ? (Vector2)GMath.Floor(position + translation) : (Vector2)(position + translation)); } else { return((Vector2)position); } }
// Draw an animation during at the given time stamp and position. public void DrawAnimation(Animation animation, int variantID, float time, float x, float y, Color color, float depth = 0.0f) { if (animation.LoopMode == LoopMode.Repeat) { if (animation.Duration == 0) { time = 0; } else { time %= animation.Duration; } } x = GMath.Round(x); y = GMath.Round(y); for (int i = 0; i < animation.Frames.Count; ++i) { AnimationFrame frame = animation.Frames[i]; if (time < frame.StartTime) { return; } if (time < frame.StartTime + frame.Duration || (time >= animation.Duration && frame.StartTime + frame.Duration == animation.Duration)) { DrawSprite(frame.Sprite, variantID, x, y, color, depth); } } }
//----------------------------------------------------------------------------- // Overridden methods //----------------------------------------------------------------------------- public override bool OnPush(int direction, float movementSpeed) { if (base.OnPush(direction, MOVEMENT_SPEED)) { offset = Directions.ToPoint(direction); ColorCubeOrientation oldOrientation = orientation; // Find the new sprite index. if (Directions.IsVertical(direction)) { orientation = (ColorCubeOrientation)GMath.Wrap((int)orientation + 3, 6); } else if ((int)orientation % 2 == 0) { orientation = (ColorCubeOrientation)GMath.Wrap((int)orientation - 1, 6); } else { orientation = (ColorCubeOrientation)GMath.Wrap((int)orientation + 1, 6); } // Play the corresponding animation. Graphics.PlayAnimation(GameData.ANIM_COLOR_CUBE_ROLLING_ORIENTATIONS[(int)oldOrientation, direction]); // Set an absolute draw position because the animation should not move with the tile. Graphics.SetAbsoluteDrawPosition(Position); return(true); } return(false); }
private void Select() { Ray r = GMath.GetRayFromScreenPoint(manager.UI.Mouse.ScreenPositionV, manager.UI.GraphicsDevice.Viewport, manager.UI.Camera.Projection, manager.UI.Camera.View); r.Direction.Normalize(); ITargetable selected = manager.UI.Sim.World.Wildlife.Select(r); if (selected != null) { if (this.selected != null) { this.selected.Updated -= UpdateSelectionInfo; } this.selected = selected; this.selected.Updated += UpdateSelectionInfo; manager.UI.Camera.SetTrackingTarget(this.selected); SelectionInfoChanged(selected, EventArgs.Empty); } else { //this.selected = null; //SelectedChanged(null, EventArgs.Empty); } }
// Draws the scrolling item description at the bottom of the screen. public void DrawDescription(Graphics2D g) { int position = textPosition - textStart; int textIndex = position / 8; if (position < 0) { // Round down always. textIndex = (position - 7) / 8; position = ((position - 7) / 8) * 8; } else { position = (position / 8) * 8; } int startIndex = GMath.Max(0, textIndex); int endIndex = GMath.Clamp(textIndex + 16, 0, description.Length); LetterString text = description.Substring(startIndex, endIndex - startIndex); if (position < 0) { g.DrawLetterString(GameData.FONT_LARGE, text, new Point2I(16 - (position / 8) * 8, 108), new Color(16, 40, 88)); } else { g.DrawLetterString(GameData.FONT_LARGE, text, new Point2I(16, 108), new Color(16, 40, 88)); } }
public bool CanDodgeCollision(Rectangle2F block, int direction) { if (Math.Abs(velocity.X) > 0.001f && Math.Abs(velocity.Y) > 0.001f) { return(false); // Only dodge when moving horizontally or vertically. } float dodgeDist = autoDodgeDistance; Rectangle2F objBox = PositionedCollisionBox; Vector2F pos = entity.Position; Vector2F dirVect = Directions.ToVector(direction); for (int side = 0; side < 2; side++) { int moveDir = (direction + (side == 0 ? 1 : 3)) % 4; float distance = Math.Abs(objBox.GetEdge((moveDir + 2) % 4) - block.GetEdge(moveDir)); if (distance <= dodgeDist) { Vector2F checkPos = pos + dirVect + (Directions.ToVector(moveDir) * distance); Vector2F gotoPos = GMath.Round(pos) + Directions.ToVector(moveDir); if (!IsPlaceMeetingSolid(checkPos, collisionBox) && !IsPlaceMeetingSolid(gotoPos, collisionBox)) { return(true); } } } return(false); }
//----------------------------------------------------------------------------- // Constructor //----------------------------------------------------------------------------- public PlayerSpinSwordState() { limitTilesToDirection = false; isReswingable = false; lunge = false; swingAnglePullBack = 0; swingAngleDurations = new int[] { 3, 2, 3, 2, 3, 2, 3, 2, 5 }; weaponSwingAnimation = GameData.ANIM_SWORD_SPIN; playerSwingAnimation = GameData.ANIM_PLAYER_SPIN; // Will always spin clockwise. swingWindingOrders = new WindingOrder[] { WindingOrder.Clockwise, WindingOrder.Clockwise, WindingOrder.Clockwise, WindingOrder.Clockwise }; swingCollisionBoxesNoLunge = new Rectangle2I[4, 9]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 9; j++) { int angle = GMath.Wrap((i * 2) - j, Angles.AngleCount); swingCollisionBoxesNoLunge[i, j] = SWING_TOOL_BOXES_SPIN[angle]; } } }
private string GetJsonFrom1(List <Vector3Int> path, List <float> times, Vector3Int curCell) { const string format = "{{" + "\"Position_Cell\":\"{0}\"," + "\"Next_Cell\":\"{1}\"," + "\"TimeMoveNextCell\":{2}" + "}}"; int count = path.Count <= times.Count ? path.Count : times.Count; string result = ""; string curPos = curCell.ToPositionString(); float lastTime = times[0]; for (int i = 1; i < count; i++) { result += string.Format(format, curPos, path[i].ToPositionString(), GMath.SecondToMilisecond(GMath.Round(times[i] + lastTime, 3))); if (i < count - 1) { result += ","; } curPos = path[i].ToPositionString(); lastTime += times[i]; } return(string.Format("[{0}]", result)); }
private static float SolveForParabaloidKnife(Vector3 rayStart, Vector3 unitRay, float currentTime) { //Vector3 squaredCoeffs = new Vector3(0.0f, 19.36f, 19.36f); //Vector3 linearCoeffs = new Vector3(1.0f, 0.0f, 0.0f); //float constantOffset = -1.8f; Vector3 squaredCoeffs = new Vector3(0.0f, knifeRenderWidthSquared, knifeRenderWidthSquared); Vector3 linearCoeffs = new Vector3(1.0f, 2.0f * knifeRenderWidthSquared * GMath.Cos(currentTime), 2.0f * knifeRenderWidthSquared * GMath.Sin(currentTime)); float constantOffset = knifeRenderWidthSquared - (KnifeXOffsetAtTime(currentTime) + knifeRenderVerticalOffsetFromTime); float a = squaredCoeffs.X * unitRay.X * unitRay.X + squaredCoeffs.Y * unitRay.Y * unitRay.Y + squaredCoeffs.Z * unitRay.Z * unitRay.Z; float b = 2.0f * (squaredCoeffs.X * rayStart.X * unitRay.X + squaredCoeffs.Y * rayStart.Y * unitRay.Y + squaredCoeffs.Z * rayStart.Z * unitRay.Z) + linearCoeffs.Dot(unitRay); float c = squaredCoeffs.X * rayStart.X * rayStart.X + squaredCoeffs.Y * rayStart.Y * rayStart.Y + squaredCoeffs.Z * rayStart.Z * rayStart.Z + linearCoeffs.Dot(rayStart) + constantOffset; float discriminant = (b * b) - (4.0f * a * c); if (discriminant <= 0.0f) { return(float.NaN); } float t0 = (-b - GMath.Sqrt(discriminant)) / (2.0f * a); float t1 = (-b + GMath.Sqrt(discriminant)) / (2.0f * a); return(GMath.Min(t0, t1)); }
public void BacktestMACD(decimal entryPrice, decimal exitPrice) { // 12/26 "slow" moving average for BNBUSD...buy when slow ma hits -0.2 and scale in more at -0.4 var candles = ReadCandles("BINANCE", "BNBUSDT", 60); //var ema = GMath.GetCandlesEMA(candles, 26); var macd = GMath.GetCandlesMACD(candles, 12, 26, 9); var backtest = new Backtest(string.Format("Entry:{0} Exit:{1}", entryPrice, exitPrice)); BacktestRoundTrip inTrade = null; foreach (var kv in macd) { if (inTrade != null) { if (kv.Value.Signal >= exitPrice) { inTrade.Exit = new BacktestTrade(OrderSide.Sell, exitPrice, kv.Key); //Console.WriteLine("EXIT : {0} {1:0.0000}", kv.Key, kv.Value.Signal); backtest.Add(inTrade); inTrade = null; } } else { if (kv.Value.Signal <= entryPrice) { inTrade = new BacktestRoundTrip(); inTrade.Entry = new BacktestTrade(OrderSide.Buy, entryPrice, kv.Key); //Console.WriteLine("ENTRY: {0} {1:0.0000}", kv.Key, kv.Value.Signal); } } } backtest.PrintTrades(); }
/// <summary> /// Расчет средней /// </summary> /// <returns></returns> public void Calculate(int index, float lineCandle) { if (Period == 0) { return; } if (index == 0) { allVal[index].Value = Math.Round(allVal[index].Value / Period, Panel.Params.CountFloat); int y1 = GMath.GetCoordinate(Panel.Rect.Height, Panel.Params.MaxPrice, Panel.Params.MinPrice, allVal[index].Value); lastPoint = new PointF(lineCandle, y1); return; } if (index >= allVal.Length) { index = allVal.Length - 1; } if (allVal[index].Count == Period) { allVal[index].Value = Math.Round(allVal[index].Value / Period, Panel.Params.CountFloat); int y2 = GMath.GetCoordinate(Panel.Rect.Height, Panel.Params.MaxPrice, Panel.Params.MinPrice, allVal[index].Value); var p2 = new PointF(lineCandle, y2); Paint(lastPoint, p2, allVal[index].Value); lastPoint = p2; } }
//========= INTERACTION ========== /** <summary> Returns true if the specified point is on the line. </summary> */ public bool IsPointOnLine(Vector2F v) { double a = Height / Width; double b = Y1 - (a * X1); return(GMath.Abs(v.Y - (a * v.X + b)) == 0); }
/// <summary> /// Gets the absolute of the specified value. /// </summary> /// <param name="x">The value.</param> /// <returns>Absolute.</returns> public static float Abs(ComplexF x) { float a = x.x; float b = x.y; float v, w, t; a = Math.Abs(a); b = Math.Abs(b); if (a > b) { v = a; w = b; } else { v = b; w = a; } t = w / v; t = 1.0f + t * t; t = v * GMath.Sqrt(t); if ((v == 0.0f) || (v > 3.402823466e38f) || (w > 3.402823466e38f)) { t = v + w; } return(t); }
public static void GetOverDecibels(GThread thread, float[,] samples, float thresholddB, float[] overdBs) { var channels = samples.GetLength(0); var sampleCount = samples.GetLength(1); int tid = thread.blockIdx.x; while (tid < sampleCount) { var allChMax = float.MinValue; for (int c = 0; c < channels; c++) { var s = samples[c, tid]; s = s > 0 ? s : -s; // fabs(s) allChMax = GMath.Max(s, allChMax); } allChMax += DC_OFFSET; var allChMaxdB = Decibels.FromLinear(allChMax); var overdB = GMath.Max(allChMaxdB - thresholddB, 0); overdB += DC_OFFSET; overdBs[tid] = overdB; tid += thread.gridDim.x; } }
private void Paint() { var canvas = Panel.GetGraphics; decimal levSign = 0; lock (syncObj) { levSign = Levels[countPainted]; } if (levSign < Panel.Params.MaxPrice && levSign > Panel.Params.MinPrice) { var y = GMath.GetCoordinate(this.Panel.Rect.Height, Panel.Params.MaxPrice, Panel.Params.MinPrice, levSign); Point p1 = new Point() { X = Panel.Rect.X + Panel.Rect.Width - 30, Y = y }; Point p2 = new Point() { X = Panel.Rect.X + Panel.Rect.Width, Y = y }; Line lineLevel = new Line(); lineLevel.Paint(canvas, p1, p2, Color.Red); } countPainted++; }
public BinomialDistribution(Random rnd, int trials, double probability) { Contract.Requires <ArgumentOutOfRangeException>(probability >= 0 && probability <= 1); _rnd = rnd; if (probability == 0) { _cdf = new double[0]; } else if (probability == 1) { _cdf = new double[] { 1.0 } } ; else { _cdf = new double[trials]; double logp = GMath.Log(probability), logq = GMath.Log(1.0 - probability), logGammaN = Combinatorics.LogGamma(trials + 1); for (int i = 0; i < trials; i++) { _cdf[i] = GMath.Exp(logGammaN - Combinatorics.LogGamma(1 + i) - Combinatorics.LogGamma(1 + trials - i) + i * logp + (trials - i) * logq); if (i > 0) { _cdf[i] += _cdf[i - 1]; } } } }
public void Initialize(Room room) { layerCount = room.LayerCount; gridDimensions = (Point2I)GMath.Ceiling((Vector2F) (room.Size * GameSettings.TILE_SIZE) / tileGridCellSize); tiles = new Tile[gridDimensions.X, gridDimensions.Y, layerCount]; }
public PuzzleRoom(string name, int minOrder, IEnumerable <ParticleType> input, IEnumerable <ParticleType> output, Tool[][] availableTools) { _name = name; _minOrder = minOrder; _task = $"{String.Join(" + ", input.Select(p => p.ColoredSymbol))} → {String.Join(" + ", output.Select(p => p.ColoredSymbol))}"; _input = input.OrderBy(p => p).ToList(); _output = output.OrderBy(p => p).ToList(); var w = availableTools.Length; var h = 0; for (var i = 0; i < w; i++) { h = GMath.Max(h, availableTools[i].Length); } var tools = new Tool[w, h]; for (var x = 0; x < availableTools.Length; x++) { for (var y = 0; y < availableTools[x].Length; y++) { tools[x, y] = availableTools[x][y]; } } _toolbar = new Toolbar(tools); }
/** <summary> Sets the hsv values of the color. </summary> */ public void SetHSV(float hue, float sat, float val) { hue = GMath.Clamp(hue, 0f, 1f); sat = GMath.Clamp(sat, 0f, 1f); val = GMath.Clamp(val, 0f, 1f); float hue2 = hue * 6f; float hueI = (float)GMath.Floor(hue2); byte b0 = (byte)(255f * val); byte b1 = (byte)(255f * val * (1f - sat)); byte b2 = (byte)(255f * val * (1f - sat * (hue2 - hueI))); byte b3 = (byte)(255f * val * (1f - sat * (1f - (hue2 - hueI)))); switch ((int)hueI) { case 0: r = b0; g = b3; b = b1; break; case 1: r = b2; g = b0; b = b1; break; case 2: r = b1; g = b0; b = b3; break; case 3: r = b1; g = b2; b = b0; break; case 4: r = b3; g = b1; b = b0; break; case 5: r = b0; g = b1; b = b2; break; } }
public override void PlayerControl(Input input) { swordNode.movement.active = false; //sword.body.velocity = Utils.AngleToVector(sword.body.orient + (float)Math.PI/2) * 100; swordNode.body.velocity = swordNode.body.effvelocity * nodeKnockback; Vector2R rightstick = input.GetRightStick().toV2R(); if (rightstick.LengthSquared() > 0.9 * 0.9) { movingStick = true; target = rightstick; //enabled = true; target.Normalize(); target *= distance; target += parent.body.pos; swordNode.body.pos = Vector2R.Lerp(swordNode.body.pos, target, 0.1f); //sword.body.pos = target + parent.body.pos; Vector2R result = swordNode.body.pos - parent.body.pos; swordNode.body.SetOrientV2(result); } else { movingStick = false; //enabled = false; Vector2R restPos = new Vector2R(parent.body.radius, 0).Rotate(parent.body.orient) + parent.body.pos; swordNode.body.pos = Vector2R.Lerp(swordNode.body.pos, restPos, 0.1f); swordNode.body.orient = GMath.AngleLerp(swordNode.body.orient, parent.body.orient, 0.1f); } //sword.body.pos = position; }
//=========== UPDATING =========== #region Updating /** <summary> Called every step to update the button states. </summary> */ public static void Update(GameTime gameTime) { for (int i = 0; i < 4; i++) { XnaPlayer player = (XnaPlayer)i; buttons[i, (int)Buttons.A].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.A)); buttons[i, (int)Buttons.B].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.B)); buttons[i, (int)Buttons.X].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.X)); buttons[i, (int)Buttons.Y].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.Y)); buttons[i, (int)Buttons.Start].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.Start)); buttons[i, (int)Buttons.Back].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.Back)); buttons[i, (int)Buttons.Home].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.BigButton)); buttons[i, (int)Buttons.LeftShoulder].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.LeftShoulder)); buttons[i, (int)Buttons.RightShoulder].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.RightShoulder)); buttons[i, (int)Buttons.LeftStickButton].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.LeftStick)); buttons[i, (int)Buttons.RightStickButton].Update(1, XnaGamePad.GetState(player).IsButtonDown(XnaButtons.RightStick)); Vector2F dPad = Vector2F.Zero; if (XnaGamePad.GetState(player).IsButtonDown(XnaButtons.DPadRight)) { dPad.X = 1; } if (XnaGamePad.GetState(player).IsButtonDown(XnaButtons.DPadDown)) { dPad.Y = 1; } if (XnaGamePad.GetState(player).IsButtonDown(XnaButtons.DPadLeft)) { dPad.X = -1; } if (XnaGamePad.GetState(player).IsButtonDown(XnaButtons.DPadUp)) { dPad.Y = -1; } if (dPad.X != 0.0f && dPad.Y != 0.0f) { dPad.X /= GMath.Sqrt(2.0f); dPad.Y /= GMath.Sqrt(2.0f); } sticks[i, (int)Buttons.DPad].Update(1, dPad); Vector2F stick = Vector2F.Zero; stick = XnaGamePad.GetState(player).ThumbSticks.Left; stick.Y *= -1; sticks[i, (int)Buttons.LeftStick].Update(1, stick); stick = XnaGamePad.GetState(player).ThumbSticks.Right; stick.Y *= -1; sticks[i, (int)Buttons.RightStick].Update(1, stick); float trigger = XnaGamePad.GetState(player).Triggers.Left; triggers[i, (int)Buttons.LeftTrigger].Update(1, trigger); trigger = XnaGamePad.GetState(player).Triggers.Right; triggers[i, (int)Buttons.RightTrigger].Update(1, trigger); } }
// Set the selection box public void SetSelectionBox(Point2I start, Point2I size) { selectionBox = new Rectangle2I(start, size); Point2I roomLoc = GMath.Clamp(start / Level.RoomSize, Point2I.Zero, Level.Dimensions); selectedRoom = Level.GetRoomAt(roomLoc); }
// Sample the room coordinates at the given point, clamping them to the level's dimensions if specified. public Point2I SampleRoomCoordinates(Point2I point, bool clamp = false) { Point2I span = (Level.RoomSize * GameSettings.TILE_SIZE) + editorControl.RoomSpacing; Point2I roomCoord = point / span; if (point.X < 0) { roomCoord.X--; } if (point.Y < 0) { roomCoord.Y--; } if (clamp && editorControl.IsLevelOpen) { if (editorControl.IsLevelOpen) { return(GMath.Clamp(roomCoord, Point2I.Zero, Level.Dimensions - 1)); } else { return(Point2I.Zero); } } return(roomCoord); }
public override void Update() { // Adjust Z-position and velocity to hover at a certain height. if (Math.Abs(zPosition - GameSettings.COLLECTIBLE_FAIRY_HOVER_HEIGHT) > 2.0f) { if (zPosition < GameSettings.COLLECTIBLE_FAIRY_HOVER_HEIGHT) { Physics.ZVelocity = Math.Min(0.5f, Physics.ZVelocity + 0.05f); } if (zPosition > GameSettings.COLLECTIBLE_FAIRY_HOVER_HEIGHT) { Physics.ZVelocity = Math.Max(-0.5f, Physics.ZVelocity - GameSettings.DEFAULT_GRAVITY); } } else { Physics.ZVelocity = 0.0f; zPosition = GameSettings.COLLECTIBLE_FAIRY_HOVER_HEIGHT; } // Adjust move direction. moveSpeed = physics.Velocity.Length; if (moveSpeed == 0.0f) { direction = GRandom.NextFloat(GMath.FullAngle); } else { direction = Physics.Velocity.Direction; } // Adjust velocity. if (Math.Abs(moveSpeed - maxMoveSpeed) > 0.01f) { moveSpeed += 0.04f * Math.Sign(maxMoveSpeed - moveSpeed); } else { moveSpeed = maxMoveSpeed; } // Update random motion. directionSpeed += 0.05f * GRandom.NextFloat(-30.0f, 30.0f); directionSpeed = GMath.Clamp(directionSpeed, -6.0f, 6.0f); direction += directionSpeed; physics.Velocity = Vector2F.CreatePolar(moveSpeed, direction); // Syncronize facing direction with velocity. if (Physics.Velocity.X > 0.0f) { Graphics.SubStripIndex = 0; } else if (Physics.Velocity.X < 0.0f) { Graphics.SubStripIndex = 1; } base.Update(); }
private void PushPose(Matrix4x4 pose) { Matrix4x4 actualPose = _posesStack.Count == 0? pose: GMath.mul(pose, _posesStack.Peek()); _posesStack.Push(actualPose); }
public static GVector3 operator /(GVector3 v1, float v) { if (GMath.Abs(v) > GMath.EPS) { return(new GVector3(v1.x / v, v1.y / v, v1.z / v)); } return(v1); }
public static GVector2 Divide(GVector2 v1, float divider) { if (GMath.Abs(divider) > GMath.EPS) { return(new GVector2(v1.x / divider, v1.y / divider)); } return(v1); }
public static Color operator *(Color a, float scalar) { return(new Color( (byte)(GMath.Clamp((a.r / 255.0f) * scalar, 0.0f, 1.0f) * 255), (byte)(GMath.Clamp((a.g / 255.0f) * scalar, 0.0f, 1.0f) * 255), (byte)(GMath.Clamp((a.b / 255.0f) * scalar, 0.0f, 1.0f) * 255), (byte)(GMath.Clamp((a.a / 255.0f) * scalar, 0.0f, 1.0f) * 255))); }