Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

NT8: Using Lerp with SharpDX?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    NT8: Using Lerp with SharpDX?

    Hi there,

    I wish to use the SharpDX method 'Lerp' with my SharpDX brush to lighten or darken a SharpDX brush.

    Edit: I have managed to work this out but I would like someone to see if this meets best practices. I also want to leave this for anyone else who needs the snippet.

    I have managed to do this:

    PHP Code:

     SharpDX
    .Direct2D1.SolidColorBrush scb =  (SharpDX.Direct2D1.SolidColorBrush)myBrushDX;                                               
     
    SharpDX.Color colorStart = (SharpDX.Color)scb.Color;
     
    SharpDX.Color colorEnd SharpDX.Color.White;
     
    SharpDX.Color colorResult;
     
    float amount 0.9f;
     
    SharpDX.Color.Lerp(ref colorStartref colorEndamountout colorResult);
     
    scb = new SharpDX.Direct2D1.SolidColorBrush(RenderTargetcolorResult);

    myBrushDX scb
    Thank you.
    Last edited by Sim22; 07-13-2016, 11:27 PM.

    #2
    Hi Sim22,

    I'm not sure of a best practice for lightening or darkening a color.

    If interpolation between white and the color or black and the color is working then that seems to be the solution.

    You could always add or subtract from the red green blue values themselves. The link below is for System.Windows.Media colors, but would apply to any color object that can use RGB values.
    http://www.pvladov.com/2012/09/make-...or-darker.html

    This thread will remain open to any community members that know of an alternative way of changing a color lighter or darker.
    Last edited by NinjaTrader_ChelseaB; 07-15-2016, 07:22 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you Chelsea. Yes I've seen Pladov's link before.

      I have several methods of which I am experimenting.


      PHP Code:

      public Color ToneChangeColor(Color colorfloat percentToneChange)
              {
                  if (
      percentToneChange 0f)
                      return 
      color;

                  
      byte red    Convert.ToByte(Math.Min(255color.percentToneChange 0.01));
                  
      byte green    Convert.ToByte(Math.Min(255color.percentToneChange 0.01));
                  
      byte blue    Convert.ToByte(Math.Min(255color.percentToneChange 0.01));

                  return 
      Color.FromArgb(color.Aredgreenblue);
              }

      public 
      Brush ToneChangeBrush(Brush brushfloat percentToneChange)
              {
                  if (
      percentToneChange 0f)
                      return 
      brush;

                  
      SolidColorBrush solidColorBrush = (SolidColorBrush)brush;

                  
      byte red Convert.ToByte(Math.Min(255solidColorBrush.Color.percentToneChange 0.01));
                  
      byte green Convert.ToByte(Math.Min(255solidColorBrush.Color.percentToneChange 0.01));
                  
      byte blue Convert.ToByte(Math.Min(255solidColorBrush.Color.percentToneChange 0.01));

                  return new 
      SolidColorBrush(Color.FromArgb(solidColorBrush.Color.Aredgreenblue));
              }

      public 
      Brush ToneChangeColorToBrush(Color colorfloat percentToneChange)
              {
                  if (
      percentToneChange 0f)
                      return new 
      SolidColorBrush(color);

                  
      byte red Convert.ToByte(Math.Min(255color.percentToneChange 0.01));
                  
      byte green Convert.ToByte(Math.Min(255color.percentToneChange 0.01));
                  
      byte blue Convert.ToByte(Math.Min(255color.percentToneChange 0.01));

                  return new 
      SolidColorBrush(Color.FromArgb(color.Aredgreenblue));
              }

      public 
      Color ChangeColorBrightness(Color colorfloat correctionFactor)
              {
                  
      float red = (float)color.R;
                  
      float green = (float)color.G;
                  
      float blue = (float)color.B;

                  if (
      correctionFactor 0)
                  {
                      
      correctionFactor correctionFactor;
                      
      red *= correctionFactor;
                      
      green *= correctionFactor;
                      
      blue *= correctionFactor;
                  }
                  else
                  {
                      
      red = (255 red) * correctionFactor red;
                      
      green = (255 green) * correctionFactor green;
                      
      blue = (255 blue) * correctionFactor blue;
                  }

                  return 
      Color.FromArgb(color.A, (byte)red, (byte)green, (byte)blue);
              } 
      I was just curious with using Lerp as it had been mentioned on StackOverflow.com but I was unsure how to go about using the inbuilt Lerp method in SharpDX.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by frslvr, 04-11-2024, 07:26 AM
      6 responses
      105 views
      1 like
      Last Post NinjaTrader_BrandonH  
      Started by trilliantrader, 04-18-2024, 08:16 AM
      6 responses
      26 views
      0 likes
      Last Post trilliantrader  
      Started by arvidvanstaey, Yesterday, 02:19 PM
      5 responses
      14 views
      0 likes
      Last Post NinjaTrader_Zachary  
      Started by Rapine Heihei, Yesterday, 08:25 PM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by Mongo, Yesterday, 11:05 AM
      6 responses
      27 views
      0 likes
      Last Post Mongo
      by Mongo
       
      Working...
      X