public void Render(Tuple <int, ConsoleColor>[,] screen) { int screenWidth = screen.GetLength(0); int screenHeight = screen.Length / screen.GetLength(0); List <Tuple <Triangle3D, int, ConsoleColor> > orderedTriangles = getTriangles(); foreach (Tuple <Triangle3D, int, ConsoleColor> t in orderedTriangles) { Triangle3D tri = t.Item1; if (triangleInView(tri)) { tri.Translate(new Point3D(1, 1, 0)); tri.Scale(new Point3D(screenWidth / 2, screenHeight / 2, 1)); Triangle2D tri2D = new Triangle2D(new Point2D(tri.V1.X, tri.V1.Y), new Point2D(tri.V2.X, tri.V2.Y), new Point2D(tri.V3.X, tri.V3.Y)); // screen, lightvalue, color if (triangleInBounds(tri2D, screen) && tri2D.Area < 4000) { tri2D.drawTriangle(screen, t.Item2, t.Item3); } } } }
private ImageSource RenderBitmap(Bitmap bitmap, List <RenderLine> rl_list, Tuple <List <ConnectedComponent>, double, double>[,] cc_tuple_list) { foreach (var rl in rl_list) { DrawLine(bitmap, rl); } //Create un for (int i = 0; i < cc_tuple_list.GetLength(0); i++) { for (int j = 0; j < cc_tuple_list.GetLength(1); j++) { double offsetX = cc_tuple_list[i, j].Item2; double offsetY = cc_tuple_list[i, j].Item3; foreach (var cc in cc_tuple_list[i, j].Item1) { DrawComponent(bitmap, cc, offsetX, offsetY); } } } ModelRendererBitmapSource renderer = new ModelRendererBitmapSource(bitmap); renderer.Render(); return(renderer.RenderedImage); }
internal PassabilityMap3D(Tuple <bool, bool>[, ,] map) { Map = map; Width = Map.GetLength(0); Height = Map.GetLength(1); Depth = Map.GetLength(2); }
/// <summary> /// Metoda wyliczająca dane do wykresów na podstawie stanu automatu /// </summary> double[][] CalculateModels(Tuple <int, float>[,] cells) { var result = new double[_strategyCount]; var count = new double[result.Length]; var sum = new double[result.Length]; for (var i = 0; i < result.Length; i++) { result[i] = 0; count[i] = 0; } for (var i = 0; i < cells.GetLength(0); i++) { for (var j = 0; j < cells.GetLength(1); j++) { var c = cells[i, j]; var integerStrategy = (IntegerStrategy)_strategyDictionary[c.Item1]; if (integerStrategy != null) { var k = integerStrategy.BetrayalThreshold; double d = (double)c.Item2 / _spd.Neighbours(i, j).Length; result[k] += d; count[k]++; } } } for (var i = 0; i < count.Length; i++) { if ((count[i] - 100 * Double.Epsilon) <= 0) { continue; } result[i] /= count[i]; } var d1 = result.Sum(); if (Math.Abs(d1) < double.Epsilon * 100) { d1 = 1; } var d2 = count.Sum(); if (Math.Abs(d2) < double.Epsilon * 100) { d2 = 1; } result = result.Select(d => 100 * d / d1).ToArray(); for (int i = 0; i < result.Length; i++) { _sumPoints[i] += result[i]; } _sumPointsHistory.Add(_sumPoints); count = count.Select(d => 100 * d / d2).ToArray(); return(new[] { count, result }); }
private bool triangleInBounds(Triangle2D tri, Tuple <int, ConsoleColor>[,] screen) { int screenWidth = screen.GetLength(0); int screenHeight = screen.Length / screen.GetLength(0); return((tri.V1.X >= 0 && tri.V1.X < screenWidth && tri.V1.Y >= 0 && tri.V1.Y < screenHeight) || (tri.V2.X >= 0 && tri.V2.X < screenWidth && tri.V2.Y >= 0 && tri.V2.Y < screenHeight) || (tri.V3.X >= 0 && tri.V3.X < screenWidth && tri.V3.Y >= 0 && tri.V3.Y < screenHeight)); }
private void ChangeNoiseValue() { Random generator = new Random(); for (int i = 0; i < gradient.GetLength(0); ++i) { for (int j = 0; j < gradient.GetLength(1); ++j) { gradient[i, j] = unitVectors[generator.Next(unitVectors.Length)]; } } }
public static float[,,] DerpByNodes(float[,,] valuesNodes, float[,,] derivativesNodes, int steps) { int width = valuesNodes.GetLength(0); int height = valuesNodes.GetLength(1); int depth = valuesNodes.GetLength(2); Tuple <float, float>[,,] nodes = new Tuple <float, float> [width, height, depth]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { for (int k = 0; k < depth; k++) { nodes[i, j, k] = new Tuple <float, float>(valuesNodes[i, j, k], derivativesNodes[i, j, k]); } } } Func <Tuple <float, float>[], Tuple <float, float>[]> selector = t => { float[] values = t.Select(e => e.Item1).ToArray(); float[] derivatives = t.Select(e => e.Item2).ToArray(); return(SequenceInterpolation.DerpByNodes(values, derivatives, steps).Select(e => new Tuple <float, float>(e, 0)).ToArray()); }; Tuple <float, float>[,,] resultTuples = nodes.GoThrough3D(selector); int resultWidth = resultTuples.GetLength(0); int resultHeight = resultTuples.GetLength(1); int resultDepth = resultTuples.GetLength(2); float[,,] result = new float[resultWidth, resultHeight, resultDepth]; for (int i = 0; i < resultWidth; i++) { for (int j = 0; j < resultHeight; j++) { for (int k = 0; k < resultDepth; k++) { result[i, j, k] = resultTuples[i, j, k].Item1; } } } return(result); }
/// ------------------------------------------------------------------------------------ private static double ComputeRawScore(Tuple <float, float>[,] samples, uint targetBreak) { double score = 0; for (int c = 0; c < samples.GetLength(1); c++) { score += Math.Abs(samples[targetBreak, c].Item1) + Math.Abs(samples[targetBreak, c].Item2); } return(score); }
private void RepopulateTileMap() { Tuple <int, int> startCoords = ConvertCoordinates(startPipeX, startPipeY, -9, -5, false); Tuple <int, int> endCoords = ConvertCoordinates(endPipeX, endPipeY, -9, -5, false); LevelGenerator levelGenerator = new LevelGenerator(); Tuple <TileType, int>[,] newLevel = levelGenerator.GenerateNewLevel(19, 11, startCoords.Item1, startCoords.Item2, endCoords.Item1, endCoords.Item2); for (int x = 0; x < newLevel.GetLength(0); x++) { for (int y = 0; y < newLevel.GetLength(1); y++) { Tuple <int, int> convertedCoords = ConvertCoordinates(x, y, -9, -5, true); bool highlight = levelGenerator.IsBorderTile(x, y); calculator.PaintTile(convertedCoords.Item1, convertedCoords.Item2, newLevel[x, y].Item1, newLevel[x, y].Item2, highlight); } } }
private static Image GenerateImage(ImageRequest request, Tuple <int, int>[,] points) { Color color1 = Color.FromHex(request.Color1); Color color2 = Color.FromHex(request.Color2); var image = new Image(request.Width, request.Height, Configuration); for (var x = 0; x < points.GetLength(0); x++) { for (var y = 0; y < points.GetLength(1); y++) { if (x + 1 < points.GetLength(0) && y + 1 < points.GetLength(1)) { var t1 = new[] { new Vector2(points[x, y].Item1, points[x, y].Item2), new Vector2(points[x + 1, y].Item1, points[x + 1, y].Item2), new Vector2(points[x, y + 1].Item1, points[x, y + 1].Item2) }; var t2 = new[] { new Vector2(points[x + 1, y].Item1, points[x + 1, y].Item2), new Vector2(points[x + 1, y + 1].Item1, points[x + 1, y + 1].Item2), new Vector2(points[x, y + 1].Item1, points[x, y + 1].Item2) }; image.FillPolygon(color1, t1); image.FillPolygon(color2, t2); } } } using (var outputStream = new MemoryStream()) { image.SaveAsJpeg(outputStream, new JpegEncoderOptions() { Quality = 100 }); outputStream.Position = 0; return(new Image(outputStream)); } }
internal static InitialConditionsGrid FromCellArray(Tuple <int, float>[,] cells) { InitialConditionCell[,] arr = new InitialConditionCell[cells.GetLength(0), cells.GetLength(1)]; var list = new List <List <InitialConditionCell> >(); for (int i = 0; i < SPDAssets.MAX; i++) { list.Add(new List <InitialConditionCell>()); } for (int i = 0; i < cells.GetLength(0); i++) { for (int j = 0; j < cells.GetLength(1); j++) { int k = (new IntegerStrategy(cells[i, j].Item1)).BetrayalThreshold; arr[i, j] = new InitialConditionCell(i, j, k, k); list[k].Add(arr[i, j]); } } var arr2 = list.Select(l => l.ToArray()).ToArray(); return(new InitialConditionsGrid { CellGrid = arr, CellSets = arr2 }); }
//vrati navic index hran Split polygonu public Tuple <IPolygonReader, List <int> >[] GetSplitPolygonsAndInx() { if (!f_MakeSplits()) { return(null); } var ret = new Tuple <IPolygonReader, List <int> > [mySplits.Count]; for (int i = 0; i < ret.GetLength(0); i++) { ret[i] = new Tuple <IPolygonReader, List <int> >(new BoxListPoint(mySplits[i]), myInxSplits[i]); } return(ret); }
static void Main(string[] args) { hmm = new Hmm(); Random rand = new Random(); Console.WriteLine("Do you want to get the information of the HMM from the file(Y/N)? :"); if (Console.ReadLine().ToUpper() == "N") //If user does NOT wants the values be grabbed from an xml file { Console.WriteLine("How many nodes do you want?"); Int32.TryParse(Console.ReadLine(), out hmm.nodes); Console.WriteLine("How many sequence steps do you want"); Int32.TryParse(Console.ReadLine(), out hmm.numberOfSequenceSteps); //Sets up the emmision array hmm.emissionProbability = new decimal[hmm.nodes][]; for (int i = 0; i < hmm.emissionProbability.GetLength(0); ++i) { hmm.emissionProbability[i] = new decimal[hmm.numberOfSequenceSteps]; } //Sets up the transition array hmm.transitionProbability = new decimal[hmm.nodes][]; for (int i = 0; i < hmm.transitionProbability.GetLength(0); ++i) { hmm.transitionProbability[i] = new decimal[hmm.nodes]; } //Sets up the initial array hmm.initialProbability = new decimal[hmm.nodes]; Console.WriteLine("Do you want the numbers generated randomly(Y/N)?"); bool random = true; if (Console.ReadLine().ToUpper() == "N") { random = false; } GenerateOrAskInitialProbability(rand, random); GenerateOrAskTransitionProbability(rand, random); GenerateOrAskEmissionProbability(rand, random); } else //Gets the valus from XML file { XmlSerializer serializer = new XmlSerializer(typeof(Hmm)); StreamReader reader = new StreamReader("HMM.xml"); hmm = (Hmm)serializer.Deserialize(reader); reader.Close(); } Console.WriteLine("Do you want to show the probability multiplication(Y/N)?"); bool showProb = false; if (Console.ReadLine().ToUpper() == "Y") { showProb = true; } //this array contains the index of the next sequence that it will get the probability of //starts at [0,0...0,0] int[] sequenceArray = new int[hmm.numberOfSequenceSteps]; for (int i = 0; i < hmm.numberOfSequenceSteps; i++) { sequenceArray[i] = 0; } Draw(); //ProbabilityPath is an array of tuples where the first value is the sequence of steps and the second value is the probability of that sequence. //it instantiates the size to the most probability paths that it can take even the ones it cant take such as 0 Tuple <string, decimal>[] probabilityPath = new Tuple <string, decimal> [(int)Math.Pow(hmm.nodes, hmm.numberOfSequenceSteps)]; //For each probability sequence for (int i = 0; i < Math.Pow(hmm.nodes, hmm.numberOfSequenceSteps); i++) { //Starts the probability with initial probability of the start sequencearray first index. decimal probability = hmm.initialProbability[sequenceArray[0]]; for (int columnEmission = 0; columnEmission < hmm.numberOfSequenceSteps; columnEmission++) { //for each column in the emissionProbability array of the starting sequence index that we are at //Multiply the probabilty with the others. probability *= hmm.emissionProbability[sequenceArray[0]][columnEmission]; //if column is not at 0 then multiply probability with the transition probability //If it was in the first index then there would not be a transition probability , just the initial probability. if (columnEmission != 0) { probability *= hmm.transitionProbability[sequenceArray[0]][sequenceArray[columnEmission]]; } //Checks if the column is the last index if (columnEmission == hmm.numberOfSequenceSteps - 1) { //Once at last index then it creates a appends the probability sequence from int to string string sequenceString = ""; for (int s = 0; s < sequenceArray.GetLength(0); s++) { //Appends the sequence int into a string sequenceString += (sequenceArray[s] + 1).ToString(); //If user wanted to see the probability then it is printed out. if (showProb) { if (s == 0) { Console.Write(hmm.initialProbability[sequenceArray[0]] + " * "); Console.Write(hmm.emissionProbability[sequenceArray[0]][s] + " * "); } else { Console.Write(hmm.emissionProbability[sequenceArray[0]][s] + " * "); Console.Write(hmm.transitionProbability[sequenceArray[0]][sequenceArray[s]]); } } } //adds the sequence and the probability path to the array tuple probabilityPath[i] = new Tuple <string, decimal>(sequenceString, probability); Console.Write("\n" + sequenceString); Console.Write(": = {0}\n", probability); //goes to the next sequence IncrementNumberArray(hmm.nodes, sequenceArray); } } } //Checks which path is the most probable path int mostProbableIndex = 0; for (int i = 0; i < probabilityPath.GetLength(0); i++) { if (probabilityPath[i].Item2 > probabilityPath[mostProbableIndex].Item2) { mostProbableIndex = i; } } Console.WriteLine("\nMost probable path is"); Console.WriteLine("{0} with probability of {1}", probabilityPath[mostProbableIndex].Item1, probabilityPath[mostProbableIndex].Item2); Console.ReadLine(); }
/// <summary> /// Metoda wyliczająca dane do wykresów na podstawie stanu automatu /// </summary> double[][] CalculateModels(Tuple<int,float>[,] cells) { var result = new double[_strategyCount]; var count = new double[result.Length]; var sum = new double[result.Length]; for (var i = 0; i < result.Length; i++) { result[i] = 0; count[i] = 0; } for (var i = 0; i < cells.GetLength(0); i++) for (var j = 0; j < cells.GetLength(1); j++) { var c = cells[i, j]; var integerStrategy = (IntegerStrategy) _strategyDictionary[c.Item1]; if (integerStrategy != null) { var k = integerStrategy.BetrayalThreshold; double d = (double)c.Item2/_spd.Neighbours(i,j).Length; result[k] += d; count[k]++; } } for (var i = 0; i < count.Length; i++) { if ((count[i] - 100*Double.Epsilon) <= 0) continue; result[i] /= count[i]; } var d1 = result.Sum(); if (Math.Abs(d1) < double.Epsilon*100) d1 = 1; var d2 = count.Sum(); if (Math.Abs(d2) < double.Epsilon * 100) d2 = 1; result = result.Select(d => 100 * d / d1).ToArray(); for (int i = 0; i < result.Length; i++) _sumPoints[i] += result[i]; _sumPointsHistory.Add(_sumPoints); count = count.Select(d => 100 * d / d2).ToArray(); return new[] { count, result }; }
public void RenderShaded(Tuple <int, ConsoleColor>[,] screen) { int screenWidth = screen.GetLength(0); int screenHeight = screen.Length / screen.GetLength(0); List <Tuple <Triangle3D, int, int, int, ConsoleColor> > tri = new List <Tuple <Triangle3D, int, int, int, ConsoleColor> >(); foreach (Mesh m in meshes) { // get all the faces, in some random order List <Triangle3D> faces = m.Faces(); //List<Triangle3D> temp = new List<Triangle3D>(); foreach (Triangle3D t in faces) { int l1 = (int)t.V1.getLightValue(lights, camera.ViewVector); int l2 = (int)t.V2.getLightValue(lights, camera.ViewVector); int l3 = (int)t.V3.getLightValue(lights, camera.ViewVector); if (!m.Shaded) { l1 = (int)(new Point3D(t.Center.X, t.Center.Y, t.Center.Z, t.Normal)).getLightValue(lights, camera.ViewVector); l2 = l1; l3 = l2; } //int lightVal = (int)t.getLightValue(lights); //convert to camera space //sort this triangle list Matrix conversion = camera.WorldtoCameraMatrix; Matrix viewConversion = camera.getCameraViewMatrix(); Point3D reference = t.V1; Matrix cameraVersion = reference * conversion; //Matrix cameraVersion = conversion * reference; Matrix v1boxCoords = cameraVersion * viewConversion; Point3D boxV1 = v1boxCoords.boxCoordsToPoint3D(); reference = t.V2; cameraVersion = reference * conversion; Matrix v2boxCoords = cameraVersion * viewConversion; Point3D boxV2 = v2boxCoords.boxCoordsToPoint3D(); reference = t.V3; cameraVersion = reference * conversion; Matrix v3boxCoords = cameraVersion * viewConversion; Point3D boxV3 = v3boxCoords.boxCoordsToPoint3D(); Triangle3D boxTriangle = new Triangle3D(boxV1, boxV2, boxV3); ConsoleColor col = ConsoleColor.White; if (m.Material != null) { col = m.Material.Colour; } //if (Point3D.Dot(camera.ViewVector, t.Normal) > -.5) Tuple <Triangle3D, int, int, int, ConsoleColor> tuple = new Tuple <Triangle3D, int, int, int, ConsoleColor>(boxTriangle, l1, l2, l3, col); tri.Add(tuple); } } List <Tuple <Triangle3D, int, int, int, ConsoleColor> > ordered = tri.OrderBy(o => o.Item1.Center.Z).ToList(); foreach (Tuple <Triangle3D, int, int, int, ConsoleColor> t in ordered) { Triangle3D triTemp = t.Item1; if (triangleInView(triTemp)) { triTemp.Translate(new Point3D(1, 1, 0)); triTemp.Scale(new Point3D(screenWidth / 2, screenHeight / 2, 1)); Triangle2D tri2D = new Triangle2D(new Point2D(triTemp.V1.X, triTemp.V1.Y), new Point2D(triTemp.V2.X, triTemp.V2.Y), new Point2D(triTemp.V3.X, triTemp.V3.Y)); // screen, lightvalue, color if (triangleInBounds(tri2D, screen) && tri2D.Area < 4000) { tri2D.drawTriangleShaded(screen, t.Item2, t.Item3, t.Item4, t.Item5); } } } }
private static void PrintPredecessorMatrix(Tuple<Vector2, Vector2>[,] predecessorMatrix) { System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\gertj\myPredecessorMatrix.txt"); //Print distance matrix for (int j = 0; j < predecessorMatrix.GetLength(0); j++) { string array = ""; Console.Write("["); for (int k = 0; k < predecessorMatrix.GetLength(1); k++) { if (predecessorMatrix[j, k] == null) { array += "X"; Console.Write("X"); } else { array += predecessorMatrix[j, k]; Console.Write(" " + predecessorMatrix[j, k]); } } array += " ]"; Console.Write(" ] \r\n"); file.WriteLine(array); array = ""; } Console.Write(" ] \r\n"); }
private Tuple <Point, char[]>[][] GenererLignes() { Tuple <Point, char[]>[][] lignes = new Tuple <Point, char[]> [charsAnimation.Length * cstStaticFrames][]; //int courant; //int lNum; int sens = 0; //if (this.Source == SourceTuyau.Plafond) //{ // sens = charsAnimation.Length - 1; //} for (int i = 0; i < lignes.GetLength(0); i += cstStaticFrames) { lignes[i] = new Tuple <Point, char[]> [this.Hauteur]; for (int j = 0; j < this.Hauteur; j++) { char[] ligne = new char[this.Largeur]; for (int k = 0; k < ligne.Length; k++) { ligne[k] = charsAnimation[(i / cstStaticFrames + j) % charsAnimation.Length]; //if (k+1 < ligne.Length) //{ // ligne[k + 1] = ' '; //} } lignes[i][j] = new Tuple <Point, char[]>(new Point(0, j), ligne); } for (int i2 = 1; i2 < cstStaticFrames; i2++) { lignes[i + i2] = lignes[i]; } //lignes[i] = new Tuple<Point, char[]>[this.Hauteur]; //lNum = 0; //for (; lNum < lignes[i].Length - cstHauteurBouche - 1; lNum++) //{ // courant = Math.Abs(sens - lNum); // lignes[i][courant] = Tuple.Create(new Point((this.Largeur - cstLargeurTube) / 2, courant), ligneTube); //} //for (; lNum < lignes[i].Length - 1; lNum++) //{ // courant = Math.Abs(sens - lNum); // lignes[i][courant] = Tuple.Create(new Point((this.Largeur - cstLargeurBouche) / 2, courant), ligneBouche); //} } //for (int i = 0; i < charsAnimation.Length; i++) //{ // List<char> animation = new List<char>(); // animation.Add(charsAnimation[i]); // while (animation.Count + 2 <= cstLargeurBouche) // { // animation.AddRange(new[] { ' ', charsAnimation[i] }); // } // courant = Math.Abs(sens - this.Hauteur + 1); // lignes[i * 2][courant] = Tuple.Create(new Point((this.Largeur - cstLargeurBouche) / 2, courant), animation.ToArray()); // lignes[i * 2 + 1][courant] = lignes[i * 2][courant]; // lignes[(i + charsAnimation.Length) * 2][courant] = Tuple.Create(new Point((this.Largeur - cstLargeurBouche) / 2 + 1, courant), animation.ToArray()); // lignes[(i + charsAnimation.Length) * 2 + 1][courant] = lignes[(i + charsAnimation.Length) * 2][courant]; //} if (this.Source == SourceTuyau.Plafond) { return(lignes.Reverse().ToArray()); } return(lignes); }
/// ------------------------------------------------------------------------------------ protected virtual void DrawWave(PaintEventArgs e, Rectangle rc) { if (!e.ClipRectangle.IntersectsWith(rc)) { return; } var channelRects = GetChannelDisplayRectangles(rc).ToArray(); var dyChannelXAxes = new int[_channels]; // Calculate the midpoint of each rectangle. for (int c = 0; c < _channels; c++) { dyChannelXAxes[c] = channelRects[c].Y + (int)Math.Ceiling(channelRects[c].Height / 2f); } // Draw the X axis through middle of each channel's rectangle. using (var pen = new Pen(ForeColor)) { foreach (var xAxis in dyChannelXAxes) { e.Graphics.DrawLine(pen, rc.X, xAxis, rc.Right, xAxis); } } // If samples per pixel is small or less than zero, we are out of zoom range, so don't display anything. if (SamplesPerPixel <= 0.0000000001d) { return; } // SP-998: If _smaplesToDraw is null, it apparently hasn't been set yet. Not sure how this can happen, // and we haven't been able to reproduce it, but let's hope it's a timing issue and // the problem magically corrects itself. if (_samplesToDraw == null) { Logger.WriteEvent("DrawWave called with null _samplesToDraw. Possible timing issue? (See SP-998)"); return; } // Samples will span from some value between -1 and +1, inclusively. // The top of the client area represents +1 and the bottom represents -1. var blend = new Blend(); blend.Positions = new[] { 0f, 0.15f, 0.5f, 0.85f, 1.0f }; blend.Factors = new[] { 0.65f, 0.85f, 1.0f, 0.85f, 0.65f }; for (int x = e.ClipRectangle.X; x < e.ClipRectangle.X + e.ClipRectangle.Width; x++) { if (x < rc.X) { continue; } var sampleToDraw = x + _offsetOfLeftEdge - rc.X; if (sampleToDraw >= _samplesToDraw.GetLength(0)) { break; } for (int channel = 0; channel < _channels; channel++) { var sampleAmplitudes = _samplesToDraw[sampleToDraw, channel]; if (sampleAmplitudes.Item1.Equals(0f) && sampleAmplitudes.Item2.Equals(0f)) { continue; } int y1 = dyChannelXAxes[channel] - (int)Math.Ceiling(channelRects[channel].Height * (sampleAmplitudes.Item1 / 2f)); int y2 = dyChannelXAxes[channel] - (int)Math.Ceiling(channelRects[channel].Height * (sampleAmplitudes.Item2 / 2f)); if (y2 - y1 <= 1) { continue; } var pt1 = new Point(x, y1); var pt2 = new Point(x, y2); using (var br = new LinearGradientBrush(pt1, pt2, BackColor, ForeColor)) { br.Blend = blend; using (var pen = new Pen(br)) e.Graphics.DrawLine(pen, pt1, pt2); } } } }
/// ------------------------------------------------------------------------------------ public void SetSamplesToDraw(Tuple <float, float>[,] samplesToDraw) { _samplesToDraw = samplesToDraw; _channels = samplesToDraw.GetLength(1); SamplesPerPixel = 1d; }
internal static InitialConditionsGrid FromCellArray(Tuple<int,float>[,] cells) { InitialConditionCell[,] arr = new InitialConditionCell[cells.GetLength(0),cells.GetLength(1)]; var list = new List<List<InitialConditionCell>>(); for(int i=0;i<SPDAssets.MAX;i++) list.Add(new List<InitialConditionCell>()); for(int i=0;i<cells.GetLength(0);i++) for (int j = 0; j < cells.GetLength(1); j++) { int k = (new IntegerStrategy(cells[i,j].Item1)).BetrayalThreshold; arr[i,j] = new InitialConditionCell(i,j,k,k); list[k].Add(arr[i, j]); } var arr2 = list.Select(l => l.ToArray()).ToArray(); return new InitialConditionsGrid {CellGrid = arr, CellSets = arr2}; }
/// <summary> /// Inicia a tabela do simplex, colocando os valores das funcoes /// nas devidas posicoes da tabela. /// </summary> public void PopuleTable() { int col = 1; table[0, 0] = new Tuple <double, double>(0, 0); // Insere os elementos fa funcao objetiva columnPositions[0] = "ml"; foreach (var element in objectiveFunction.Transform( )) { table[0, col] = new Tuple <double, double>(element.Item2, 0); columnPositions[col] = element.Item1; col++; } // Insere os elementos das restricoes col = 0; int lin = 1; linePositions[0] = "f(x)"; foreach (var restriction in restrictionsList) { foreach (var element in restriction.Transform((objectiveFunction.Type == ObjectiveFunction.FuncType.Min) ? true : false)) { table[lin, col] = new Tuple <double, double>(element.Item2, 0); linePositions[lin] = "x" + ((table.GetLength(1) - 1) + lin); col++; } lin++; col = 0; } Print( ); }
private bool Inbounds(Tuple <int, ConsoleColor>[,] screen, int x, int y) { return(y >= 0 && y < (screen.Length / screen.GetLength(0)) && x >= 0 && x < screen.GetLength(0)); }
private MapTile[,] tiles; // x,y indexing private bool LoadMapImpl(Tuple <MapTile.TileType, MovingObject.ObjectType>[,] map) { this.width = map.GetLength(1); this.height = map.GetLength(0); tiles = new MapTile[width, height]; ExitTile = null; int actorsCount = 0; int x = 0, y = 0; int index = 0; foreach (var t in map) { x = index % width; y = index / width; index++; MapTile.TileType tileType = t.Item1; MovingObject.ObjectType objectType = t.Item2; var tile = new MapTile(tileType, x, y, index, this); tiles[x, y] = tile; if (tileType == MapTile.TileType.Exit) { if (ExitTile != null) { //Console.WriteLine( "Map exit already defined" ); return(false); } ExitTile = tile; } if (objectType != MovingObject.ObjectType.None) { tile.obj = new MovingObject { type = objectType } } ; if (objectType == MovingObject.ObjectType.Actor) { actors[actorsCount++] = tile; } else if (objectType == MovingObject.ObjectType.AntiActor) { contrActors.Add(tile); } } if (index != width * height) { //Console.WriteLine( "Invalid map data" ); return(false); } if (TestIsOn == false && actorsCount == 0) { //Console.WriteLine( "No actors on map" ); return(false); } if (TestIsOn == false && ExitTile == null) { //Console.WriteLine( "No exit on map" ); return(false); } SetupTileNeighbourhood(); Symmetry = eMapSymmetry.None; FindSymmetry(); var res = CalculateDistanceToExit(); return(res); }
private Biomes[,] DrawMap(Tuple <int, int, int>[,] noise) { Random rnd = new Random(1); int width = noise.GetLength(0), height = noise.GetLength(1); var newNoise = new Biomes[width, height]; //Drawing grass, ocean, mountains for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { var p = new Biomes(); var h = (255 - noise[x, y].Item1) * (255 - noise[x, y].Item2) * (255 - noise[x, y].Item3); if (h <= 130 * 130 * 130) //water { p = Biomes.Ocean; } else if (h > 180 * 180 * 180) // mountains { var v = rnd.Next(4); if (v >= 1) { p = Biomes.Mountains; } else { p = Biomes.Grass; } } else //grass { p = Biomes.Grass; } newNoise[x, y] = p; } } //Drawing desert for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (newNoise[x, y] != Biomes.Ocean && newNoise[x, y] != Biomes.Mountains && newNoise[x, y] != Biomes.Snow) { var v = height / 2 - Math.Abs(height / 2 - y); if (rnd.Next(v) > height / 3) { newNoise[x, y] = Biomes.Desert; } } } } //Drawing rivers for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { var p = newNoise[x, y]; if (p != Biomes.Grass) { var d = rnd.Next(4); int x1 = x, y1 = y; var v1 = rnd.Next(50); if (v1 < 1) { while (newNoise[x1, y1] != Biomes.Ocean && x1 > 2 && x1 < 318 && y1 > 2 && y1 < 158) { newNoise[x1, y1] = Biomes.River; if (d == 0) { var yd = rnd.Next(3) - 1; if (yd == 0 && x1 < 320 - 1) { x1++; } else if (y1 > 0 && y1 < 160 - 1 && newNoise[x1, y1 + yd] != Biomes.River) { y1 += yd; } else if (y1 > 0 && y1 < 160 - 1) { y1 -= yd; } } else if (d == 1) { var xd = rnd.Next(3) - 1; if (xd == 0 && y1 < 160 - 1) { y1++; } else if (x1 > 0 && x1 < 320 - 1 && newNoise[x1 + xd, y1] != Biomes.River) { x1 += xd; } else if (x1 > 0 && x1 < 320 - 1) { x1 -= xd; } } else if (d == 2) { var yd = rnd.Next(3) - 1; if (yd == 0 && x1 > 0) { x1--; } else if (y1 > 0 && y1 < 160 - 1 && newNoise[x1, y1 + yd] != Biomes.River) { y1 += yd; } else if (y1 > 0 && y1 < 160 - 1) { y1 -= yd; } } else { var xd = rnd.Next(3) - 1; if (xd == 0 && y1 > 0) { y1--; } else if (x1 > 0 && x1 < 320 - 1 && newNoise[x1 + xd, y1] != Biomes.River) { x1 += xd; } else if (x1 > 0 && x1 < 320 - 1) { x1 -= xd; } } } } } } } //Drawing snow for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { var v = (y == 0 || y == 159) ? 1 : (y == 1 || y == 158) ? rnd.Next(2) : (y < 5 || y > 155) ? rnd.Next(5) : 0; if ((v == 1 && (y < 2 || y > 157)) || ((v == 1 && y > 1 && y < 158) && ((x < 319 && newNoise[x + 1, y] == Biomes.Snow) || newNoise[x, y + 1] == Biomes.Snow || (x > 0 && newNoise[x - 1, y] == Biomes.Snow) || newNoise[x, y - 1] == Biomes.Snow))) { newNoise[x, y] = Biomes.Snow; } } } //Drawing tundra for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { var v = (y < 3 || y > 156) ? 0 : (y < 40 || y > 120) ? rnd.Next(10) : 0; if (v != 0 && v < 5 && newNoise[x, y] == Biomes.Grass) { newNoise[x, y] = Biomes.Tundra; } } } //Drawing forest for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { var v = (y < 10 || y > 150) ? 0 : (y < 60 || y > 100) ? rnd.Next(10) : rnd.Next(1000); if (v != 0 && v < 5 && noise[x, y] == new Tuple <int, int, int>(0, 150, 0)) { newNoise[x, y] = Biomes.Forest; } } } return(newNoise); }