//sets clicked cell to alive private void PB_main_Click(object sender, EventArgs e) { Point cellId = GetCellCoords(PB_main.PointToClient(MousePosition)); map[cellId.X, cellId.Y].SetAlive(); PB_main.Refresh(); }
private void TIM_clock_Tick(object sender, EventArgs e) { int avgx1, avgy1, avgx2, avgy2; int sumx1 = 0, sumy1 = 0, sumx2 = 0, sumy2 = 0; Point[] targets = new Point[0]; Random rng = new Random(); int n = 0; foreach (Bird bi in b) { if (n % 2 == 0) { sumx1 += bi.Pos.X; sumy1 += bi.Pos.Y; } else { sumx2 += bi.Pos.X; sumy2 += bi.Pos.Y; } n++; } avgx1 = sumx1 / (n / 2); avgy1 = sumy1 / (n / 2); avgx2 = sumx2 / (n / 2); avgy2 = sumy2 / (n / 2); //int rad = 1; //while (targets.Count() < 3) //{ // targets = GetTargets(rad, clumpDensity); // rad++; //} n = rng.Next(0, 2); foreach (Bird bi in b) { //double distMin = PB_main.Width; Point t; if (n % 2 == 0) { t = new Point(avgx1, avgy1); } else { t = new Point(avgx2, avgy2); } //foreach (Point target in targets) //{ // int diffx, diffy; // double dist; // diffx = bi.Pos.X - target.X; diffy = bi.Pos.Y - target.Y; // dist = Math.Sqrt(Math.Pow(diffx, 2) + Math.Pow(diffy, 2)); // if (dist < distMin) // { // distMin = dist; // t = target; // } //} bi.Step(new Point(t.X, t.Y), new Point(rng.Next(-maxWSpeed, maxWSpeed + 1), rng.Next(-maxWSpeed, maxWSpeed + 1)), rng.Next(-1, 2)); n++; } PB_main.Refresh(); }
private void TIM_main_Tick(object sender, EventArgs e) { foreach (Boio boio in boios) { boio.Step(alignment, seperation, cohesion, boios.ToArray(), ref rng); } PB_main.Refresh(); }
private void TIM_main_Tick(object sender, EventArgs e) { foreach (Growth growth in growths) { growth.Step(); } PB_main.Refresh(); }
//debug method - keeping in case //private void FRM_render_KeyPress(object sender, KeyPressEventArgs e) //{ // //ENTER // if (e.KeyChar == (char)13) // { // Point mouse = PB_main.PointToClient(MousePosition); // MessageBox.Show(mouse.X.ToString() + ", " + mouse.Y.ToString() + ": " + zBuffer[mouse.X, mouse.Y].ToString()); // float[] bary = GetBary(testTris[0], new Vect3(mouse.X, mouse.Y, -1)); // MessageBox.Show(bary[0] + ", " + bary[1] + ", " + bary[2]); // } //} private void PB_main_MouseDown(object sender, MouseEventArgs e) { rotationSpeed = 0; TSL_rotateSpeed.Text = "0"; //set rotation base rotationBase = PB_main.PointToClient(MousePosition); //start the rotation timer to correct rotation every tick TIM_rotate.Enabled = true; }
private void TIM_animate_Tick(object sender, EventArgs e) { ratioLine = positions[positionIndex]; positionIndex++; if (positionIndex >= positions.Length) { TIM_animate.Enabled = false; } PB_main.Refresh(); }
//toolbarpics private void TS_clear_Click(object sender, EventArgs e) { for (int x = 0; x <= map.GetLength(0) - 1; x++) { for (int y = 0; y <= map.GetLength(1) - 1; y++) { map[x, y] = new Cell(false); } } PB_main.Refresh(); }
void Init() { string current = "1"; while (true) { current = PosNegNegPos(current); Bitmap bmp = new Bitmap(Convert.ToInt32(Math.Sqrt(current.Length)), Convert.ToInt32(Math.Sqrt(current.Length))); PB_main.Image = bmp; PB_main.SizeMode = PictureBoxSizeMode.StretchImage; PB_main.Refresh(); } }
//triggers paint refresh and steps all cells every interval private void Step() { Cell[,] oldMap = Clone(map); //Display(map); for (int x = 0; x <= map.GetLength(0) - 1; x++) { for (int y = 0; y <= map.GetLength(1) - 1; y++) { map[x, y].Step(new Locale(oldMap, new Point(x, y))); } } PB_main.Refresh(); }
private void TIM_main_Tick(object sender, EventArgs e) { Random rng = new Random(); Point repulse = MousePosition; for (int i = 0; i <= arrSize - 1; i++) { int angle = rng.Next(0, 360); Point particleCenter = new Point(particles[i].Left + particleSize / 2, particles[i].Top + particleSize / 2); double distanceFromRepulse = Math.Sqrt(Math.Pow(particleCenter.X - repulse.X, 2) + Math.Pow(particleCenter.Y - repulse.Y, 2)); if (distanceFromRepulse <= repulseThreshold) { double angleToRepulse; try { angleToRepulse = Math.Atan((repulse.X - particleCenter.X) / (particleCenter.Y - repulse.Y)); } catch { angleToRepulse = angle; } angle = Convert.ToInt32(Math.Round(angleToRepulse + 180, 0)); if (angle >= 360) { angle -= 360; } } double speedx, speedy; speedx = speed * Math.Sin(angle); speedy = speed * Math.Cos(angle); particles[i].X += Convert.ToInt32(Math.Round(speedx, 0)); particles[i].Y += Convert.ToInt32(Math.Round(speedy, 0)); if (particles[i].Left < 0) { particles[i].X = 0; } else if (particles[i].Right > PB_main.Width) { particles[i].X = PB_main.Width - particleSize; } if (particles[i].Top < 0) { particles[i].Y = 0; } else if (particles[i].Bottom > PB_main.Height) { particles[i].Y = PB_main.Height - particleSize; } } PB_main.Refresh(); }
//TIM_rotate tracks controlled rotation private void TIM_rotate_Tick(object sender, EventArgs e) { //difference in x and y used to generate int diffX, diffY; //find second point on line, P1 being where mouse was clicked rotationHover = PB_main.PointToClient(MousePosition); //find 2 smaller sides of triangle they make diffX = rotationHover.X - rotationBase.X; diffY = rotationHover.Y - rotationBase.Y; //using arbritary const scaler, find angle... base angle is from previous state angleX = diffY * CONTROLLEDROTATIONSCALING + baseAngleX; angleY = diffX * CONTROLLEDROTATIONSCALING + baseAngleY; }
private void TB_angle_Scroll(object sender, EventArgs e) { angle = Convert.ToDouble((TB_angle.Value / 500f) * 1.61803398875); Text = "Golden Ratio - " + angle.ToString() + " rad"; if (angle.ToString() == "1.61803398875") { PB_main.BackColor = Color.Green; } else { PB_main.BackColor = Color.Black; } PB_main.Refresh(); }
void Init() { current = PosNegNegPos(current); //Bitmap bmp = new Bitmap(Convert.ToInt32(Math.Sqrt(current.Length)), Convert.ToInt32(Math.Sqrt(current.Length))); Bitmap bmp = new Bitmap(1920, 1080); GenBmp(current, ref bmp); PB_main.Image = bmp; bmp.Save("output" + i + ".bmp"); i++; //PB_main.SizeMode = PictureBoxSizeMode.StretchImage; PB_main.CreateGraphics().InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; PB_main.Refresh(); }
private void TB_zoom_Scroll(object sender, EventArgs e) { cellSize = TB_zoom.Value; //helps visibility if (cellSize < 10) { backgroundLineWidth = 1; } else { backgroundLineWidth = 2; } NewMap(); PB_main.Refresh(); }
private void TIM_animate_Tick(object sender, EventArgs e) { Random rng = new Random(); foreach (Boi boi in bois) { if (rng.Next(0, 2) == 0) { boi.angle += TURNSPEED; } else { boi.angle -= TURNSPEED; } Point speed = GetXY(boi.angle, MAG); boi.ShiftBack(); boi.boi.X += speed.X; boi.boi.Y += speed.Y; if (boi.boi.Left < 0) { boi.boi.X = 0; boi.angle = rng.Next(0, 181); } else if (boi.boi.Right > PB_main.Width) { boi.boi.X = PB_main.Width - BOISIZE; boi.angle = rng.Next(180, 360); } if (boi.boi.Top < 0) { boi.boi.Y = 0; boi.angle = rng.Next(90, 271); } else if (boi.boi.Bottom > PB_main.Height) { boi.boi.Y = PB_main.Height - BOISIZE; boi.angle = rng.Next(0, 2); if (boi.angle == 0) { boi.angle = rng.Next(0, 91); } else { boi.angle = rng.Next(270, 360); } } } PB_main.Refresh(); }
private void PB_main_Click(object sender, EventArgs e) { //checks what you are adding if (TS_addGrav.Checked) { CreateSource(ConvertMass(TSTXT_mass.Text), PB_main.PointToClient(MousePosition)); } else if (TS_addObj.Checked) { try { CreateObject(Convert.ToDouble(TSTXT_vX.Text), Convert.ToDouble(TSTXT_vY.Text), ConvertMass(TSTXT_mass.Text), PB_main.PointToClient(MousePosition)); } catch (Exception) { MessageBox.Show("Invalid mass or velocity."); } } }
private void PB_main_Paint(object sender, PaintEventArgs e) { //gets current pos of mouse Point mousePos = PB_main.PointToClient(MousePosition); Graphics g = e.Graphics; if (!(lines == null)) { foreach (Tuple <Point, Point> l in lines) { g.DrawLine(Pens.Red, l.Item1, l.Item2); } } //draws all sources and objs foreach (Source source in sources) { DrawSourceIcon(g, source.Pos.Round(), source); } foreach (Obj obj in objs) { DrawObjIcon(g, obj.Pos.Round(), obj); } //draws hovering add icon if (TS_addGrav.Checked) { DrawGravAddIcon(g, mousePos); } else if (TS_addObj.Checked) { DrawObjAddIcon(g, mousePos); } else { DrawCursor(g, mousePos); } }
private void LoadFile(string path) { //reads StreamReader strR = new StreamReader(path); List <string> lines = new List <string>(); //for later string line; while (!(strR.EndOfStream)) { lines.Add(strR.ReadLine()); } strR.Close(); //puts in new map map = new Cell[lines.Count, lines[0].Length]; for (int x = 0; x <= map.GetLength(0) - 1; x++) { line = lines[x]; for (int y = 0; y <= map.GetLength(1) - 1; y++) { if (line[y] == 'T') { map[x, y] = new Cell(true); } else { map[x, y] = new Cell(false); } } } //adjusts map size NewMap(); PB_main.Refresh(); }
//TIM_render is processing private void TIM_render_Tick(object sender, EventArgs e) { Renderable[] projected; zBuffer = new float[PB_main.Width, PB_main.Height]; Matrix combined, translateToFrustrum; { //matrix definition section //takes from origin, translates to into camera view translateToFrustrum = new Matrix(new float[, ] { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, -1.25f }, { 0, 0, 0, 1 } }); //rotation matrices Matrix rotateY = new Matrix(new float[, ] { { Convert.ToSingle(Math.Cos(angleY)), 0, Convert.ToSingle(Math.Sin(angleY)), 0 }, { 0, 1, 0, 0 }, { Convert.ToSingle(-Math.Sin(angleY)), 0, Convert.ToSingle(Math.Cos(angleY)), 0 }, { 0, 0, 0, 1 } }); Matrix rotateX = new Matrix(new float[, ] { { 1, 0, 0, 0 }, { 0, Convert.ToSingle(Math.Cos(angleX)), Convert.ToSingle(-Math.Sin(angleX)), 0 }, { 0, Convert.ToSingle(Math.Sin(angleX)), Convert.ToSingle(Math.Cos(angleX)), 0 }, { 0, 0, 0, 1 } }); //scaling matrix Matrix scale = new Matrix(new float[, ] { { scaleFactor, 0, 0, 0 }, { 0, scaleFactor, 0, 0 }, { 0, 0, scaleFactor, 0 }, { 0, 0, 0, scaleFactor } }); //combined matrix to make syntax cleaner combined = scale.Multiply(rotateY.Multiply(rotateX)); } //clean array render = new List <Renderable>(); //initialise zBuffer for (int x = 0; x < zBuffer.GetLength(0); x++) { for (int y = 0; y < zBuffer.GetLength(1); y++) { zBuffer[x, y] = INFINITY; } } //array of 2d renderables - still NDC projected = new Renderable[preRender.Count]; for (int i = 0; i < preRender.Count; i++) { projected[i] = preRender[i].Transform(combined) .Transform(translateToFrustrum) .Project(VPWIDTH, VPHEIGHT, CTOVPZ, ZCLIPPING); } //add NDC converts to render list foreach (Renderable entity in projected) { if (Array.TrueForAll(entity.Vertices, vertex => vertex.Z < scaleFactor * -0.75f)) { render.Add(ToScreenFromNDC(entity)); } } //add axis List <Line> axes = new List <Line>(); axes.Add(new Line(new Vect3[] { new Vect3(0, 0, 0), new Vect3(0.1f, 0, 0) })); axes.Add(new Line(new Vect3[] { new Vect3(0, 0, 0), new Vect3(0, 0.1f, 0) })); axes.Add(new Line(new Vect3[] { new Vect3(0, 0, 0), new Vect3(0, 0, 0.1f) })); foreach (Line axis in axes) { render.Add(ToScreenFromNDC(axis.Transform(combined).Transform(translateToFrustrum).Project(VPWIDTH, VPHEIGHT, CTOVPZ, ZCLIPPING))); } TSC_main.ContentPanel.Update(); PB_main.Refresh(); }
private void TIM_main_Tick(object sender, EventArgs e) { //totalstrength is resultant accel, indiv is accel due to individual sources DoublePoint totalStrength, indivStrength; Obj obj; bool delete = false; for (int i = 0; i <= objs.Count - 1; i++) { obj = objs[i]; //steps accel and v obj.Step(); totalStrength = new DoublePoint(0, 0); //for every source, find accel on this obj, and add to resultant foreach (Source s in sources) { indivStrength = s.GetStrengthAtPoint(obj.Pos); if (!(indivStrength == null)) { totalStrength.X += indivStrength.X; totalStrength.Y += indivStrength.Y; } else { delete = true; } } if (TS_objGrav.Checked) { for (int a = 0; a <= objs.Count - 1; a++) { if (!(a == i)) { indivStrength = objs[a].GetStrengthAtPoint(obj.Pos); if (!(indivStrength == null)) { totalStrength.X += indivStrength.X; totalStrength.Y += indivStrength.Y; } else { delete = true; } } } if (delete) { objs.Remove(objs[i]); if (TS_trail.Checked) { p1.Remove(p1[i]); } } } //change accel by resultant obj.ApplyAccel(totalStrength); } for (int i = 0; i <= objs.Count - 1; i++) { if (objs[i].Pos.X > MAXINT || objs[i].Pos.X <-MAXINT || objs[i].Pos.Y> MAXINT || objs[i].Pos.X < -MAXINT) { objs.Remove(objs[i]); if (TS_trail.Checked) { p1.Remove(p1[i]); } } } //focus section foreach (Obj o in objs) { if (o.Container.Contains(PB_main.PointToClient(MousePosition))) { o.Focused = true; foreach (Obj a in objs) { if (!(o == a)) { a.Focused = false; } } } } foreach (Obj o in objs) { if (o.Focused) { RTXT_focused.Text = o.GetReadout(); } } PB_main.Refresh(); }