public static HsbColor FromRgbColorF(ColorF rgb) { float minColour = System.Math.Min(System.Math.Min(rgb.R, rgb.G), rgb.B); float maxColour = System.Math.Max(System.Math.Max(rgb.R, rgb.G), rgb.B); float delta = maxColour - minColour; float b = maxColour; // If the colour is black, the value of saturation doesn't matter so it // can be set to 0. This has to be done to avoid a division by 0. float s = (maxColour != 0) ? 255 * delta / maxColour : 0.0f; // Calculate hue. If saturation is 0, the colour is gray so hue doesn't // matter. Again this case is handled separately to avoid divisions by 0. float h; if (s == 0.0f) { h = 0.0f; } else { if (rgb.R == maxColour) h = (rgb.G - rgb.B) / delta; else if (rgb.G == maxColour) h = 2.0f + (rgb.B - rgb.R) / delta; else h = 4.0f + (rgb.R - rgb.G) / delta; h /= 6.0f; // to bring it to a number between 0 and 1. if (h < 0) ++h; } return new HsbColor(h, s, b); }
public Material(ColorF ambient, ColorF diffuse, ColorF specular, ColorF emission, float shininess) : this() { Ambient = ambient == null? _defaultColor : ambient; Diffuse = diffuse == null? _defaultColor : diffuse; Specular = specular == null? _defaultColor : specular; Emission = emission == null? _defaultColor : emission; Shininess = shininess; }
static ColorsF() { Black = ColorF.FromRgbColor(Colors.Black); Blue = ColorF.FromRgbColor(Colors.Blue); Empty = ColorF.FromRgbColor(Colors.Empty); Gray = ColorF.FromRgbColor(Colors.Gray); Green = ColorF.FromRgbColor(Colors.Green); Red = ColorF.FromRgbColor(Colors.Red); Transparent = ColorF.FromRgbColor(Colors.Transparent); White = ColorF.FromRgbColor(Colors.White); }
public static HslColor FromRgbColorF(ColorF rgb) { float h, s, l; // These two variables are needed because the Lightness is defined as // (minColour + maxColour) / 2 float minColour = System.Math.Min(System.Math.Min(rgb.R, rgb.G), rgb.B); float maxColour = System.Math.Max(System.Math.Max(rgb.R, rgb.G), rgb.B); // If minColour equals maxColour, we know that R = G = B and thus the colour // is a shade of grey. This is a trivial case, hue can be set to anything, // saturation has to be to 0 because only then it's a shade of grey, and lightness // is set to R = G = B, the shade of the grey. if (minColour == maxColour) { // R = G = B to it's a shade of grey h = 0.0f; // it doesn't matter what value it has s = 0.0f; l = rgb.R; // doesn't matter if you pick r, b, or b } else { // If minColour is not equal to maxColour, we have a real colour instead of // a shade of grey, so more calculations are needed: // - Lightness (l) is now set to its definition of (minColour + maxColour) / 2 // - Saturation (s) is then calculated with a different formula depending if light // is in the first half or the second half. This is because the HSL model can be // represented as a double cone, the first cone has a black tip and corresponds // to the first half of lightness values, the second cone has a white tip and // contains the second half of lightness values. // - Hue (h) is calculated with a different formula depending on which of the 3 // colour components is the dominating one, and then normalised to a number // between 0 and 1. l = (minColour + maxColour) / 2.0f; float delta = maxColour - minColour; if (l < 0.5f) s = delta / (maxColour + minColour); else s = delta / (2.0f - delta); if (rgb.R == maxColour) h = (rgb.G - rgb.B) / delta; else if (rgb.G == maxColour) h = 2.0f + (rgb.B - rgb.R) / delta; else h = 4.0f + (rgb.R - rgb.G) / delta; h /= 6.0f; // to bring it to a number between 0 and 1. if (h < 0) ++h; } return new HslColor(h, s, l); }
private void SelectColorClick(object sender, EventArgs e) { colorDialog1.Color = System.Drawing.Color.Black; if (colorDialog1.ShowDialog() != DialogResult.Cancel) { color1 = new ColorF( colorDialog1.Color.R / 255F, colorDialog1.Color.G / 255F, colorDialog1.Color.B / 255F, colorDialog1.Color.A / 255F); colorLabel.Text = string.Format("R = {0}, G = {1}, B = {2}, A = {3}", color1.R, color1.G, color1.B, color1.A); } }
private GameObject CreateStar(Vector2f position, float scale, ColorF color) { var star = new GameObject("Star"); star.SetParent(this.GameObject); star.SetPosition2D(position); star.SetScale2D(scale); SpriteRenderer spriteRenderer = star.AddComponent<SpriteRenderer>(); spriteRenderer.sprite = this.Sprite; spriteRenderer.color = color; spriteRenderer.sortingOrder = -10000; return star; }
public Material(IEnumerable<MaterialContainableBase> users, ColorF ambient, ColorF diffuse, ColorF specular, ColorF emission, float shininess) : this() { if (users != null) { foreach (var user in users) { _users.AddLast(user); } } Ambient = ambient == null? _defaultColor : ambient; Diffuse = diffuse == null? _defaultColor : diffuse; Specular = specular == null? _defaultColor : specular; Emission = emission == null? _defaultColor : emission; Shininess = shininess; }
/// <summary> /// This method creates the render target and all associated D2D and DWrite resources /// </summary> void CreateDeviceResources() { // Only calls if resources have not been initialize before if (renderTarget == null) { // The text format textFormat = dwriteFactory.CreateTextFormat("Bodoni MT", 24, DWrite.FontWeight.Normal, DWrite.FontStyle.Italic, DWrite.FontStretch.Normal); // Create the render target SizeU size = new SizeU((uint)host.ActualWidth, (uint)host.ActualHeight); RenderTargetProperties props = new RenderTargetProperties(); HwndRenderTargetProperties hwndProps = new HwndRenderTargetProperties(host.Handle, size, PresentOptions.None); renderTarget = d2dFactory.CreateHwndRenderTarget(props, hwndProps); // A black brush to be used for drawing text ColorF cf = new ColorF(0, 0, 0, 1); blackBrush = renderTarget.CreateSolidColorBrush(cf); // Create a linear gradient. GradientStop[] stops = { new GradientStop(1, new ColorF(1f, 0f, 0f, 0.25f)), new GradientStop(0, new ColorF(0f, 0f, 1f, 1f)) }; GradientStopCollection pGradientStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Linear, ExtendMode.Wrap); LinearGradientBrushProperties gradBrushProps = new LinearGradientBrushProperties(new Point2F(50, 25), new Point2F(25, 50)); linearGradientBrush = renderTarget.CreateLinearGradientBrush(gradBrushProps, pGradientStops); gridPatternBitmapBrush = CreateGridPatternBrush(renderTarget); solidBrush1 = renderTarget.CreateSolidColorBrush(new ColorF(0.3F, 0.5F, 0.65F, 0.25F)); solidBrush2 = renderTarget.CreateSolidColorBrush(new ColorF(0.0F, 0.0F, 0.65F, 0.5F)); solidBrush3 = renderTarget.CreateSolidColorBrush(new ColorF(0.9F, 0.5F, 0.3F, 0.75F)); // Create a linear gradient. stops[0] = new GradientStop(1, new ColorF(0f, 0f, 0f, 0.25f)); stops[1] = new GradientStop(0, new ColorF(1f, 1f, 0.2f, 1f)); GradientStopCollection radiantGradientStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Linear, ExtendMode.Wrap); RadialGradientBrushProperties radialBrushProps = new RadialGradientBrushProperties(new Point2F(25, 25), new Point2F(0, 0), 10, 10); radialGradientBrush = renderTarget.CreateRadialGradientBrush(radialBrushProps, radiantGradientStops); } }
private void InitParticle(Particle particle) { //position particle.pos.X = (int)(CenterOfGravity.X + PosVar.X * Random11()); particle.pos.Y = (int)(CenterOfGravity.Y + PosVar.Y * Random11()); // direction float a = (Angle + AngleVar * Random11()).ToRadians(); PointF v = new PointF((float)Math.Cos(a), (float)Math.Sin(a)); float s = Speed + SpeedVar * Random11(); v = v.Multiply(s); particle.dir = v; // radial accel particle.radialAccel = RadialAccel + RadialAccelVar * Random11(); // tangential accel particle.tangentialAccel = TangentialAccel + TangentialAccelVar * Random11(); // life float life = Life + LifeVar * Random11(); particle.life = Math.Max(0, life); // color ColorF start = new ColorF(); start.R = StartColor.R + StartColorVar.R * Random11(); start.G = StartColor.G + StartColorVar.G * Random11(); start.B = StartColor.B + StartColorVar.B * Random11(); start.A = StartColor.A + StartColorVar.A * Random11(); ColorF end = new ColorF(); end.R = EndColor.R + EndColorVar.R * Random11(); end.G = EndColor.G + EndColorVar.G * Random11(); end.B = EndColor.B + EndColorVar.B * Random11(); end.A = EndColor.A + EndColorVar.A * Random11(); particle.color = start; particle.deltaColor.R = (end.R - start.R) / particle.life; particle.deltaColor.G = (end.G - start.G) / particle.life; particle.deltaColor.B = (end.B - start.B) / particle.life; particle.deltaColor.A = (end.A - start.A) / particle.life; // size float startS = StartSize + StartSizeVar * Random11(); startS = Math.Max(0, startS); particle.size = startS; if (EndSize == ParticleStartSizeEqualToEndSize) { particle.deltaSize = 0; } else { float endS = EndSize + EndSizeVar * Random11(); particle.deltaSize = (endS - startS) / particle.life; } // angle float startA = StartSpin + StartSpinVar * Random11(); float endA = EndSpin + EndSpinVar * Random11(); particle.angle = startA; particle.deltaAngle = (endA - startA) / particle.life; particle.startPos = this.Position; }
public ColorFToUintConverter(ColorF color) : this() { this.Color = color; }
public void SetBlendColor(ColorF color) { GL.BlendColor(color.Red, color.Green, color.Blue, color.Alpha); }
public DXGI_RGBA(ColorF knownColor, float a = 1.0f) : this((uint)knownColor, a) { }
/// <summary> /// Get the color for a given extruder, falling back to extruder 0 color on -1 (unassigned) /// </summary> /// <param name="materialIndex">The extruder/material index to resolve</param> /// <returns>The color for the given extruder</returns> public static Color Color(int materialIndex) { return(ColorF.FromHSL(Math.Max(materialIndex, 0) / 10.0, .99, .49).ToColor()); }
public bezier_ctrl() { m_color = new ColorF(0.0, 0.0, 0.0); }
protected override void Output(ColorF color) { _form.SetColor((Color)color); }
protected abstract void Output(ColorF color);
public override void SetColor(ColorF color, TOutputInfo outputInfo) { Color = color; }
public SolidColorTexture(Color color) { _color = color.ToColorF(); _textureRes = this.CreateResource(ResourceType.RT_SolidColorTexture); RegisterUpdateResource(); }
public void UpdateSolidColorTexture(IResource res, ref ColorF color) { _resourceManager.UpdateSolidColorTexture(res, ref color); }
private void OnColorChanged(ColorF color) { _color = color; RegisterUpdateResource(); }
public void ClearRenderTargetColor(int index, int layer, int layerCount, uint componentMask, ColorF color) { if (FramebufferParams == null) { return; } if (componentMask != 0xf) { // We can't use CmdClearAttachments if not writing all components, // because on Vulkan, the pipeline state does not affect clears. var dstTexture = FramebufferParams.GetAttachment(index); if (dstTexture == null) { return; } Span <float> clearColor = stackalloc float[4]; clearColor[0] = color.Red; clearColor[1] = color.Green; clearColor[2] = color.Blue; clearColor[3] = color.Alpha; // TODO: Clear only the specified layer. Gd.HelperShader.Clear( Gd, dstTexture, clearColor, componentMask, (int)FramebufferParams.Width, (int)FramebufferParams.Height, FramebufferParams.AttachmentFormats[index], ClearScissor); } else { ClearRenderTargetColor(index, layer, layerCount, color); } }
public void line_color(IColorType c) { m_color = c.ToColorF(); }
public Material(ColorF ambient, ColorF diffuse, ColorF specular, ColorF emission, float shininess) : this(null, ambient, diffuse, specular, emission, shininess) { }
private void scientificVisual3DControl_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 'r') { // 随机显示某些hexahedron foreach (var item in this.scientificVisual3DControl.ModelContainer.Children) { { HexahedronGridderElement element = item as HexahedronGridderElement; if (element != null) { YieldingGeometryModel.Builder.HexahedronGridderElementHelper.RandomVisibility(element, this.scientificVisual3DControl.OpenGL, 0.2); } } { PointSpriteGridderElement element = item as PointSpriteGridderElement; if (element != null) { YieldingGeometryModel.Builder.PointSpriteGridderElementHelper.RandomVisibility(element, this.scientificVisual3DControl.OpenGL, 0.2); } } } this.scientificVisual3DControl.Invalidate(); } if (e.KeyChar == 'c') { OpenGL gl = this.scientificVisual3DControl.OpenGL; List <HexahedronGridderElement> elements = this.scientificVisual3DControl.ModelContainer.Traverse <HexahedronGridderElement>().ToList <HexahedronGridderElement>(); if (elements.Count > 0) { HexahedronGridderElement gridder = elements[0]; HexahedronGridderSource source = gridder.Source; UnmanagedArray <float> visibles = HexahedronGridderHelper.GridVisibleFromActive(source); //随机生成不完整网格的属性。 int propCount = source.DimenSize / 2; if (propCount <= 0) { return; } int minValue = 5000; int maxValue = 10000; int[] gridIndexes; float[] gridValues; HexahedronGridderHelper.RandomValue(propCount, minValue, maxValue, out gridIndexes, out gridValues); float step = (maxValue - minValue) / 10.0f; this.scientificVisual3DControl.SetColorIndicator(minValue, maxValue, step); ColorF[] colors = new ColorF[propCount]; for (int i = 0; i < colors.Length; i++) { colors[i] = (ColorF)this.scientificVisual3DControl.MapToColor(gridValues[i]); } UnmanagedArray <ColorF> colorArray = HexahedronGridderHelper.FromColors(source, gridIndexes, colors, visibles); gridder.UpdateColorBuffer(gl, colorArray, visibles); colorArray.Dispose(); visibles.Dispose(); this.scientificVisual3DControl.Invalidate(); } } }
private void SelectRadialColor2_Click(object sender, EventArgs e) { colorDialog1.Color = System.Drawing.Color.Black; if (colorDialog1.ShowDialog() != DialogResult.Cancel) { color2 = new ColorF( colorDialog1.Color.R / 255F, colorDialog1.Color.G / 255F, colorDialog1.Color.B / 255F, colorDialog1.Color.A / 255F); radialBrushColor2Label.Text = String.Format("R = {0}, G = {1}, B = {2}, A = {3}", color2.R, color2.G, color2.B, color2.A); } }
public void setLightColor(ColorF color) { pInvokes.m_ts.fnGuiObjectView_setLightColor(_ID, color.AsString()); }
public static ColorBGRA ToColorBGRA(this ColorF color) { return(new ColorBGRA(color.R, color.G, color.B, color.A)); }
/// <summary> /// specifies the background of the scene /// </summary> /// <param name="color">the color of the background</param> /// <param name="ambience">the ambient lighting used [0,1]</param> public Background(ColorF color, double ambience) { Color = color; Ambience = ambience; }
public override bool ColorsEqual(ColorF first, ColorF second) { return(((Color)first) == ((Color)second)); }
public MyVertex(Vector3 position, ColorF color, Vector2 textureCoordinate) { Position = position; Color = color; TextureCoordinate = textureCoordinate; }
public void setItemColor(int index, ColorF color) { pInvokes.m_ts.fnGuiListBoxCtrl_setItemColor(_ID, index, color.AsString()); }
public SpriteRendererComponent(ColorF color, Material material, RenderData2D spriteData) { this.color = color; Material = material; SpriteData = spriteData; }
/// <summary> /// Get the color for a given extruder, falling back to the supplied color on -1 (unassigned) /// </summary> /// <param name="materialIndex">The extruder/material index to resolve</param> /// <param name="unassignedColor">The color to use when the extruder/material has not been assigned</param> /// <returns>The color for the given extruder</returns> public static Color Color(int materialIndex, Color unassignedColor) { return((materialIndex == -1) ? unassignedColor : ColorF.FromHSL(materialIndex / 10.0, .99, .49).ToColor()); }
static ColorF() { ColorF w = new ColorF(); w.R = w.G = w.B = w.A = 1.0f; White = w; ColorF black = new ColorF(); black.R = black.G = black.B = 0; black.A = 1.0f; Black = black; }
protected internal ColorF RandomColor() { ColorF ret = new ColorF( (float)Random.NextDouble(), (float)Random.NextDouble(), (float)Random.NextDouble(), RandomOpacity()); #if _D2DTRACE Trace.WriteLine(string.Format("ColorF (RGBA): {0},{1},{2},{3}", ret.R, ret.G, ret.B, ret.A)); #endif return ret; }
private static NSColor ToNSColor(ColorF c) { return NSColor.FromDeviceRgba(c.R, c.G, c.B, c.A); }
private static extern void ICall_LightComponent_SetColorF(LightComponent self, ref ColorF color);
public PlaneShape(Vector3 planeNormal, double distanceFromOrigin, ColorF color, ColorF oddcolor, double reflection, double transparency) { plane.Normal = planeNormal; plane.DistanceFromOrigin = distanceFromOrigin; //Color = color; OddColor = oddcolor; //Transparency = transparency; //Reflection = reflection; }
public void ClearRenderTargetColor(int index, int layer, int layerCount, uint componentMask, ColorF color) { _renderer.New <ClearRenderTargetColorCommand>().Set(index, layer, layerCount, componentMask, color); _renderer.QueueCommand(); }
public static Color4 ToColor4(this ColorF color) { return(new Color4(color.A, color.R, color.G, color.B)); }
private void UpdateAddColor(int keyIndex) { ColorF value = Engine.GetAddColor(keyIndex); cpAC.Value = ConvertColor(value); }
public static Color4 ToColor4(this Nexus.Graphics.Colors.Color color) { ColorF colorF = (ColorF)color; return(new Color4(colorF.R, colorF.G, colorF.B, colorF.A)); }
public static HslColor FromRgbColor(Color rgb) { return(FromRgbColorF(ColorF.FromRgbColor(rgb))); }
/// <summary> /// @brief Set the light color on the sun object used to render the model. /// @param color Color of sunlight. /// @tsexample /// // Set the color value for the sun /// %color = \"1.0 0.4 0.5\"; /// // Inform the GuiObjectView object to change the sun color to the defined value /// %thisGuiObjectView.setLightColor(%color); /// @endtsexample /// @see GuiControl) /// /// </summary> public void setLightColor(ColorF color) { TorqueScriptTemplate.m_ts.fnGuiObjectView_setLightColor(_mSimObjectId, color.AsString()); }
public static ColorF FromRGBA(float r, float g, float b, float a) { ColorF c = new ColorF(); c.R = r; c.G = g; c.B = b; c.A = a; return c; }
public static HslColor FromRgbColorF(ColorF rgb) { float h, s, l; // These two variables are needed because the Lightness is defined as // (minColour + maxColour) / 2 float minColour = System.Math.Min(System.Math.Min(rgb.R, rgb.G), rgb.B); float maxColour = System.Math.Max(System.Math.Max(rgb.R, rgb.G), rgb.B); // If minColour equals maxColour, we know that R = G = B and thus the colour // is a shade of grey. This is a trivial case, hue can be set to anything, // saturation has to be to 0 because only then it's a shade of grey, and lightness // is set to R = G = B, the shade of the grey. if (minColour == maxColour) { // R = G = B to it's a shade of grey h = 0.0f; // it doesn't matter what value it has s = 0.0f; l = rgb.R; // doesn't matter if you pick r, b, or b } else { // If minColour is not equal to maxColour, we have a real colour instead of // a shade of grey, so more calculations are needed: // - Lightness (l) is now set to its definition of (minColour + maxColour) / 2 // - Saturation (s) is then calculated with a different formula depending if light // is in the first half or the second half. This is because the HSL model can be // represented as a double cone, the first cone has a black tip and corresponds // to the first half of lightness values, the second cone has a white tip and // contains the second half of lightness values. // - Hue (h) is calculated with a different formula depending on which of the 3 // colour components is the dominating one, and then normalised to a number // between 0 and 1. l = (minColour + maxColour) / 2.0f; float delta = maxColour - minColour; if (l < 0.5f) { s = delta / (maxColour + minColour); } else { s = delta / (2.0f - delta); } if (rgb.R == maxColour) { h = (rgb.G - rgb.B) / delta; } else if (rgb.G == maxColour) { h = 2.0f + (rgb.B - rgb.R) / delta; } else { h = 4.0f + (rgb.R - rgb.G) / delta; } h /= 6.0f; // to bring it to a number between 0 and 1. if (h < 0) { ++h; } } return(new HslColor(h, s, l)); }