public static void Unconnect(cord a, cord b) { if (a.a != b.a && a.b != b.b) { return; } if (a.a > b.a || a.b > b.b) { cord c = new cord(b); b = a; a = c; } if (a.b < b.b) { map[a.a, a.b].UnRight(); map[b.a, b.b].UnLeft(); for (int i = a.b + 1; i < b.b; i++) { UnTube(a.a, i); } return; } if (a.a < b.a) { map[a.a, a.b].UnDown(); map[b.a, b.b].UnUp(); for (int i = a.a + 1; i < b.a; i++) { UnTube(i, a.b); } return; } }
List <cord> getRegionTiles(int startX, int startY) { List <cord> tiles = new List <cord>(); int[,] mapFlogs = new int[width, height]; int tiletype = map[startX, startY]; Queue <cord> queue = new Queue <cord>(); queue.Enqueue(new cord(startX, startY)); mapFlogs[startX, startY] = 1; while (queue.Count > 0) { cord tile = queue.Dequeue(); tiles.Add(tile); for (int x = tile.tileX - 1; x <= tile.tileX + 1; x++) { for (int y = tile.tileY - 1; y <= tile.tileY + 1; y++) { if (isInMapRabge(x, y) && (y == tile.tileY || x == tile.tileX)) { if (mapFlogs[x, y] == 0 && map[x, y] == tiletype) { mapFlogs[x, y] = 1; queue.Enqueue(new cord(x, y)); } } } } } return(tiles); }
cord Getlowest() { if (Open.Count != 0) { cord returncord = Open[0]; float low = returncord.CostSoFar; if (Open.Count > 1) { for (int i = 1; i < Open.Count; ++i) { if (Open[i].CostSoFar < low) { returncord = Open[i]; low = returncord.CostSoFar; } } } return(returncord); } else { return(null); } }
public void runX(cord s, int x) { Open.Clear(); Closed.Clear(); Start = s; Startcord(s); Target = null; AddtoOpen(Start); bool NoPath = false; for (int i = 0; i < x; i++) { cord c = Getlowest(); if (c != Target) { AddtoOpen(c); AddtoClose(c); } else { //MapGenerator.Map[c.X, c.Y].SetTexture(TerrainTypes.Coast); Debug.Log("done"); path(Target); break; } } }
public static cord[] Connect(cord a, cord b) { List <cord> temp = new List <cord>(); if (a.a != b.a && a.b != b.b) { return(null); } if (a.a > b.a || a.b > b.b) { cord c = new cord(b); b = a; a = c; } if (a.b < b.b) { for (int i = a.b; i <= b.b; i++) { temp.Add(new cord(a.a, i)); } } if (a.a < b.a) { for (int i = a.a; i <= b.a; i++) { temp.Add(new cord(i, a.b)); } } return(temp.ToArray()); }
List <cord> getLine(cord from, cord to) { List <cord> line = new List <cord>(); int x = from.tileX; int y = from.tileY; int dx = to.tileX - from.tileX; int dy = to.tileY - from.tileY; bool inverted = false; int step = Math.Sign(dx); int gradientStep = Math.Sign(dy); int longest = Mathf.Abs(dx); int shortest = Mathf.Abs(dy); if (longest < shortest) { inverted = true; longest = Mathf.Abs(dy); shortest = Mathf.Abs(dx); step = Math.Sign(dy); gradientStep = Math.Sign(dx); } int gradientAccumulation = longest / 2; for (int i = 0; i < longest; i++) { line.Add(new cord(x, y)); if (inverted) { y += step; } else { x += step; } gradientAccumulation += shortest; if (gradientAccumulation >= longest) { if (inverted) { x += gradientStep; } else { y += gradientStep; } gradientAccumulation -= longest; } } return(line); }
void createPassage(Room roomA, Room roomB, cord tileA, cord tileB) { Room.connectRooms(roomA, roomB); List <cord> line = getLine(tileA, tileB); foreach (cord elem in line) { drawCircle(elem, radius); } }
bool IsTarget(List <cord> t, cord c) { foreach (cord target in t) { if (c == target) { Target = target; return(true); } } return(false); }
public void setup() { W = MapGenerator.Map.GetLength(0); H = MapGenerator.Map.GetLength(1); map = new cord[H, W]; for (int i = 0; i < W; i++) { for (int b = 0; b < H; b++) { map[i, b] = new cord(); map[i, b].cost = UnityEngine.Random.Range(1, 20); map[i, b].X = i; map[i, b].Y = b; } } for (int i = 0; i < W; i++) { for (int b = 0; b < H; b++) { try { map[i, b].nabours.Add(map[i - 1, b]); } catch { }; try { map[i, b].nabours.Add(map[i + 1, b]); } catch { }; //right try { map[i, b].nabours.Add(map[i, b + 1]); } catch { }; //left try { map[i, b].nabours.Add(map[i, b - 1]); } catch { }; } } //Start = map[50, 50]; //Start = map[map.GetLength(] //Target = map[90, 90]; }
void AddtoOpen(cord c) { if (!(c.cost == 1000)) { foreach (cord cc in c.nabours) { if (c.nabours.Count > 0) { if (!Open.Contains(cc) && !Closed.Contains(cc)) { Open.Add(cc); cc.CostSoFar = c.CostSoFar + cc.cost; cc.root = c; if (cc != Target) { if (ChangeOnsearch) { if (!(MapGenerator.Map[cc.X, cc.Y].TerrainType == DontChange)) { if (MapGenerator.Map[cc.X, cc.Y].TerrainType == OnlyChange || ChangeAll) { MapGenerator.Map[cc.X, cc.Y].TerrainType = T; MapGenerator.Map[cc.X, cc.Y].SetTexture(T); } } } } } else if ((cc.CostSoFar) > (c.CostSoFar + cc.cost)) { cc.CostSoFar = c.CostSoFar + cc.cost; cc.root = c; if (Closed.Contains(c)) { Closed.Remove(cc); Open.Add(cc); if (cc != Target) { // MapGenerator.Map[cc.X, cc.Y].SetTexture(TerrainTypes.D); } } } } } } }
public void path(cord c) { if (c != Start) { //c.CostSoFar = 1000; if (ChangeTerrainOnTrail) { try { MapGenerator.Map[c.X, c.Y].TerrainType = T; MapGenerator.Map[c.X, c.Y].SetTexture(T); } catch { Debug.Log("ErrorPath"); } } path(c.root); } }
private static void Print(cord i) { if (i.what_to_do) { MapGenerator.map[i.a, i.b].level++; MapGenerator.players[1]++; } else { MapGenerator.players[1] += MapGenerator.map[i.a, i.b].level + 1; if (MapGenerator.map[i.a, i.b].owner == 0) { MapGenerator.players[0] -= (MapGenerator.map[i.a, i.b].level + 1); } MapGenerator.map[i.a, i.b].owner = (MapGenerator.turn ? 1 : 0); } MapGenerator.turn_count--; }
void drawCircle(cord c, int r) { for (int x = -r; x <= r; x++) { for (int y = -r; y <= r; y++) { if (x * x + y * y <= r * r) { int realX = c.tileX + x; int realY = c.tileY + y; if (isInMapRabge(realX, realY)) { map[realX, realY] = 0; } } } } }
public IEnumerator Run() { Startcord(Start); AddtoOpen(Start); yield return(null); bool ReachedDestination = false; bool noValidPath = false; HexTile DestinaitionReached = null; while (ReachedDestination == false) { cord c = Getlowest(); if (c != Target) { AddtoOpen(c); AddtoClose(c); } else if (c == Target) { foreach (cord b in Open) { if (b == Target) { Debug.Log("1done"); break; } } Debug.Log("2done"); break; } else { Debug.Log("3done"); } yield return(null); } }
public void runToHit(cord s, List <cord> Tlist) { Reset(); Open.Clear(); Closed.Clear(); Start = s; Startcord(s); List <cord> targets = Tlist; //Target = t; AddtoOpen(Start); bool NoPath = false; while (true) { cord c = Getlowest(); if (!IsTarget(Tlist, c) && c != null) { AddtoOpen(c); AddtoClose(c); } else if (c == null) { NoPath = true; Debug.Log("NoPathFound"); break; } else { //MapGenerator.Map[c.X, c.Y].SetTexture(TerrainTypes.Coast); path(Target); break; } } }
public void run(cord s, cord t) { Open.Clear(); Closed.Clear(); Start = s; Startcord(s); Target = t; AddtoOpen(Start); bool NoPath = false; while (true) { cord c = Getlowest(); if (c != Target && c != null) { AddtoOpen(c); AddtoClose(c); } else if (c == null) { NoPath = true; Debug.Log("NoPathFound"); break; } else { //MapGenerator.Map[c.X, c.Y].SetTexture(TerrainTypes.Coast); Debug.Log("done"); path(Target); break; } } }
void Startcord(cord c) { c.CostSoFar = 0; Closed.Add(c); }
private void addCords(int arrayNo, cord clickedCord, int penSize, cord topLeftCord) { int runTime = penSize * penSize; cord bottomRightCord = new cord(topLeftCord.X + penSize, topLeftCord.Y + penSize); cord[] workingCords = new cord[runTime]; int properPix = 0; for (int x = 0; x < penSize; x++) { for (int y = 0; y < penSize; y++) { int currentElement = x * 10 + y; cord setCord = new cord(topLeftCord.X + x, topLeftCord.Y + y); workingCords[currentElement] = setCord; } } for (int i = 0; i < penSize; i++) { for (int b = 0; b < penSize; b++) { cord testCord = new cord(topLeftCord.X + i, topLeftCord.Y + b); bool cordInCircle = insideCircle(topLeftCord, penSize / 2, testCord); int currentElement = i * 10 + b; if (cordInCircle == true) { properPix++; } else { workingCords[currentElement] = null; } } } }
private void moveCordsRight(cord[] currentCords, int pixToMove) { cord[] rightMoveCords = new cord[currentCords.Length]; System.Drawing.Drawing2D.GraphicsPath erasePath = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Drawing2D.GraphicsPath nextPath = new System.Drawing.Drawing2D.GraphicsPath(); erasePath.StartFigure(); nextPath.StartFigure(); for (int i = 0; i < currentCords.Length; i++) { // x - pixToMove cord currentEditCord = new cord(currentCords[i].X, currentCords[i].Y); cord nextCord = new cord(currentEditCord.X + pixToMove, currentEditCord.Y); rightMoveCords[i].X = nextCord.X; rightMoveCords[i].Y = nextCord.Y; } for (int b = 0; b < currentCords.Length; b++) { graphics = pictureBox1.CreateGraphics(); graphics.FillRectangle(whiteSol, currentCords[b].X, currentCords[b].Y, 1, 1); } for (int c = 0; c < currentCords.Length; c++) { graphics = pictureBox1.CreateGraphics(); graphics.FillRectangle(blackSol, rightMoveCords[c].X, rightMoveCords[c].Y, 1, 1); } nextPath.CloseFigure(); erasePath.CloseFigure(); }
void Form1_MouseMove(object sender, MouseEventArgs e) { cord cursor = new cord(e.X, e.Y); string text = "x = " + cursor.X + ", y = " + cursor.Y; label1.Text = text; }
public void prototypeMarkerSpotColor(string color, cord cursorPoint, int diameterSZ) { int radius = diameterSZ / 2; string[] colorList = new string[4]; colorList[0] = "Black"; colorList[1] = "White"; colorList[2] = "Blue"; colorList[3] = "Red"; int colorNo; for (int i = 0; i < colorList.Length; i++) { if (colorList[i] == color) { colorNo = i + 1; } } }
/// <summary> /// подготовливает к рисаниваю график /// </summary> /// <param name="rdouble">Массив радиусов</param> /// <param name="R_double">R большое</param> /// <returns>true - если выполнено успешно, false - ошибка при выполнении</returns> public bool ShowGraphW(double[] rdouble, double R_double) { List <cord> list = new List <cord>(); cord cor = new cord(); cor.y = 1; cor.x = (float)rdouble[0]; list.Add(cor); int proc100 = rdouble.Length; for (int i = 1; i < rdouble.Length; i++) { bool ifi = true; for (int j = 0; j < list.Count; j++) { if (Math.Abs(list[j].x - rdouble[i]) < 0.9) { cor = list[j]; cor.y = cor.y + 1; list[j] = cor; ifi = false; break; } } if (ifi) { cor = new cord(); cor.y = 1; cor.x = (float)rdouble[i]; list.Add(cor); } } //for (int i = 0; i < list.Count; i++) Parallel.For(0, list.Count, (i, state) => { float p = list[i].y; p = p * 100 / proc100; cord cordi = list[i]; cordi.y = p; list[i] = cordi; }); float[] xline = new float[list.Count]; float[] yline = new float[list.Count]; float procmax = 0; float min = list[0].x, max = list[0].x; for (int i = 0; i < list.Count - 1; i++) { int ifi = -1; cord t1 = list[i]; for (int j = i + 1; j < list.Count; j++) { if (t1.x > list[j].x) { t1 = list[j]; ifi = j; } } if (ifi != -1) { cord c = list[i]; list[i] = list[ifi]; list[ifi] = c; } } Parallel.For(0, list.Count, (i, state) => { if (min > list[i].x) { min = list[i].x; } if (max < list[i].x) { max = list[i].x; } xline[i] = list[i].x; yline[i] = list[i].y; if (procmax < yline[i]) { procmax = yline[i]; } }); procmax = (float)(procmax * 1.5); Thread thread = new Thread(delegate() { retth: bool ifi = TwoDGraphPaint(xline, yline, min, max, min, (float)(max / 10), 0, (int)procmax, 0, (int)(procmax / 10), "w(r) = ", ""); if (ifi == false) { goto retth; } }); thread.Name = "TwoGraph"; thread.Start(); return(true); }
Vector3 cordToWordPoint(cord tile) { return(new Vector3(-width / 2 + .5f + tile.tileX, 2, -height / 2 + .5f + tile.tileY)); }
public void updateRegion() { int selectedIn = comboBox1.SelectedIndex; int brushSize; cord cursor = new cord(cursorCordPts.X, cursorCordPts.Y); if (picBoxClick == true && selectedIn < 11 && fileExists && allTools.pen.selected == true) { selectedIn = comboBox1.SelectedIndex; int selectedColor = comboBox2.SelectedIndex; brushSize = sizes[selectedIn]; if (aDown == true) { brushSize = brushSize * 2; } addCurrentMarkerSpotCirRegion(cursor, brushSize); if (strokeNum == 1) { int radius = brushSize / 2; cord centerCord = new cord(cursor.X - radius, cursor.Y - radius); cord[] drawnCordsToAdd = calculateCircle(centerCord, brushSize); for (int i = 0; i < drawnCordsToAdd.Length; i++) { currentStrokeCordsA[currentStrokeANum] = drawnCordsToAdd[i]; currentStrokeANum++; } //firstGPath.AddEllipse(cursor.X, cursor.Y, brushSize, brushSize); } if (strokeNum == 2) { int radius = brushSize / 2; cord centerCord = new cord(cursor.X - radius, cursor.Y - radius); cord[] drawnCordsToAdd = calculateCircle(centerCord, brushSize); for (int i = 0; i < drawnCordsToAdd.Length; i++) { currentStrokeCordsA[currentStrokeBNum] = drawnCordsToAdd[i]; currentStrokeBNum++; } } } if (picMsUp == true) { picBoxClick = false; strokeNum++; } else { if (firstMark == false && selectedIn < 11 && fileExists && allTools.pen.selected == true) { selectedIn = comboBox1.SelectedIndex; brushSize = sizes[selectedIn]; if (aDown == true) { brushSize = brushSize * 2; } int selectedColorIn = comboBox2.SelectedIndex; string color = availibleColors[selectedColorIn]; int[] rgb = new int[3]; int alpha = int.Parse(textBox1.Text); regionUpdateColors(color, cursor); } else { firstMark = false; } } prevCord.X = cursor.X; prevCord.Y = cursor.Y; }
public void lineRenderConnect(int selectedIn, int brushSize, cord cursor) { if (firstMark == false && selectedIn < 11 && fileExists && allTools.pen.selected == true) { selectedIn = comboBox1.SelectedIndex; brushSize = sizes[selectedIn]; if (aDown == true) { brushSize = brushSize * 2; } int selectedColorIn = comboBox2.SelectedIndex; string color = availibleColors[selectedColorIn]; int[] rgb = new int[3]; int alpha = int.Parse(textBox1.Text); if (color == "Black") { rgb[0] = 0; rgb[1] = 0; rgb[2] = 0; } else { if (color == "White") { rgb[0] = 255; rgb[1] = 255; rgb[2] = 255; } else { if (color == "Blue") { rgb[0] = 0; rgb[1] = 0; rgb[2] = 255; } else { if (color == "Red") { rgb[0] = 255; rgb[1] = 0; rgb[2] = 0; } } } } System.Drawing.Pen customSize = new System.Drawing.Pen(Color.FromArgb(alpha, rgb[0], rgb[1], rgb[2]), brushSize); System.Drawing.Pen customWSize = new System.Drawing.Pen(Color.FromArgb(255, 255, 255, 255), brushSize); graphics = pictureBox1.CreateGraphics(); //graphics.DrawLine(customWSize, prevCord.X, prevCord.Y, cursor.X, cursor.Y); //graphics.DrawLine(customSize, prevCord.X, prevCord.Y, cursor.X, cursor.Y); pathToRender.StartFigure(); pathToRender.AddLine(prevCord.X, prevCord.Y, cursor.X, cursor.Y); } else { firstMark = false; } }
public void setTestPathClear(int method, cord[] coordinates) { cord[] usingCords; if (method == 0) { usingCords = new cord[coordinates.Length]; testPath.StartFigure(); for (int i = 0; i < coordinates.Length; i++) { usingCords[i].X = coordinates[i].X; usingCords[i].Y = coordinates[i].Y; } Point[] cordsForPolygon = new Point[usingCords.Length]; for (int i = 0; i < usingCords.Length; i++) { cordsForPolygon[i].X = usingCords[i].X; cordsForPolygon[i].Y = usingCords[i].Y; } testPath.AddPolygon(cordsForPolygon); } else { if (method == 1) { usingCords = new cord[1]; usingCords[0].X = 0; usingCords[0].Y = 0; testPath = new GraphicsPath(); } } }
void pictureBox1_MouseWheel(object sender, MouseEventArgs e) { if (allTools.zoom.selected == true) { if (e.Delta != 0) { if (e.Delta <= 0) { zoomOut(); } else { cord mouseCord = new cord(e.X, e.Y); zoomIn(mouseCord); } } } }
public void regionUpdateColors(string color, cord cursor) { if (color == "Black") { if (renderRegionInitial[0] == false) { blackDefPath.StartFigure(); renderRegionInitial[0] = true; } blackDefPath.AddLine(prevCord.X, prevCord.Y, cursor.X, cursor.Y); } else { if (color == "White") { if (renderRegionInitial[1] == false) { whiteDefPath.StartFigure(); renderRegionInitial[1] = true; } whiteDefPath.AddLine(prevCord.X, prevCord.Y, cursor.X, cursor.Y); } else { if (color == "Blue") { if (renderRegionInitial[2] == false) { blueDefPath.StartFigure(); renderRegionInitial[2] = true; } blueDefPath.AddLine(prevCord.X, prevCord.Y, cursor.X, cursor.Y); } else { if (color == "Red") { if (renderRegionInitial[3] == false) { redDefPath.StartFigure(); renderRegionInitial[3] = true; } redDefPath.AddLine(prevCord.X, prevCord.Y, cursor.X, cursor.Y); } } } } }
public void prototypePicBoxRendering(object sender, MouseEventArgs e) { cord cursor = new cord(e.X, e.Y); cursorCordPts.X = e.X; cursorCordPts.Y = e.Y; string text = "x = " + cursor.X + ", y = " + cursor.Y; label1.Text = text; int selectedIn = comboBox1.SelectedIndex; //regionRenderLoop(); int brushSize; if (picBoxClick == true && selectedIn < 11 && fileExists && allTools.pen.selected == true) { selectedIn = comboBox1.SelectedIndex; int selectedColor = comboBox2.SelectedIndex; brushSize = sizes[selectedIn]; if (aDown == true) { brushSize = brushSize * 2; } drawCurrentMarkerSpotCir(cursor, brushSize); if (strokeNum == 1) { int radius = brushSize / 2; cord centerCord = new cord(cursor.X - radius, cursor.Y - radius); cord[] drawnCordsToAdd = calculateCircle(centerCord, brushSize); for (int i = 0; i < drawnCordsToAdd.Length; i++) { currentStrokeCordsA[currentStrokeANum] = drawnCordsToAdd[i]; currentStrokeANum++; } drawCurrentMarkerSpotCir(cursor, brushSize); //firstGPath.AddEllipse(cursor.X, cursor.Y, brushSize, brushSize); } if (strokeNum == 2) { int radius = brushSize / 2; cord centerCord = new cord(cursor.X - radius, cursor.Y - radius); cord[] drawnCordsToAdd = calculateCircle(centerCord, brushSize); for (int i = 0; i < drawnCordsToAdd.Length; i++) { currentStrokeCordsA[currentStrokeBNum] = drawnCordsToAdd[i]; currentStrokeBNum++; } } } if (picMsUp == true) { picBoxClick = false; strokeNum++; } else { if (firstMark == false && selectedIn < 11 && fileExists && allTools.pen.selected == true) { selectedIn = comboBox1.SelectedIndex; brushSize = sizes[selectedIn]; if (aDown == true) { brushSize = brushSize * 2; } int selectedColorIn = comboBox2.SelectedIndex; string color = availibleColors[selectedColorIn]; int[] rgb = new int[3]; int alpha = int.Parse(textBox1.Text); if (color == "Black") { rgb[0] = 0; rgb[1] = 0; rgb[2] = 0; } else { if (color == "White") { rgb[0] = 255; rgb[1] = 255; rgb[2] = 255; } else { if (color == "Blue") { rgb[0] = 0; rgb[1] = 0; rgb[2] = 255; } else { if (color == "Red") { rgb[0] = 255; rgb[1] = 0; rgb[2] = 0; } } } } System.Drawing.Pen customSize = new System.Drawing.Pen(Color.FromArgb(alpha, rgb[0], rgb[1], rgb[2]), brushSize); System.Drawing.Pen customWSize = new System.Drawing.Pen(Color.FromArgb(255, 255, 255, 255), brushSize); graphics = pictureBox1.CreateGraphics(); graphics.DrawLine(customWSize, prevCord.X, prevCord.Y, cursor.X, cursor.Y); graphics.DrawLine(customSize, prevCord.X, prevCord.Y, cursor.X, cursor.Y); } else { firstMark = false; } } prevCord.X = cursor.X; prevCord.Y = cursor.Y; }
void AddtoClose(cord c) { Open.Remove(c); Closed.Add(c); }
public bool insideCircle(cord circle, int circleR, cord testCord) { int distX = 0; int distY = 0; if (circle.X < testCord.X) { distX = testCord.X - circle.X; } else { if (circle.X > testCord.X) { distX = circle.X - testCord.X; } else { if (circle.X == testCord.X) { distX = 0; } } } if (circle.Y < testCord.Y) { distY = testCord.Y - circle.Y; } else { if (circle.Y > testCord.Y) { distY = circle.Y - testCord.Y; } else { if (circle.Y == testCord.Y) { distY = 0; } } } int compDist = distX * distX + distY * distY; if (compDist == circleR * circleR || compDist < circleR * circleR) { return true; } else { return false; } }
public void zoomIn(cord mouseCord) { if (zoomStateOut == true) { cord topLeftCord = new cord(0, 0); if (mouseCord.X < 120) { topLeftCord.X = 0; } else { if (mouseCord.Y < 120) { topLeftCord.Y = 0; } else { topLeftCord.X = mouseCord.X - 120; topLeftCord.Y = mouseCord.Y - 120; } } Rectangle cropSection = new Rectangle(topLeftCord.X, topLeftCord.Y, 240, 240); Bitmap croppedPiece = cropImagePiece(cropSection, pictureBoxPic); Graphics g = pictureBox1.CreateGraphics(); g.FillRectangle(whiteSol, 0, 0, 2000, 2000); Rectangle drawRect = new Rectangle(0, 0, 500, 500); g.DrawImage(croppedPiece, drawRect); zoomStateOut = false; } }
public void drawCurrentMarkerSpotCir(cord curPos, int sizePX) { int radius = sizePX / 2; graphics = pictureBox1.CreateGraphics(); //graphics.FillEllipse(whiteSol, curPos.X, curPos.Y, sizePX, sizePX); int selectedColorIn = comboBox2.SelectedIndex; string color = availibleColors[selectedColorIn]; int[] rgb = new int[3]; int alpha = int.Parse(textBox1.Text); if (color == "Black") { rgb[0] = 0; rgb[1] = 0; rgb[2] = 0; } else { if (color == "White") { rgb[0] = 255; rgb[1] = 255; rgb[2] = 255; } else { if (color == "Blue") { rgb[0] = 0; rgb[1] = 0; rgb[2] = 255; } else { if (color == "Red") { rgb[0] = 255; rgb[1] = 0; rgb[2] = 0; } } } } System.Drawing.SolidBrush customBrush = new System.Drawing.SolidBrush(Color.FromArgb(alpha, rgb[0], rgb[1], rgb[2])); System.Drawing.SolidBrush customWBrush = new System.Drawing.SolidBrush(Color.FromArgb(255, 255, 255, 255)); graphics.FillEllipse(customWBrush, curPos.X - radius, curPos.Y - radius, sizePX, sizePX); graphics.FillEllipse(customBrush, curPos.X - radius, curPos.Y - radius, sizePX, sizePX); }
public cord[] calculateCircle(cord placeClicked, int size) { cord[] validTestCords = new cord[size * size]; int radius = size / 2; cord topLeftCord = new cord(placeClicked.X - radius, placeClicked.Y - radius); int allowedAmount = 0; for (int i = 0; i < size; i++) { for (int b = 0; b < size; b++) { cord currentCord = new cord(topLeftCord.X + i, topLeftCord.Y + b); validTestCords[i * 10 + b].X = currentCord.X; validTestCords[i * 10 + b].Y = currentCord.Y; } } for (int z = 0; 0 < size * size; z++) { cord testInsideCircle = new cord(validTestCords[z].X, validTestCords[z].Y); bool cordInCircle = insideCircle(topLeftCord, radius, testInsideCircle); if (cordInCircle == true) { allowedAmount++; } else { validTestCords[z] = null; } } cord[] realCords = new cord[allowedAmount]; int counter = 0; for (int h = 0; h < size * size; h++) { if (validTestCords[h] == null) { validTestCords[h].X = 0; validTestCords[h].Y = 0; } else { realCords[counter].X = validTestCords[h].X; realCords[counter].Y = validTestCords[h].Y; } } return realCords; }
public void markerSpotColor(string color, cord curPos, int radius, int sizePX) { if (color == "Black") { if (renderRegionInitial[0] == false) { cord centerCord = new cord(curPos.X, curPos.Y); Rectangle renderCenter = new Rectangle(centerCord.X, centerCord.Y, 1, 1); blackDefPath = new GraphicsPath(); blackDefPath.StartFigure(); blackDefPath.AddRectangle(renderCenter); renderRegionInitial[0] = true; } blackDefPath.StartFigure(); blackDefPath.AddEllipse(curPos.X - radius, curPos.Y - radius, sizePX, sizePX); } else { if (color == "White") { if (renderRegionInitial[1] == false) { Rectangle renderCenter = new Rectangle(curPos.X, curPos.Y, 1, 1); whiteDefPath = new GraphicsPath(); whiteDefPath.StartFigure(); whiteDefPath.AddRectangle(renderCenter); renderRegionInitial[1] = true; } whiteDefPath.StartFigure(); whiteDefPath.AddEllipse(curPos.X - radius, curPos.Y - radius, sizePX, sizePX); } else { if (color == "Blue") { if (renderRegionInitial[2] == false) { cord centerCord = new cord(curPos.X, curPos.Y); Rectangle renderCenter = new Rectangle(centerCord.X, centerCord.Y, 1, 1); blueDefPath = new GraphicsPath(); blueDefPath.StartFigure(); blueDefPath.AddRectangle(renderCenter); renderRegionInitial[2] = true; } blueDefPath.StartFigure(); blueDefPath.AddEllipse(curPos.X - radius, curPos.Y - radius, sizePX, sizePX); } else { if (color == "Red") { if (renderRegionInitial[3] == false) { cord centerCord = new cord(curPos.X, curPos.Y); Rectangle renderCenter = new Rectangle(centerCord.X, centerCord.Y, 1, 1); redDefPath = new GraphicsPath(); redDefPath.StartFigure(); redDefPath.AddRectangle(renderCenter); renderRegionInitial[3] = true; } redDefPath.StartFigure(); redDefPath.AddEllipse(curPos.X - radius, curPos.Y - radius, sizePX, sizePX); } } } } }
public void updateEllipsesDrawing(cord mouseClickedSpot) { int selectedIn = comboBox1.SelectedIndex; int brushSize = sizes[selectedIn]; if (aDown == true) { brushSize = brushSize * 2; } int elipRadius = brushSize / 2; cord elipCorner = new cord(0, 0); elipCorner.X = mouseClickedSpot.X - elipRadius; elipCorner.Y = mouseClickedSpot.Y - elipRadius; currentMarkPath.StartFigure(); currentMarkPath.AddEllipse(elipCorner.X, elipCorner.Y, brushSize, brushSize); }
public void updateInbetweenLines(cord previousCord, cord newCord) { }
public cord(cord c) { a = c.a; b = c.b; }
private System.Drawing.Drawing2D.GraphicsPath setGraphicsPath(cord[] setCords) { System.Drawing.Drawing2D.GraphicsPath returnPath = new System.Drawing.Drawing2D.GraphicsPath(); returnPath.StartFigure(); for (int i = 0; i < setCords.Length; i++) { Rectangle pixRect = new Rectangle(setCords[i].X, setCords[i].Y, 1, 1); cPath.AddRectangle(pixRect); } return returnPath; }
public void addCurrentMarkerSpotCirRegion(cord curPos, int sizePX) { int radius = sizePX / 2; int selectedColorIn = comboBox2.SelectedIndex; string color = availibleColors[selectedColorIn]; markerSpotColor(color, curPos, radius, sizePX); }
void connectClosestRooms(List <Room> allRooms, bool forceAccessibilityFromMainRoom = false) { List <Room> roomListA = new List <Room>(); List <Room> roomListB = new List <Room>(); if (forceAccessibilityFromMainRoom) { foreach (Room room in allRooms) { if (room.isAssessableFromMainRoom) { roomListB.Add(room); } else { roomListA.Add(room); } } } else { roomListA = allRooms; roomListB = allRooms; } int bestDistance = 0; cord bestTileA = new cord(); cord bestTileB = new cord(); Room bestRoomA = new Room(); Room bestRoomB = new Room(); bool possibleConectionFound = false; foreach (Room roomA in roomListA) { if (!forceAccessibilityFromMainRoom) { possibleConectionFound = false; if (roomA.connectedRoom.Count > 0) { continue; } } foreach (Room roomB in roomListB) { if (roomA == roomB || roomA.isConnected(roomB)) { continue; } for (int tileIndexA = 0; tileIndexA < roomA.edgeTiles.Count; tileIndexA++) { for (int tileIndexB = 0; tileIndexB < roomB.edgeTiles.Count; tileIndexB++) { cord tileA = roomA.edgeTiles[tileIndexA]; cord tileB = roomB.edgeTiles[tileIndexB]; int distanceBetweenRooms = (int)(Mathf.Pow(tileA.tileX - tileB.tileX, 2) + Mathf.Pow(tileA.tileY - tileB.tileY, 2)); if (distanceBetweenRooms < bestDistance || !possibleConectionFound) { bestDistance = distanceBetweenRooms; possibleConectionFound = true; bestTileA = tileA; bestTileB = tileB; bestRoomA = roomA; bestRoomB = roomB; } } } } if (possibleConectionFound && !forceAccessibilityFromMainRoom) { createPassage(bestRoomA, bestRoomB, bestTileA, bestTileB); } } if (possibleConectionFound && forceAccessibilityFromMainRoom) { createPassage(bestRoomA, bestRoomB, bestTileA, bestTileB); connectClosestRooms(allRooms, true); } if (!forceAccessibilityFromMainRoom) { connectClosestRooms(allRooms, true); } }
public Path(int[] path) { this.path = path; List <cord> coords = PathInCord(path).ToList(); bool horz = true; List <cord> temp = new List <cord>(); blocks = new List <cord[]>(); for (int i = 0; i < coords.Count; i++) { cord dum = coords[i]; if (i == 0) { temp.Add(coords[i]); continue; } if (horz == true) { if (dum.b != temp.Last().b || i == coords.Count - 1) { horz = false; if (i != 0 && (temp.Count != 1 || i == coords.Count - 1)) { if (temp[0] != coords[i] && i == coords.Count - 1) { if (coords[i].a == temp[0].a || coords[i].b == temp[0].b) { temp.Add(coords[i]); } else { i--; } } blocks.Add(temp.ToArray()); temp = new List <cord>(); } } } else { if (dum.a != temp.Last().a || i == coords.Count - 1) { horz = true; if (temp.Count != 1 || i == coords.Count - 1) { if (temp[0] != coords[i] && i == coords.Count - 1) { if (coords[i].a == temp[0].a || coords[i].b == temp[0].b) { temp.Add(coords[i]); } else { i--; } } blocks.Add(temp.ToArray()); temp = new List <cord>(); } } } temp.Add(dum); } }
public void renderSquareBrush(cord mouseClickedSpot, int penSize) { int selectedIn = comboBox1.SelectedIndex; int brushSize = sizes[selectedIn]; if (aDown == true) { brushSize = brushSize * 2; } int rectRadius = penSize / 2; cord rectCorner = new cord(0, 0); rectCorner.X = mouseClickedSpot.X - rectRadius; rectCorner.Y = mouseClickedSpot.Y - rectRadius; currentMarkPath.StartFigure(); Rectangle renderArea = new Rectangle(rectCorner.X, rectCorner.Y, penSize, penSize); currentMarkPath.AddRectangle(renderArea); }