public void notifierActionClicDessin(int x, int y) { switch (formeActive) { case FORME.CERCLE: Debug.WriteLine("FORME.CERCLE"); Cercle cercle = new Cercle(x, y, new Forme.Couleur(0, 0, 0)); this.dessin.ajouterForme(cercle); this.vuePlancheDessin.afficherCercle(cercle); this.vuePlancheDessin.desactiverBoutonCercle(); break; case FORME.CARRE: Debug.WriteLine("FORME.CARRE"); Carre carre = new Carre(x, y, new Forme.Couleur(0, 0, 0)); this.dessin.ajouterForme(carre); this.vuePlancheDessin.afficherCarre(carre); this.vuePlancheDessin.desactiverBoutonCarre(); break; case FORME.TRIANGLE: Debug.WriteLine("FORME.TRIANGLE"); Triangle triangle = new Triangle(x, y, new Forme.Couleur(0, 0, 0)); this.dessin.ajouterForme(triangle); this.vuePlancheDessin.afficherTriangle(triangle); this.vuePlancheDessin.desactiverBoutonTriangle(); break; default: Debug.WriteLine("DEFAULT"); break; } this.formeActive = FORME.AUCUNE; }
static void Main(string[] args) { Point p = new Point(3, 4); var p2 = new Point(5, 7); // Revient à faire Point p2 = new Point(5, 7); car cela permet de racoussir var p3 = new Point(10, 4); var p4 = new Point(3, 6); Cercle c = new Cercle(p, 4); var poly = new Polygone(p, p2, p3, p4); System.Console.WriteLine(poly.CalculerPerimetre()); foreach (var item in poly) { System.Console.WriteLine(item); } for (int i = 0; i < poly.Count; i++) { System.Console.WriteLine(poly[i].ToString()); } }
private void dessiner() { this.P_Quest.CreateGraphics().Clear(Color.Gainsboro); switch (FormeRandom[numQuestion - 1].Type) { case "Carre": Carre f1 = (Carre)FormeRandom[numQuestion - 1]; INFO_Forme.Text = "Le carre a pour cote " + f1.getC() + " pixel ."; DessinateurCarre dc = new DessinateurCarre(); dc.dessiner(FormeRandom[numQuestion - 1], this.P_Quest); break; case "Cercle": Cercle f2 = (Cercle)FormeRandom[numQuestion - 1]; INFO_Forme.Text = "Le cercle a pour Rayon " + f2.getR() + " pixel ."; DessinateurCercle dc2 = new DessinateurCercle(); dc2.dessiner(FormeRandom[numQuestion - 1], this.P_Quest); break; case "Rectangle": librairie.Rectangle f3 = (librairie.Rectangle)FormeRandom[numQuestion - 1]; INFO_Forme.Text = "Le Rectangle a pour Largeur " + f3.getlarg() + " pixel et de Longeur " + f3.getlong() + " pixel ."; DessinateurRectangle dc3 = new DessinateurRectangle(); dc3.dessiner(FormeRandom[numQuestion - 1], this.P_Quest); break; } }
static void Main(string[] args) { double surfaceTotale; Figure[] tableau = new Figure[2]; tableau[0] = new Cercle(10); tableau[1] = new Rectangle(15, 10, 3, 4); Console.WriteLine("Avec un tableau \n"); Console.WriteLine("Rectangle centré au point de coordonnées " + tableau[1].Informations()); Console.WriteLine("Cercle centré au point de coordonnées " + tableau[0].Informations()); surfaceTotale = Math.Round(tableau[0].Surface() + tableau[1].Surface(), 2); Console.WriteLine("Surface totale : " + surfaceTotale + "\n"); surfaceTotale = 0; List <Figure> listFigures = new List <Figure>(); listFigures.Add(new Cercle(10)); listFigures.Add(new Rectangle(15, 10, 3, 4)); Console.WriteLine("Avec une collection \n"); Console.WriteLine("Rectangle centré au point de coordonnées " + listFigures.First().Informations()); Console.WriteLine("Cercle centré au point de coordonnées " + listFigures.Last().Informations()); surfaceTotale = Math.Round(listFigures.First().Surface() + listFigures.Last().Surface(), 2); Console.WriteLine("Surface totale : " + surfaceTotale); Console.ReadLine(); }
//constructeur qui initialise un décor de forme sphérique public Decor(string nom, short type, Point pos, float r, Point vit, bool f) { relativeCoordinate = pos; speed = vit; franchissabilite = f; id = type; shape = new Cercle(r, relativeCoordinate); name = nom; }
//constructeur par défaut public Personnage() { AbsoluteCoordinate = new Point(0, 0); relativeCoordinate = new Point(0, 0); speed = new Point(0, 0); franchissabilite = false; shape = new Cercle(0, relativeCoordinate); name = "john/jane doe"; }
public ControleurDessin(VuePlancheDessin vue) { this.vuePlancheDessin = vue; // TEST debut Dessin dessin = new Dessin(); Cercle cercle = new Cercle(100, 100, new Forme.Couleur(0, 0, 0)); dessin.ajouterForme(cercle); // TEST fin }
//teste l'intersection entre deux cercles public bool AppartenanceCercle(Cercle c) { bool appart = false; float dist = centre.DistancePoint(c.centre); if (dist <= Math.Pow(rayon + c.rayon, 2)) { appart = true; } return(appart); }
public void dessiner(Forme f, Control c) { Cercle f1 = (Cercle)f; Graphics formGraphics; formGraphics = c.CreateGraphics(); SolidBrush myBrush = new SolidBrush(Color.Blue); formGraphics.FillEllipse(myBrush, new System.Drawing.Rectangle(f.getposi().getY(), f.getposi().getX(), f1.getR(), f1.getR())); myBrush.Dispose(); }
public void afficherCercle(Cercle cercle) { Ellipse rond = new Ellipse(); SolidColorBrush brosse = new SolidColorBrush(); brosse.Color = Color.FromRgb(239, 174, 23); rond.Fill = brosse; rond.Width = 50; rond.Height = 50; rond.Margin = new Thickness(cercle.x, cercle.y, 0, 0); this.dessin.Children.Add(rond); }
public static void DrawCercles(Bitmap img, Color pen) { Cercle c = new Cercle(0, 0, 0, 50); c.Afficher(img, pen); Cercle c1 = new Cercle(10, 0, 0, 30); c1.Afficher(img, pen); Cercle c2 = new Cercle(10, 10, 0, 60); c2.Afficher(img, pen); Cercle c3 = new Cercle(15, 15, 0, 70); c3.Afficher(img, pen); }
private void Bt_Add_Cercle_Click(object sender, EventArgs e) { if (Tb_Rayon_Cercle.Text != "" && Tb_X_Cercle.Text != "" && Tb_Y_Cercle.Text != "") { Forme cercle = new Cercle(Convert.ToInt32(Tb_Rayon_Cercle.Text), Convert.ToInt32(Tb_X_Cercle.Text), Convert.ToInt32(Tb_Y_Cercle.Text)); Tb_Rayon_Cercle.Text = ""; Tb_X_Cercle.Text = ""; Tb_Y_Cercle.Text = ""; LesForme.Add(cercle); Cercle f1 = (Cercle)LesForme[LesForme.Count - 1]; Conn.AddCercle(LesForme[LesForme.Count - 1].Id, f1.getR(), LesForme[LesForme.Count - 1].getposi().getX(), LesForme[LesForme.Count - 1].getposi().getY()); ActualisationDgv(); } else { MessageBox.Show("Un champ n'a pas etais saisie"); } }
public static Vector3 _Intersection3D_DroiteCoupantUnCercle(Cercle c, Droite d, float angle) { Intersections3D i12 = _Intersections3D_DroiteCoupantUnCercle(c, d); //i1 ou i2 ==> celui qui est le plus proche du point sans marge ?? float Bx = c.r * Mathf.Sin(angle / 180 * Mathf.PI); float By = c.r * Mathf.Cos(angle / 180 * Mathf.PI); Vector3 b = new Vector3(Bx, 0, By); if (Vector3.Distance(b, i12.intersection_1) < Vector3.Distance(b, i12.intersection_2)) { return(i12.intersection_1); } else { return(i12.intersection_2); } }
private static List <GeometricShapes.Shapes> Inizialization() { var shapeCollections = new List <GeometricShapes.Shapes>(); var cercle1 = new Cercle(2.3f); var rectangle1 = new Rectangle(5.2f, 1.6f); var square1 = new Square(5.1f); var triangleEqui = new Triangle(3.0f, 3.0f, 3.0f); var triangleIsoscele = new Triangle(1.2f, 1.2f, 1.0f); var triangleScalene = new Triangle(1.4f, 5.2f, 1.7f); shapeCollections.Add(cercle1); shapeCollections.Add(rectangle1); shapeCollections.Add(triangleEqui); shapeCollections.Add(triangleIsoscele); shapeCollections.Add(triangleScalene); shapeCollections.Add(square1); return(shapeCollections); }
public DisplayObject(Figure fig, CoronaObject coronaObjectParent) { this.Name = "Figure"; this.type = "FIGURE"; this.Figure = fig; this.Figure.DisplayObjectParent = this; if (this.Figure.ShapeType.Equals("RECTANGLE")) { Rect rect = this.Figure as Rect; this.surfaceRect = rect.getBounds(new Matrix()); } else if (this.Figure.ShapeType.Equals("CIRCLE")) { Cercle cercle = this.Figure as Cercle; this.surfaceRect = cercle.getBounds(new Matrix()); } else if (this.Figure.ShapeType.Equals("LINE")) { Line line = this.Figure as Line; this.surfaceRect = line.getBounds(new Matrix()); } else if (this.Figure.ShapeType.Equals("TEXT")) { Texte text = this.Figure as Texte; this.surfaceRect = new Rectangle(text.Position, System.Windows.Forms.TextRenderer.MeasureText(text.txt, new Font(text.font2.FamilyName, text.font2.Size, text.font2.Style))); } else if (this.Figure.ShapeType.Equals("CURVE")) { CourbeBezier courbe = this.Figure as CourbeBezier; this.surfaceRect = courbe.getBounds(new Matrix()); } Alpha = 1.0F; this.GradientColor = new GradientColor(); this.CoronaObjectParent = coronaObjectParent; }
//Equation d'un cercle (1) : (x - Ox)² + (y - Oy)² = c.r ² //Equation d'une droite (2) : y = a * x + b //(2) dans (1) : (x - Ox)² + (a * x + b - Oy)² = r² //g = (a * x + b - Oy)² = (a * x + b - Oy) * (a * x + b - Oy) //g = a * a * x * x + a * x * b - a * x * Oy + b * a * x + b * b - b * Oy - Oy * a * x - Oy * b + Oy * Oy; //g = x * x * (a * a) + x * (a * b - a * Oy + b * a - Oy * a) + (b * b - b * Oy - Oy * b + Oy * Oy); //g = x * x * (a * a) + x * 2 * a * (b - Oy) + (b - Oy) * (b - Oy); //(2) dans (1) : x * x + Ox * Ox - 2 * x * Ox + x * x * (a * a) + x * 2 * a * (b - Oy) + (b - Oy) * (b - Oy) = r * r //r * r = x * x + x * (- 2 * Ox) + Ox * Ox + x * x * (a * a) + x * 2 * a * (b - Oy) + (b - Oy) * (b - Oy); //r * r= x * x * (1 + a * a) + x * (-2 * Ox + 2 * a * (b - Oy)) + Ox * Ox + (b - Oy) * (b - Oy); //x * x * (1 + a * a) + x * (-2 * Ox + 2 * a * (b - Oy)) + Ox * Ox + (b - Oy) * (b - Oy) - r * r= 0; //Equation de la forme a * x²+ b * x + c = 0 public static Intersections2D _Intersections2D_DroiteCoupantUnCercle(Cercle c, Droite d) { if (d.a != float.MinValue && d.a != float.MaxValue) { float a = d.a; float b = d.b; float Ox = c.O.x; float Oy = c.O.y; float r = c.r; float _a = (1 + a * a); float _b = (-2 * Ox + 2 * a * (b - Oy)); float _c = Ox * Ox + (b - Oy) * (b - Oy) - r * r; Vector2?X12 = _TrinomeDu2ndDegres(_a, _b, _c); if (X12 == null) { Debug.Log($"Aucun point de la droite y = {d.a} * x + {d.b} ne coupe le cercle de rayon {c.r} et de centre {c.O}"); return(null); } Vector2 x12 = (Vector2)X12; //trouve les Y avec l'équation de la droite float Y1 = a * x12.x + b; float Y2 = a * x12.y + b; return(new Intersections2D() { intersection_1 = new Vector2(x12.x, Y1), intersection_2 = new Vector2(x12.y, Y2) }); } else { return(new Intersections2D() { intersection_1 = new Vector2(0, c.r), intersection_2 = new Vector2(0, -c.r) }); } }
public static Intersections3D _Intersections3D_DroiteCoupantUnCercle(Cercle c, Droite d) { if (d.a != float.MinValue && d.a != float.MaxValue) { float a = d.a; float b = d.b; float Ox = c.O.x; float Oy = c.O.y; float r = c.r; float _a = (1 + a * a); float _b = (-2 * Ox + 2 * a * (b - Oy)); float _c = Ox * Ox + (b - Oy) * (b - Oy) - r; Vector2?X12 = _TrinomeDu2ndDegres(_a, _b, _c); if (X12 == null) { return(null); } Vector2 x12 = (Vector2)X12; //trouve les Y avec l'équation de la droite float Y1 = a * x12.x + b; float Y2 = a * x12.y + b; return(new Intersections3D() { intersection_1 = new Vector3(x12.x, 0, Y1), intersection_2 = new Vector3(x12.y, 0, Y2) }); } else { return(new Intersections3D() { intersection_1 = new Vector3(0, 0, c.r), intersection_2 = new Vector3(0, 0, -c.r) }); } }
static void Main(string[] args) { Console.WriteLine("____________________________________________"); Console.WriteLine("TEST CERCLE"); Cercle c1 = new Cercle(4, 3, 2); c1.SeDessiner(); Console.WriteLine("____________________________________________"); Console.WriteLine("TEST RECTANGLE"); Rectangle r1 = new Rectangle(4, 3, 2, 1); r1.SeDessiner(); Console.WriteLine("____________________________________________"); Console.WriteLine("TEST FIGURES"); Figures ensembleDeFigures = new Figures(4, 3); Cercle c2 = new Cercle(5, 6, 7); Rectangle r2 = new Rectangle(8, 4, 3, 4); ensembleDeFigures.AjouterFigure(c2); ensembleDeFigures.AjouterFigure(r2); ensembleDeFigures.SeDessiner(); Console.WriteLine("____________________________________________"); Console.WriteLine("TEST FIGURES CONTENANT UN FIGURES"); Figures ensembleDeFigures2 = new Figures(4, 3); Cercle c3 = new Cercle(2, 1, 5); Rectangle r3 = new Rectangle(3, 2, 7, 1); ensembleDeFigures2.AjouterFigure(c3); ensembleDeFigures2.AjouterFigure(r3); ensembleDeFigures.AjouterFigure(ensembleDeFigures2); ensembleDeFigures.SeDessiner(); Console.ReadLine(); }
static void Main(string[] args) { // Avec un tableau Console.WriteLine("Avec un tableau : "); Console.WriteLine(""); Figure[] Figures = new Figure[2]; // Création d'un tableau de Figure de taille 2 Figures[0] = new Cercle(10); // Ajout d'un Cercle de rayon 10 en première position du tableau Figures[1] = new Rectangle(3, 4, 15, 10); // Ajout d'un Rectangle en (3;4) de taille 15 sur 10 // en deuxième position du tableau Figures[0].Informations(); // Affichage des coordonnées Console.WriteLine("A une surface de " + String.Format("{0:0.00}", Figures[0].Surface())); Figures[1].Informations(); // Affichage des coordonnées Console.WriteLine("A une surface de " + String.Format("{0:0.00}", Figures[1].Surface())); double surfaceTotale = Figures[0].Surface() + Figures[1].Surface(); Console.WriteLine("La surface totale de toutes les figures est : " + String.Format("{0:0.00}", surfaceTotale)); Console.WriteLine(""); // Avec une liste Console.WriteLine("Avec une liste : "); Console.WriteLine(""); List <Figure> Figures2 = new List <Figure>(); Figures2.Add(new Cercle(10)); Figures2.Add(new Rectangle(3, 4, 15, 10)); Figures2[0].Informations(); Console.WriteLine("A une surface de " + String.Format("{0:0.00}", Figures[0].Surface())); Figures2[1].Informations(); Console.WriteLine("A une surface de " + String.Format("{0:0.00}", Figures[1].Surface())); Console.WriteLine("La surface totale de toutes les figures est : " + String.Format("{0:0.00}", surfaceTotale)); Console.ReadLine(); }
static void Main(string[] args) { FigureOuverte fOv = new FigureOuverte(); Console.WriteLine(fOv.Dessiner() + "\n********\n couleur " + fOv.Color); Console.ReadLine(); Point p1 = new Point(50, 30); Point p2 = new Point(250, 130); Rectangle rec = new Rectangle(p1, p2); Console.WriteLine(rec.Dessiner() + "\n********\n couleur " + rec.Color); Console.WriteLine("Perimètre : " + rec.GetPerimetre()); Console.WriteLine("Surface : " + rec.GetSurface()); Console.ReadLine(); Point centre = new Point(60, 40); int rayon = 80; Cercle monCercle = new Cercle(centre, rayon); Console.WriteLine(monCercle.Dessiner() + "\n********\n couleur " + monCercle.Color); Console.WriteLine("Perimètre : " + monCercle.GetPerimetre()); Console.WriteLine("Surface : " + monCercle.GetSurface()); Console.ReadLine(); }
public void dessineAllBodyELements(Graphics g, Brush brush, bool applyPointsAjustingWithParent, Point offsetPoint) { if (this.BodyElements.Count == 0) { this.isCustomizedBody = false; } if (this.isCustomizedBody == true) { for (int i = 0; i < this.BodyElements.Count; i++) { BodyElement elem = this.BodyElements[i]; if (elem.Type.Equals("SHAPE")) { if (applyPointsAjustingWithParent == true) { //Creer un tableau de points ajustés Point[] tabPointsAjust = new Point[elem.BodyShape.Count]; for (int j = 0; j < elem.BodyShape.Count; j++) { Point pAjust = new Point(elem.BodyShape[j].X + this.objectParent.DisplayObject.SurfaceRect.X + offsetPoint.X, elem.BodyShape[j].Y + this.objectParent.DisplayObject.SurfaceRect.Y + offsetPoint.Y); tabPointsAjust[j] = pAjust; } g.FillPolygon(brush, tabPointsAjust); } else { //Creer un tableau de points ajustés Point[] tabPointsAjust = new Point[elem.BodyShape.Count]; for (int j = 0; j < elem.BodyShape.Count; j++) { Point pAjust = new Point(elem.BodyShape[j].X + offsetPoint.X, elem.BodyShape[j].Y + offsetPoint.Y); tabPointsAjust[j] = pAjust; } g.FillPolygon(brush, tabPointsAjust); } } else if (elem.Type.Equals("CIRCLE")) { int radius = elem.Radius; if (applyPointsAjustingWithParent == true) { g.FillEllipse(brush, new Rectangle(new Point(elem.SurfaceCircle.X + this.objectParent.DisplayObject.SurfaceRect.X + offsetPoint.X, elem.SurfaceCircle.Y + this.objectParent.DisplayObject.SurfaceRect.Y + offsetPoint.Y) , new Size(elem.Radius * 2, elem.Radius * 2))); } else { g.FillEllipse(brush, new Rectangle(new Point(elem.SurfaceCircle.X + offsetPoint.X, elem.SurfaceCircle.Y + offsetPoint.Y) , new Size(elem.Radius * 2, elem.Radius * 2))); } } else if (elem.Type.Equals("LINE")) { if (applyPointsAjustingWithParent == true) { //Creer un tableau de points ajustés Point[] tabPointsAjust = new Point[elem.BodyShape.Count]; for (int j = 0; j < elem.BodyShape.Count; j++) { Point pAjust; pAjust = new Point(elem.BodyShape[j].X + this.objectParent.DisplayObject.SurfaceRect.X + offsetPoint.X, elem.BodyShape[j].Y + this.objectParent.DisplayObject.SurfaceRect.Y + offsetPoint.Y); tabPointsAjust[j] = pAjust; } g.DrawLines(Pens.GreenYellow, tabPointsAjust); } else { //Creer un tableau de points ajustés Point[] tabPointsAjust = new Point[elem.BodyShape.Count]; for (int j = 0; j < elem.BodyShape.Count; j++) { Point pAjust = new Point(elem.BodyShape[j].X + offsetPoint.X, elem.BodyShape[j].Y + offsetPoint.Y); tabPointsAjust[j] = pAjust; } g.DrawLines(Pens.GreenYellow, tabPointsAjust); } } } } else { DisplayObject dispObj = this.objectParent.DisplayObject; if (dispObj.Type.Equals("FIGURE")) { Figure fig = this.objectParent.DisplayObject.Figure; if (fig != null) { if (fig.ShapeType.Equals("CIRCLE")) { Cercle circ = fig as Cercle; g.FillEllipse(brush, circ.Position.X + offsetPoint.X, circ.Position.Y + offsetPoint.Y, circ.Rayon * 2, circ.Rayon * 2); } else if (fig.ShapeType.Equals("RECTANGLE")) { Rect rect = fig as Rect; g.FillRectangle(brush, rect.Position.X + offsetPoint.X, rect.Position.Y + offsetPoint.Y, rect.Width, rect.Height); } else if (fig.ShapeType.Equals("LINE")) { Krea.CGE_Figures.Line line = fig as Krea.CGE_Figures.Line; //Convertir tous les points et leur ajouter un offset Point[] tabPoints = new Point[line.Points.Count]; for (int i = 0; i < line.Points.Count; i++) { tabPoints[i] = new Point(line.Points[i].X + offsetPoint.X, line.Points[i].Y + offsetPoint.Y); } if (line.Points.Count > 2) { g.DrawLines(Pens.GreenYellow, tabPoints); } else if (line.Points.Count == 2) { g.DrawLine(Pens.GreenYellow, tabPoints[0], tabPoints[1]); } } else if (fig.ShapeType.Equals("TEXT")) { Texte txt = fig as Texte; SizeF size = g.MeasureString(txt.txt, new Font(txt.font2.FamilyName, txt.font2.Size)); g.FillRectangle(brush, txt.Position.X + offsetPoint.X, txt.Position.Y + offsetPoint.Y, size.Width, size.Height); } } } else { if (applyPointsAjustingWithParent == true) { g.FillRectangle(brush, dispObj.SurfaceRect.X + offsetPoint.X, dispObj.SurfaceRect.Y + offsetPoint.Y, dispObj.SurfaceRect.Width, dispObj.SurfaceRect.Height); } else { g.FillRectangle(brush, offsetPoint.X, offsetPoint.Y, dispObj.SurfaceRect.Width, dispObj.SurfaceRect.Height); } } } }
static void Main(string[] args) { int reponse; do { Console.Clear(); //Console.BackgroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Red; Console.SetCursorPosition(15, 2); Console.WriteLine("1 - Calcul de la surface d'un Carre"); Console.SetCursorPosition(15, 3); Console.WriteLine("2 - Calcul de la surface d'un Cercle"); Console.SetCursorPosition(15, 4); Console.WriteLine("3 - Calcul de la surface d'un Triangle"); Console.SetCursorPosition(15, 5); Console.WriteLine("4 - Calcul de la Surface d'un Rectangle"); Console.SetCursorPosition(15, 6); Console.WriteLine("5 - Calcul de la surface d'un Losange"); Console.SetCursorPosition(15, 7); Console.WriteLine("6 - Calcul de la surface d'un Trapeze"); Console.SetCursorPosition(15, 8); Console.WriteLine("7 - Calcul de la surface d'un Parallelogramme"); Console.SetCursorPosition(15, 9); Console.WriteLine("8 - Calcul de la surface d'un Pentagone Regulier"); Console.SetCursorPosition(15, 10); Console.WriteLine("9 - Calcul de la surface d'une Couronne(Anneau)"); Console.SetCursorPosition(15, 11); Console.WriteLine("10 - Calcul de la surface d'un Demi - Cercle"); Console.SetCursorPosition(15, 12); Console.WriteLine("11 - Calcul de la surface d'une Ellipse"); Console.SetCursorPosition(15, 13); Console.WriteLine("12 - Calcul de la surface d'un Hexagone Regulier"); Console.SetCursorPosition(15, 14); Console.WriteLine("0 - Quitter"); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("Entrez votre Choix"); reponse = Convert.ToInt32(Console.ReadLine()); switch (reponse) { // Calcul de la surface d'un carre case 1: Console.ForegroundColor = ConsoleColor.Red; Console.SetCursorPosition(15, 19); Console.WriteLine("LA SURFACE D'UN CARRE"); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("Donnez la longueur du Cote"); float c = float.Parse(Console.ReadLine()); Carre ca = new Carre(c); float aireCarre = ca.Aire(); Console.WriteLine("La Surface d'un carre de {0} Cm de cote est : {1} Cm2", c, aireCarre); Console.ReadLine(); break; // Calcul de la surface d'un Cercle case 2: Console.ForegroundColor = ConsoleColor.White; Console.SetCursorPosition(15, 19); Console.WriteLine("LA SURFACE D'UN CERCLE"); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("Donnez la longueur du Rayon"); float r = float.Parse(Console.ReadLine()); Cercle ce = new Cercle(r); float aireCercle = ce.Aire(); Console.WriteLine("La surface d'un cercle de {0} Cm de rayon est : {1} Cm2", r, aireCercle); Console.ReadLine(); break; // Calcul de la surface d'un Triangle case 3: Console.ForegroundColor = ConsoleColor.Green; Console.SetCursorPosition(15, 19); Console.WriteLine("LA SURFACE D'UN TRIANGLE"); Console.ForegroundColor = ConsoleColor.Gray; //Figure(); Console.WriteLine("Donnez la longueur de la base du triangle"); float B = float.Parse(Console.ReadLine()); Console.WriteLine("Donnez la longueur de la hauteur de triangle"); float h = float.Parse(Console.ReadLine()); Triangle tr = new Triangle(B, h); float aireTriangle = tr.Aire(); Console.WriteLine("La surface d'un Triangle de {0} Cm de base et {1} Cm de hauteur est : {2} Cm2", B, h, aireTriangle); Console.ReadLine(); break; // Calcul de la Surface d'un rectangle case 4: Console.ForegroundColor = ConsoleColor.Magenta; Console.SetCursorPosition(15, 19); Console.WriteLine("LA SURFACE D'UN RECTANGLE"); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("Donnez la longueur du rectangle"); float L = float.Parse(Console.ReadLine()); Console.WriteLine("Donnez la largeur du rectangle"); float l = float.Parse(Console.ReadLine()); Rectangle re = new Rectangle(L, l); float aireRectangle = re.Aire(); Console.WriteLine("La surface d'un rectangle de {0} Cm de Long et {1} Cm de large est : {2} Cm2", L, l, aireRectangle); Console.ReadLine(); break; // Calcul de la surface d'un Losange case 5: Console.ForegroundColor = ConsoleColor.Blue; Console.SetCursorPosition(15, 19); Console.WriteLine("LA SURFACE D'UN LOSANGE"); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("Donnez la taille de la grande diagonale"); float gd = float.Parse(Console.ReadLine()); Console.WriteLine("Donnez la taille de la petite diagonale"); float pd = float.Parse(Console.ReadLine()); Losange lo = new Losange(gd, pd); float aireLosange = lo.Aire(); Console.WriteLine("La surface d'un Losange de {0} Cm de grande diagonal et {1} Cm de petite diagonale est : {2} Cm2", gd, pd, aireLosange); Console.ReadLine(); break; // Calcul de la surface d'un Trapeze case 6: Console.ForegroundColor = ConsoleColor.Magenta; Console.SetCursorPosition(15, 19); Console.WriteLine("LA SURFACE D'UN TRAPEZE"); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("Donnez la taille de la grande base"); float gb = float.Parse(Console.ReadLine()); Console.WriteLine("Donnez la taille de la petite base"); float pb = float.Parse(Console.ReadLine()); Console.WriteLine("Donnez la taille de la hauteur"); float ha = float.Parse(Console.ReadLine()); Trapeze Tr = new Trapeze(gb, pb, ha); float aireTrapeze = Tr.Aire(); Console.WriteLine("La surface d'un Trapeze de {0} Cm de grande base, {1} Cm de petite base et {2} de hauteur est : {3} Cm2", gb, pb, ha, aireTrapeze); Console.ReadLine(); break; // Calcul de la surface d'un Parallelogramme case 7: Console.ForegroundColor = ConsoleColor.Yellow; Console.SetCursorPosition(15, 19); Console.WriteLine("LA SURFACE D'UN PARALLELOGRAMME"); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("Donnez la longueur de la grande base du parallelogramme"); float lb = float.Parse(Console.ReadLine()); Console.WriteLine("Donnez la taille de la hauteur du parallelogramme"); float ht = float.Parse(Console.ReadLine()); Parallelogramme Pa = new Parallelogramme(lb, ht); float aireParallelogramme = Pa.Aire(); Console.WriteLine("La surface d'un Parallelogramme de {0} Cm de longueur de la base et de {1} Cm de hauteur est : {2} Cm2", lb, ht, aireParallelogramme); Console.ReadLine(); break; // Calcul de la surface d'un Pentagone Regulier case 8: Console.ForegroundColor = ConsoleColor.DarkRed; Console.SetCursorPosition(15, 19); Console.WriteLine("LA SURFACE D'UN PENTAGONE REGULIER"); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("Donnez la Longueur du triangle"); float LT = float.Parse(Console.ReadLine()); Console.WriteLine("Donnez la longueur de la hauteur"); float HT = float.Parse(Console.ReadLine()); Pentagone Pe = new Pentagone(LT, HT); float airePentagone = Pe.Aire(); Console.WriteLine("La surface d'un Pentagone de {0} cm de la Longueur du triangle et de {1} Cm de hauteur est : {2} Cm2", LT, HT, airePentagone); Console.ReadLine(); break; // Calcul de la surface d'une Couronne(Anneau) case 9: Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.SetCursorPosition(15, 19); Console.WriteLine("LA SURFACE D'UNE COURONNE"); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("Donnez la taille du grand Rayon"); float gR = float.Parse(Console.ReadLine()); Console.WriteLine("Donnez la taille du petit Rayon"); float pR = float.Parse(Console.ReadLine()); Couronne Cou = new Couronne(gR, pR); float aireCouronne = Cou.Aire(); Console.WriteLine("La surface d'une Couronne de {0} Cm de grand rayon et de {1} Cm de petit rayon est {2} Cm2", gR, pR, aireCouronne); Console.ReadLine(); break; // Calcul de la surface d'un Demi - Cercle case 10: Console.ForegroundColor = ConsoleColor.DarkGreen; Console.SetCursorPosition(15, 19); Console.WriteLine("LA SURFACE D'UN DEMI-CERCLE"); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("Donnez la taille du rayon du Demi - cercle"); float R = float.Parse(Console.ReadLine()); Demicercle DC = new Demicercle(R); float aireDemicercle = DC.Aire(); Console.WriteLine("La surface d'un Demi Cercle de rayon {0} Cm est : {1} Cm2", R, aireDemicercle); Console.ReadLine(); break; // Calcul de la surface d'une Ellipse case 11: Console.ForegroundColor = ConsoleColor.Cyan; Console.SetCursorPosition(15, 19); Console.WriteLine("LA SURFACE D'UNE ELLIPSE"); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("Donnez la taille de la moitier du grand axe"); float mga = float.Parse(Console.ReadLine()); Console.WriteLine("Donnez la taille de la moitier du grand axe"); float mpa = float.Parse(Console.ReadLine()); Ellipse El = new Ellipse(mga, mpa); float aireEllipse = El.Aire(); Console.WriteLine("La surface d'une Ellipse de {0} Cm de grand axe et de {1} Cm de petit axe est : {2} Cm2", mga, mpa, aireEllipse); Console.ReadLine(); break; // Calcul de la surface d'un Hexagone Regulier case 12: Console.ForegroundColor = ConsoleColor.DarkYellow; Console.SetCursorPosition(15, 19); Console.WriteLine("LA SURFACE D'UN HEXAGONE"); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("Donnez la longueur du Coté de l'Hexagone"); float Ct = float.Parse(Console.ReadLine()); Hexagone He = new Hexagone(Ct); float aireHexagone = He.Aire(); Console.WriteLine("La surface d'un Hexagone de {0} Cm de cote est : {1} m2", Ct, aireHexagone); Console.ReadLine(); break; default: break; } } while (reponse != 0); }
public bool Visit(Cercle _c) { Console.WriteLine(_c.ToString()); return(true); }
public void dessineAt(Graphics g, Point offsetPoint, bool showSelection, Matrix matrixToApply, float xScale, float yScale) { try { Rectangle rectDest = new Rectangle(new Point(offsetPoint.X + this.surfaceRect.Location.X, offsetPoint.Y + this.surfaceRect.Location.Y), this.surfaceRect.Size); Matrix m = null; if (matrixToApply != null) { m = matrixToApply; } else { m = this.getMatrixForDrawing(rectDest, xScale, yScale); } //Si c'est un sprite ----------- if (this.type.Equals("SPRITE")) { if (this.CoronaObjectParent != null) { if (this.SpriteSet != null) { if (this.currentFrame < this.SpriteSet.Frames.Count) { g.Transform = m; if (this.CurrentSequence == "") { this.setSequence(""); } if (this.CurrentSequence == "DEFAULT") { Image image = this.SpriteSet.Frames[this.currentFrame].Image; float factor = this.SpriteSet.Frames[this.currentFrame].SpriteSheetParent.FramesFactor; if (factor <= 0) { factor = 1; } int width = Convert.ToInt32((float)image.Size.Width / factor); int height = Convert.ToInt32((float)image.Size.Height / factor); this.surfaceRect = new Rectangle(this.surfaceRect.Location, new Size(width, height)); g.DrawImage(image, rectDest.X, rectDest.Y, this.surfaceRect.Width, this.surfaceRect.Height); } else { CoronaSpriteSetSequence sequence = this.getSequenceByName(this.CurrentSequence); if (sequence == null) { this.setSequence(""); Image image = this.SpriteSet.Frames[this.currentFrame].Image; float factor = this.SpriteSet.Frames[this.currentFrame].SpriteSheetParent.FramesFactor; if (factor <= 0) { factor = 1; } int width = Convert.ToInt32((float)image.Size.Width / factor); int height = Convert.ToInt32((float)image.Size.Height / factor); this.surfaceRect = new Rectangle(this.surfaceRect.Location, new Size(width, height)); g.DrawImage(image, rectDest.X, rectDest.Y, this.surfaceRect.Width, this.surfaceRect.Height); } else { int convertedFrame = this.currentFrame + sequence.FrameDepart - 1; Image image = this.SpriteSet.Frames[convertedFrame].Image; float factor = this.SpriteSet.Frames[convertedFrame].SpriteSheetParent.FramesFactor; if (factor <= 0) { factor = 1; } int width = Convert.ToInt32((float)image.Size.Width / factor); int height = Convert.ToInt32((float)image.Size.Height / factor); this.surfaceRect = new Rectangle(this.surfaceRect.Location, new Size(width, height)); g.DrawImage(image, rectDest.X, rectDest.Y, this.surfaceRect.Width, this.surfaceRect.Height); } } } } } else if (this.AnimSpritePictBxParent != null) { if (this.SpriteSet.Frames.Count > 0) { Image img = this.SpriteSet.Frames[CurrentFrame].Image; if (img.Height > this.AnimSpritePictBxParent.Height || img.Height > this.AnimSpritePictBxParent.Height) { g.DrawImage(img, 0, 0, this.AnimSpritePictBxParent.Width, this.AnimSpritePictBxParent.Height); } else { int xDest = System.Convert.ToInt32(this.AnimSpritePictBxParent.Size.Width * 0.5 - rectDest.Size.Width * 0.5); int yDest = System.Convert.ToInt32(this.AnimSpritePictBxParent.Size.Height * 0.5 - rectDest.Size.Height * 0.5); Point pDest = new Point(xDest, yDest); g.DrawImage(img, pDest); } } } } //Si c'est une image simple ----------- else if (this.type.Equals("IMAGE")) { if (this.CoronaObjectParent != null) { g.Transform = m; if (this.ImageFillColor.IsEmpty) { this.ImageFillColor = Color.White; } float tR = (float)ImageFillColor.R / 255; float tG = (float)ImageFillColor.G / 255; float tB = (float)ImageFillColor.B / 255; float tA = this.Alpha; ColorMatrix cm = new ColorMatrix(new float[][] { new float[] { tR, 0, 0, 0, 0 }, new float[] { 0, tG, 0, 0, 0 }, new float[] { 0, 0, tB, 0, 0 }, new float[] { 0, 0, 0, tA, 0 }, new float[] { 0, 0, 0, 0, 1 } }); // Create ImageAttributes ImageAttributes imgAttribs = new ImageAttributes(); // Set color matrix imgAttribs.SetColorMatrix(cm); try { // Draw image with ImageAttributes g.DrawImage(image, rectDest, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imgAttribs); } catch (Exception ex) { } } } //Si c'est une figure ----------- else if (this.type.Equals("FIGURE")) { int alphaARGB = System.Convert.ToInt32(this.Alpha * 255); if (this.Figure.ShapeType.Equals("RECTANGLE")) { Rect rect = this.Figure as Rect; g.Transform = m; rect.DessineAt(g, rectDest.Location, alphaARGB); } else if (this.Figure.ShapeType.Equals("CIRCLE")) { Cercle circ = this.Figure as Cercle; g.Transform = m; circ.DessineAt(g, rectDest.Location, alphaARGB); } else if (this.Figure.ShapeType.Equals("CURVE")) { CourbeBezier bezier = this.Figure as CourbeBezier; g.Transform = m; bezier.Dessine(g, alphaARGB, offsetPoint); } else if (this.Figure.ShapeType.Equals("LINE")) { Line line = this.Figure as Line; g.Transform = m; line.Dessine(g, alphaARGB, offsetPoint); } else if (this.Figure.ShapeType.Equals("TEXT")) { Texte txt = this.Figure as Texte; g.Transform = m; txt.DessineAt(g, rectDest.Location, alphaARGB); rectDest = new Rectangle(rectDest.Location, new Size((int)txt.stringSize.Width, (int)txt.stringSize.Height)); } } //DRAW SELECTION if (showSelection == true) { if (this.CoronaObjectParent.isSelected == true) { /* float[] dashValues = { 2, 2 }; * Pen pen = new Pen(Color.FromArgb(150, Color.Blue), 3); * pen.DashPattern = dashValues; * * g.ResetTransform();*/ Matrix matrixPath = new Matrix(); matrixPath.Scale(xScale, yScale); g.Transform = matrixPath; if (this.CoronaObjectParent.PathFollow != null) { if (this.CoronaObjectParent.PathFollow.isEnabled == true) { this.CoronaObjectParent.PathFollow.dessine(g, offsetPoint); } } if (this.CoronaObjectParent.TransformBox != null) { this.CoronaObjectParent.TransformBox.drawTransformBox(g, offsetPoint, xScale, yScale); } /* GraphicsPath gp = new GraphicsPath(); * * gp.AddRectangle(rectDest); * * RectangleF rectF = gp.GetBounds(m); * g.DrawRectangle(pen, rectF.X, rectF.Y, rectF.Width, rectF.Height);*/ g.Transform = m; } } } catch (Exception Exception) { } }
public void DrawGorgon(Point offsetPoint, bool showSelection, float xScale, float yScale, bool applyRotation) { try { Rectangle rectDest = new Rectangle(new Point(offsetPoint.X + this.surfaceRect.Location.X, offsetPoint.Y + this.surfaceRect.Location.Y), this.surfaceRect.Size); //Si c'est un sprite ----------- if (this.type.Equals("SPRITE")) { if (this.GorgonSprite != null) { this.GorgonSprite.Color = Color.FromArgb((int)(this.Alpha * 255.0f), Color.White); float imgScaleX = (float)this.SurfaceRect.Width / (float)this.GorgonSprite.Image.Width; float imgScaleY = (float)this.SurfaceRect.Height / (float)this.GorgonSprite.Image.Height; float finalXScale = xScale * imgScaleX; float finalYScale = yScale * imgScaleY; this.GorgonSprite.SetScale(finalXScale, finalYScale); this.GorgonSprite.SetAxis((float)this.GorgonSprite.Image.Width / 2, (float)this.GorgonSprite.Image.Height / 2); this.GorgonSprite.SetPosition((float)rectDest.X * xScale + (this.GorgonSprite.Axis.X * finalXScale), (float)rectDest.Y * yScale + (this.GorgonSprite.Axis.Y * finalYScale)); if (applyRotation == true) { this.GorgonSprite.Rotation = this.Rotation; } else { this.GorgonSprite.Rotation = 0; } this.GorgonSprite.Draw(); } } //Si c'est une image simple ----------- else if (this.type.Equals("IMAGE")) { if (this.GorgonSprite != null) { if (this.ImageFillColor.IsEmpty) { this.ImageFillColor = Color.White; } this.GorgonSprite.Color = Color.FromArgb((int)(this.Alpha * 255.0f), this.ImageFillColor); float imgScaleX = (float)this.SurfaceRect.Width / (float)this.GorgonSprite.Image.Width; float imgScaleY = (float)this.SurfaceRect.Height / (float)this.GorgonSprite.Image.Height; float finalXScale = xScale * imgScaleX; float finalYScale = yScale * imgScaleY; this.GorgonSprite.SetScale(finalXScale, finalYScale); this.GorgonSprite.SetAxis((float)this.GorgonSprite.Image.Width / 2, (float)this.GorgonSprite.Image.Height / 2); if (applyRotation == true) { this.GorgonSprite.Rotation = this.Rotation; } else { this.GorgonSprite.Rotation = 0; } this.GorgonSprite.SetPosition((float)rectDest.X * xScale + (this.GorgonSprite.Axis.X * finalXScale), (float)rectDest.Y * yScale + (this.GorgonSprite.Axis.Y * finalYScale)); this.GorgonSprite.Draw(); } } //Si c'est une figure ----------- else if (this.type.Equals("FIGURE")) { int alphaARGB = System.Convert.ToInt32(this.Alpha * 255); if (this.Figure.ShapeType.Equals("RECTANGLE")) { if (this.GorgonSprite != null) { float imgScaleX = (float)this.SurfaceRect.Width / (float)this.GorgonSprite.Image.Width; float imgScaleY = (float)this.SurfaceRect.Height / (float)this.GorgonSprite.Image.Height; float finalXScale = xScale * imgScaleX; float finalYScale = yScale * imgScaleY; this.GorgonSprite.SetScale(finalXScale, finalYScale); this.GorgonSprite.SetAxis((float)this.GorgonSprite.Image.Width / 2, (float)this.GorgonSprite.Image.Height / 2); this.GorgonSprite.Rotation = this.Rotation; this.GorgonSprite.SetPosition((float)rectDest.X * xScale + (this.GorgonSprite.Axis.X * finalXScale), (float)rectDest.Y * yScale + (this.GorgonSprite.Axis.Y * finalYScale)); this.GorgonSprite.Draw(); } } else if (this.Figure.ShapeType.Equals("CIRCLE")) { Cercle circ = this.Figure as Cercle; circ.DrawGorgon(offsetPoint, alphaARGB, xScale); } else if (this.Figure.ShapeType.Equals("CURVE")) { CourbeBezier bezier = this.Figure as CourbeBezier; bezier.DrawGorgon(offsetPoint, alphaARGB, xScale); } else if (this.Figure.ShapeType.Equals("LINE")) { Line line = this.Figure as Line; line.DrawGorgon(offsetPoint, alphaARGB, xScale); } else if (this.Figure.ShapeType.Equals("TEXT")) { Krea.CGE_Figures.Texte textObject = this.Figure as Krea.CGE_Figures.Texte; string fontName = "DEFAULT"; if (textObject.font2.FontItem != null) { fontName = textObject.font2.FontItem.NameForIphone; } GorgonGraphicsHelper.Instance.DrawText(textObject.txt, fontName, textObject.font2.Size, Point.Empty, Color.FromArgb((int)(this.Alpha * 255.0f), textObject.FillColor), this.Rotation, true, new Rectangle(offsetPoint.X + this.SurfaceRect.X, offsetPoint.Y + this.SurfaceRect.Y, this.surfaceRect.Width, this.surfaceRect.Height), xScale); //if (textObject.TextSprite != null) //{ // textObject.TextSprite.Text = textObject.txt; // textObject.TextSprite.Font.FontSize = textObject.font2.Size * xScale; // textObject.TextSprite.Color = Color.FromArgb((int)(this.Alpha * 255.0f), // textObject.FillColor.R, textObject.FillColor.G, textObject.FillColor.B); // textObject.TextSprite.SetAxis((float)textObject.TextSprite.Width / 2, (float)textObject.TextSprite.Height / 2); // textObject.TextSprite.SetPosition((float)this.SurfaceRect.X + textObject.TextSprite.Axis.X + offsetPoint.X, // (float)this.SurfaceRect.Y + textObject.TextSprite.Axis.Y + offsetPoint.Y); // textObject.TextSprite.Rotation = this.Rotation; // textObject.TextSprite.SetScale(xScale, yScale); // textObject.TextSprite.Draw(); //} //if (this.GorgonSprite != null) //{ // this.GorgonSprite.SetScale(xScale, yScale); // this.GorgonSprite.SetAxis((float)this.GorgonSprite.Image.Width / 2, (float)this.GorgonSprite.Image.Height / 2); // this.GorgonSprite.Rotation = this.Rotation; // this.GorgonSprite.SetPosition((float)rectDest.X * xScale + (this.GorgonSprite.Axis.X * xScale), // (float)rectDest.Y * yScale + (this.GorgonSprite.Axis.Y * yScale)); // this.GorgonSprite.Draw(); //} } } //DRAW SELECTION if (showSelection == true) { if (this.CoronaObjectParent.isSelected == true) { if (this.CoronaObjectParent.PathFollow != null) { if (this.CoronaObjectParent.PathFollow.isEnabled == true) { this.CoronaObjectParent.PathFollow.drawGorgon(offsetPoint, xScale); } } if (this.CoronaObjectParent.TransformBox != null) { this.CoronaObjectParent.TransformBox.drawGorgon(offsetPoint, xScale); } } } } catch (Exception Exception) { } }
//DateTime prec = DateTime.Now; void timerDeplacement_Elapsed(object sender, ElapsedEventArgs e) { // Calcul du temps écoulé depuis la dernière mise à jour de la position double intervalle = 0; if (watch != null) { intervalle = watch.ElapsedMilliseconds; watch.Restart(); } else watch = Stopwatch.StartNew(); //prec = DateTime.Now; SemDeplacement.WaitOne(); if (pointCourantTrajPolaire >= 0) { double distanceAvantProchainPoint = Position.Coordonnees.Distance(trajectoirePolaire[pointCourantTrajPolaire]); double distanceTotaleRestante = distanceAvantProchainPoint; distanceTotaleRestante += DistanceParcours(trajectoirePolaire, pointCourantTrajPolaire, trajectoirePolaire.Count - 1); if (distanceTotaleRestante > DistanceFreinageActuelle) VitesseActuelle = Math.Min(VitesseDeplacement, VitesseActuelle + AccelerationDebutDeplacement / (1000.0 / intervalle)); else VitesseActuelle = VitesseActuelle - AccelerationDebutDeplacement / (1000.0 / intervalle); double distanceAParcourir = VitesseActuelle / (1000.0 / intervalle); double distanceTestee = distanceAvantProchainPoint; bool changePoint = false; while (distanceTestee < distanceAParcourir && pointCourantTrajPolaire < trajectoirePolaire.Count - 1) { pointCourantTrajPolaire++; distanceTestee += trajectoirePolaire[pointCourantTrajPolaire - 1].Distance(trajectoirePolaire[pointCourantTrajPolaire]); changePoint = true; } Segment seg = null; Cercle cer = null; if(changePoint) { seg = new Segment(trajectoirePolaire[pointCourantTrajPolaire - 1], trajectoirePolaire[pointCourantTrajPolaire]); cer = new Cercle(trajectoirePolaire[pointCourantTrajPolaire - 1], distanceAParcourir - (distanceTestee - trajectoirePolaire[pointCourantTrajPolaire - 1].Distance(trajectoirePolaire[pointCourantTrajPolaire]))); } else { seg = new Segment(Position.Coordonnees, trajectoirePolaire[pointCourantTrajPolaire]); cer = new Cercle(Position.Coordonnees, distanceAParcourir); } PointReel newPos = seg.Croisements(cer)[0]; Angle a = -Maths.GetDirection(newPos, trajectoirePolaire[pointCourantTrajPolaire]).angle; position = new Position(a, newPos); ChangerPosition(Position); if (pointCourantTrajPolaire == trajectoirePolaire.Count - 1) { pointCourantTrajPolaire = -1; Destination.Copie(Position); } } else { double difference = Destination.Coordonnees.Distance(Position.Coordonnees); Angle adifference = Position.Angle - Destination.Angle; if (Math.Abs(adifference.AngleDegres) > 0.01)// Math.Round(Position.Angle.AngleDegres, 2) != Math.Round(Destination.Angle.AngleDegres, 2)) { Angle diff = Destination.Angle - Position.Angle; int coeff = 1; if (SensPivot == SensGD.Gauche) coeff = -1; double distance = Math.Abs(adifference.AngleDegres) / 360.0 * Entraxe * Math.PI; if (distance > AngleFreinageActuel) VitesseActuelle = Math.Min(VitessePivot, VitesseActuelle + AccelerationPivot / (1000.0 / intervalle)); else VitesseActuelle = VitesseActuelle - AccelerationPivot / (1000.0 / intervalle); if (Math.Abs(diff.AngleDegres) >= VitesseActuelle / (1000.0 / intervalle)) Position.Angle.Tourner(coeff * VitesseActuelle / (1000.0 / intervalle)); else if (Math.Abs(diff.AngleDegres) <= -VitesseActuelle / (1000.0 / intervalle)) Position.Angle.Tourner(coeff * VitesseActuelle / (1000.0 / intervalle)); else Position.Angle.Tourner(diff.AngleDegres); ChangerPosition(Position); } else if (difference > 0) { // Phase accélération ou déccélération if (Position.Coordonnees.Distance(Destination.Coordonnees) > DistanceFreinageActuelle) VitesseActuelle = Math.Min(VitesseDeplacement, VitesseActuelle + AccelerationDebutDeplacement / (1000.0 / intervalle)); else VitesseActuelle = VitesseActuelle - AccelerationDebutDeplacement / (1000.0 / intervalle); double distance = VitesseActuelle / (1000.0 / intervalle); //VitesseActuelle += AccellerationDeplacement / (1000 / IntervalleRafraichissementPosition); if (Destination.Coordonnees.Distance(Position.Coordonnees) <= distance) { VitesseActuelle = 0; //Position = Destination;//.Avancer(Destination.Coordonnees.Distance(Position.Coordonnees)); //Position.Coordonnees.X = Destination.Coordonnees.X; //Position.Coordonnees.Y = Destination.Coordonnees.Y; //Position.Angle.Set(Destination.Angle); //Position.Coordonnees.Placer(Destination.Coordonnees.X, Destination.Coordonnees.Y); Position.Copie(Destination); DeplacementLigne = false; } else { if (SensDep == SensAR.Avant) Position.Avancer(distance); else Position.Avancer(-distance); } ChangerPosition(Position); } } SemDeplacement.Release(); }
private static void DessinerForme(Graphics graphics, Color color, int epaisseur, Cercle Cercle, bool plein = false) { Point positionEcran = RealToScreenPosition(Cercle.Centre); int rayonEcran = RealToScreenDistance(Cercle.Rayon); if (!plein) using (Pen pen = new Pen(color, epaisseur)) graphics.DrawEllipse(pen, new Rectangle(positionEcran.X - rayonEcran, positionEcran.Y - rayonEcran, rayonEcran * 2, rayonEcran * 2)); else using (SolidBrush brush = new SolidBrush(color)) graphics.FillEllipse(brush, new Rectangle(positionEcran.X - rayonEcran, positionEcran.Y - rayonEcran, rayonEcran * 2, rayonEcran * 2)); }
public void drawGorgonBodyElements(Color color, bool applyPointsAjustingWithParent, Point offsetPoint, float worldScale, bool applyRotation) { if (this.BodyElements.Count == 0) { this.isCustomizedBody = false; } Color colorElements = Color.FromArgb(150, Color.GreenYellow); if (this.isCustomizedBody == true) { for (int i = 0; i < this.BodyElements.Count; i++) { BodyElement elem = this.BodyElements[i]; if (elem.Type.Equals("SHAPE")) { if (applyPointsAjustingWithParent == true) { //Creer un tableau de points ajustés List <Point> tabPointsAjust = new List <Point>(); Point middlePoint = new Point(objectParent.DisplayObject.SurfaceRect.X + objectParent.DisplayObject.SurfaceRect.Width / 2 + offsetPoint.X, objectParent.DisplayObject.SurfaceRect.Y + objectParent.DisplayObject.SurfaceRect.Height / 2 + offsetPoint.Y); float angle = this.objectParent.DisplayObject.Rotation; double cosRotation = Math.Cos(Math.PI * angle / 180.0); double sinRotation = Math.Sin(Math.PI * angle / 180.0); for (int j = 0; j < elem.BodyShape.Count; j++) { Point pAjust = new Point(elem.BodyShape[j].X + this.objectParent.DisplayObject.SurfaceRect.X + offsetPoint.X, elem.BodyShape[j].Y + this.objectParent.DisplayObject.SurfaceRect.Y + offsetPoint.Y); if (applyRotation == true) { int rotatedX = (int)(middlePoint.X + cosRotation * (pAjust.X - middlePoint.X) - Math.Sin(Math.PI * angle / 180.0) * (pAjust.Y - middlePoint.Y)); int rotatedY = (int)(middlePoint.Y + sinRotation * (pAjust.X - middlePoint.X) + cosRotation * (pAjust.Y - middlePoint.Y)); Point pRotated = new Point(rotatedX, rotatedY); tabPointsAjust.Insert(j, pRotated); } else { tabPointsAjust.Insert(j, pAjust); } //Close the figure if (j == elem.BodyShape.Count - 1) { tabPointsAjust.Add(tabPointsAjust[0]); } } GorgonGraphicsHelper.Instance.DrawLines(tabPointsAjust, colorElements, 1, worldScale); } else { //Creer un tableau de points ajustés List <Point> tabPointsAjust = new List <Point>(); Point middlePoint = new Point(objectParent.DisplayObject.SurfaceRect.Width / 2, objectParent.DisplayObject.SurfaceRect.Height / 2); float angle = this.objectParent.DisplayObject.Rotation; double cosRotation = Math.Cos(Math.PI * angle / 180.0); double sinRotation = Math.Sin(Math.PI * angle / 180.0); for (int j = 0; j < elem.BodyShape.Count; j++) { Point pAjust = new Point((int)((float)(elem.BodyShape[j].X + offsetPoint.X)), (int)((float)(elem.BodyShape[j].Y + offsetPoint.Y))); if (applyRotation == true) { int rotatedX = (int)(middlePoint.X + cosRotation * (pAjust.X - middlePoint.X) - Math.Sin(Math.PI * angle / 180.0) * (pAjust.Y - middlePoint.Y)); int rotatedY = (int)(middlePoint.Y + sinRotation * (pAjust.X - middlePoint.X) + cosRotation * (pAjust.Y - middlePoint.Y)); Point pRotated = new Point(rotatedX, rotatedY); tabPointsAjust.Insert(j, pRotated); } else { tabPointsAjust.Insert(j, pAjust); } //Close the figure if (j == elem.BodyShape.Count - 1) { tabPointsAjust.Add(tabPointsAjust[0]); } } GorgonGraphicsHelper.Instance.DrawLines(tabPointsAjust, colorElements, 1, worldScale); } } else if (elem.Type.Equals("CIRCLE")) { int radius = elem.Radius; if (applyPointsAjustingWithParent == true) { GorgonGraphicsHelper.Instance.FillCircle(elem.SurfaceCircle.X + this.objectParent.DisplayObject.SurfaceRect.X + offsetPoint.X, elem.SurfaceCircle.Y + this.objectParent.DisplayObject.SurfaceRect.Y + offsetPoint.Y, elem.Radius, colorElements, worldScale, false); } else { GorgonGraphicsHelper.Instance.FillCircle(elem.SurfaceCircle.X + offsetPoint.X, elem.SurfaceCircle.Y + offsetPoint.Y, elem.Radius, colorElements, worldScale, false); } } else if (elem.Type.Equals("LINE")) { if (applyPointsAjustingWithParent == true) { //Creer un tableau de points ajustés List <Point> tabPointsAjust = new List <Point>(); for (int j = 0; j < elem.BodyShape.Count; j++) { Point pAjust = new Point(elem.BodyShape[j].X + this.objectParent.DisplayObject.SurfaceRect.X + offsetPoint.X, elem.BodyShape[j].Y + this.objectParent.DisplayObject.SurfaceRect.Y + offsetPoint.Y); tabPointsAjust.Insert(j, pAjust); } GorgonGraphicsHelper.Instance.DrawLines(tabPointsAjust, colorElements, 2, worldScale); } else { //Creer un tableau de points ajustés List <Point> tabPointsAjust = new List <Point>(); for (int j = 0; j < elem.BodyShape.Count; j++) { Point pAjust = new Point(elem.BodyShape[j].X + offsetPoint.X, elem.BodyShape[j].Y + offsetPoint.Y); tabPointsAjust.Insert(j, pAjust); } GorgonGraphicsHelper.Instance.DrawLines(tabPointsAjust, colorElements, 2, worldScale); } } } } else { DisplayObject dispObj = this.objectParent.DisplayObject; if (dispObj.Type.Equals("FIGURE")) { Figure fig = this.objectParent.DisplayObject.Figure; if (fig != null) { if (fig.ShapeType.Equals("CIRCLE")) { Cercle circ = fig as Cercle; GorgonGraphicsHelper.Instance.FillCircle(circ.Position.X + offsetPoint.X, circ.Position.Y + offsetPoint.Y, circ.Rayon, colorElements, worldScale, false); } else if (fig.ShapeType.Equals("RECTANGLE")) { Rect rect = fig as Rect; //GorgonGraphicsHelper.Instance.FillRectangle(new Rectangle(rect.Position.X + offsetPoint.X, // rect.Position.Y + offsetPoint.Y, rect.Width, rect.Height), // 2, colorElements, worldScale); //Creer un tableau de points ajustés List <Point> tabPointsAjust = new List <Point>(); Point middlePoint = new Point(objectParent.DisplayObject.SurfaceRect.X + objectParent.DisplayObject.SurfaceRect.Width / 2 + offsetPoint.X, objectParent.DisplayObject.SurfaceRect.Y + objectParent.DisplayObject.SurfaceRect.Height / 2 + offsetPoint.Y); float angle = this.objectParent.DisplayObject.Rotation; double cosRotation = Math.Cos(Math.PI * angle / 180.0); double sinRotation = Math.Sin(Math.PI * angle / 180.0); List <Point> rectPoints = new List <Point>(); rectPoints.Add(rect.Position); rectPoints.Add(new Point(rect.Position.X + rect.Width, rect.Position.Y)); rectPoints.Add(new Point(rect.Position.X + rect.Width, dispObj.SurfaceRect.Bottom)); rectPoints.Add(new Point(rect.Position.X, dispObj.SurfaceRect.Bottom)); for (int j = 0; j < rectPoints.Count; j++) { Point pAjust = new Point((int)((float)(rectPoints[j].X + offsetPoint.X)), (int)((float)(rectPoints[j].Y + offsetPoint.Y))); if (applyRotation == true) { int rotatedX = (int)(middlePoint.X + cosRotation * (pAjust.X - middlePoint.X) - Math.Sin(Math.PI * angle / 180.0) * (pAjust.Y - middlePoint.Y)); int rotatedY = (int)(middlePoint.Y + sinRotation * (pAjust.X - middlePoint.X) + cosRotation * (pAjust.Y - middlePoint.Y)); Point pRotated = new Point(rotatedX, rotatedY); tabPointsAjust.Insert(j, pRotated); } else { tabPointsAjust.Insert(j, pAjust); } //Close the figure if (j == rectPoints.Count - 1) { tabPointsAjust.Add(tabPointsAjust[0]); } } GorgonGraphicsHelper.Instance.DrawLines(tabPointsAjust, colorElements, 1, worldScale); } else if (fig.ShapeType.Equals("LINE")) { Krea.CGE_Figures.Line line = fig as Krea.CGE_Figures.Line; //Convertir tous les points et leur ajouter un offset //Creer un tableau de points ajustés List <Point> tabPointsAjust = new List <Point>(); for (int j = 0; j < line.Points.Count; j++) { Point pAjust = new Point(line.Points[j].X + offsetPoint.X, line.Points[j].Y + offsetPoint.Y); tabPointsAjust.Insert(j, pAjust); } GorgonGraphicsHelper.Instance.DrawLines(tabPointsAjust, colorElements, 2, worldScale); } else if (fig.ShapeType.Equals("TEXT")) { GorgonGraphicsHelper.Instance.FillRectangle(dispObj.SurfaceRect, 2, colorElements, worldScale, false); } } } else { if (applyPointsAjustingWithParent == true) { //GorgonGraphicsHelper.Instance.FillRectangle(new Rectangle(dispObj.SurfaceRect.X + offsetPoint.X, dispObj.SurfaceRect.Y + offsetPoint.Y, // dispObj.SurfaceRect.Width, dispObj.SurfaceRect.Height), 2, colorElements, worldScale); //Creer un tableau de points ajustés List <Point> tabPointsAjust = new List <Point>(); Point middlePoint = new Point(objectParent.DisplayObject.SurfaceRect.X + objectParent.DisplayObject.SurfaceRect.Width / 2 + offsetPoint.X, objectParent.DisplayObject.SurfaceRect.Y + objectParent.DisplayObject.SurfaceRect.Height / 2 + offsetPoint.Y); float angle = this.objectParent.DisplayObject.Rotation; double cosRotation = Math.Cos(Math.PI * angle / 180.0); double sinRotation = Math.Sin(Math.PI * angle / 180.0); List <Point> rectPoints = new List <Point>(); rectPoints.Add(dispObj.SurfaceRect.Location); rectPoints.Add(new Point(dispObj.SurfaceRect.Right, dispObj.SurfaceRect.Top)); rectPoints.Add(new Point(dispObj.SurfaceRect.Right, dispObj.SurfaceRect.Bottom)); rectPoints.Add(new Point(dispObj.SurfaceRect.Left, dispObj.SurfaceRect.Bottom)); for (int j = 0; j < rectPoints.Count; j++) { Point pAjust = new Point((int)((float)(rectPoints[j].X + offsetPoint.X)), (int)((float)(rectPoints[j].Y + offsetPoint.Y))); if (applyRotation == true) { int rotatedX = (int)(middlePoint.X + cosRotation * (pAjust.X - middlePoint.X) - Math.Sin(Math.PI * angle / 180.0) * (pAjust.Y - middlePoint.Y)); int rotatedY = (int)(middlePoint.Y + sinRotation * (pAjust.X - middlePoint.X) + cosRotation * (pAjust.Y - middlePoint.Y)); Point pRotated = new Point(rotatedX, rotatedY); tabPointsAjust.Insert(j, pRotated); } else { tabPointsAjust.Insert(j, pAjust); } //Close the figure if (j == rectPoints.Count - 1) { tabPointsAjust.Add(tabPointsAjust[0]); } } GorgonGraphicsHelper.Instance.DrawLines(tabPointsAjust, colorElements, 1, worldScale); } else { //GorgonGraphicsHelper.FillRectangle(new Rectangle(offsetPoint.X, offsetPoint.Y, dispObj.SurfaceRect.Width, dispObj.SurfaceRect.Height), // 2, colorElements, worldScale); //Creer un tableau de points ajustés List <Point> tabPointsAjust = new List <Point>(); Point middlePoint = new Point(objectParent.DisplayObject.SurfaceRect.Width / 2 + offsetPoint.X, objectParent.DisplayObject.SurfaceRect.Height / 2 + offsetPoint.Y); float angle = this.objectParent.DisplayObject.Rotation; double cosRotation = Math.Cos(Math.PI * angle / 180.0); double sinRotation = Math.Sin(Math.PI * angle / 180.0); List <Point> rectPoints = new List <Point>(); rectPoints.Add(offsetPoint); rectPoints.Add(new Point(dispObj.SurfaceRect.Width + offsetPoint.X, offsetPoint.Y)); rectPoints.Add(new Point(dispObj.SurfaceRect.Width + offsetPoint.X, dispObj.SurfaceRect.Height + offsetPoint.Y)); rectPoints.Add(new Point(offsetPoint.X, dispObj.SurfaceRect.Height + offsetPoint.Y)); for (int j = 0; j < rectPoints.Count; j++) { Point pAjust = new Point((int)((float)(rectPoints[j].X + offsetPoint.X)), (int)((float)(rectPoints[j].Y + offsetPoint.Y))); if (applyRotation == true) { int rotatedX = (int)(middlePoint.X + cosRotation * (pAjust.X - middlePoint.X) - Math.Sin(Math.PI * angle / 180.0) * (pAjust.Y - middlePoint.Y)); int rotatedY = (int)(middlePoint.Y + sinRotation * (pAjust.X - middlePoint.X) + cosRotation * (pAjust.Y - middlePoint.Y)); Point pRotated = new Point(rotatedX, rotatedY); tabPointsAjust.Insert(j, pRotated); } else { tabPointsAjust.Insert(j, pAjust); } //Close the figure if (j == rectPoints.Count - 1) { tabPointsAjust.Add(tabPointsAjust[0]); } } GorgonGraphicsHelper.Instance.DrawLines(tabPointsAjust, colorElements, 1, worldScale); } } } }
public String getPhysicsParams(CoronaObject objParent, float XRatio, float YRatio) { string paramsPhysics = ""; float moyenneRatio = (XRatio + YRatio) / 2; if (this.isCustomizedBody == true) { for (int i = 0; i < this.BodyElements.Count; i++) { BodyElement elem = this.BodyElements[i]; if (i > 0) { paramsPhysics += ",\n"; } paramsPhysics += "{ "; //Recuperer les properties /* paramsPhysics += ("bounce =" + ((float)elem.Bounce / moyenneRatio)).Replace(",", ".") + ","; * paramsPhysics += ("density =" + ((float)elem.Density/ moyenneRatio)).Replace(",", ".") + ","; * paramsPhysics += ("friction =" + ((float)elem.Friction / moyenneRatio)).Replace(",", "."); * paramsPhysics += ",filter = " + this.getCollisionFilter();*/ paramsPhysics += "bounce =" + elem.Bounce.ToString().Replace(",", ".") + ","; paramsPhysics += "density =" + elem.Density.ToString().Replace(",", ".") + ","; paramsPhysics += "friction =" + elem.Friction.ToString().Replace(",", "."); paramsPhysics += ",isSensor =" + elem.IsSensor.ToString().ToLower() + ","; if (elem.CollisionGroupIndex > 0) { paramsPhysics += "filter = " + this.getCollisionFilter(elem.CollisionGroupIndex); } else { paramsPhysics += "filter = " + this.getCollisionFilter(this.CollisionGroupIndex); } if (elem.Type.Equals("CIRCLE")) { if (elem.Radius > 0) { paramsPhysics += ",radius =" + (elem.Radius * moyenneRatio).ToString().Replace(",", "."); } } else { if (objParent.DisplayObject.Type.Equals("FIGURE") && (objParent.DisplayObject.Figure.ShapeType.Equals("CURVE") || objParent.DisplayObject.Figure.ShapeType.Equals("LINE"))) { //Recuperer la shape du body si elle existe if (elem.BodyShape.Count > 1) { paramsPhysics += ",shape = {"; for (int j = 0; j < elem.BodyShape.Count; j++) { if (j != 0) { paramsPhysics += ",\n"; } Point p = elem.BodyShape[j]; paramsPhysics += ((float)(p.X - BodyElements[0].BodyShape[0].X) * XRatio).ToString().Replace(",", ".") + "," + ((float)(p.Y - BodyElements[0].BodyShape[0].Y) * YRatio).ToString().Replace(",", "."); } paramsPhysics += "}"; } } else { //Recuperer la shape du body si elle existe if (elem.BodyShape.Count > 1) { paramsPhysics += ",shape = {"; for (int j = 0; j < elem.BodyShape.Count; j++) { if (j != 0) { paramsPhysics += ",\n"; } Point p = elem.BodyShape[j]; paramsPhysics += ((float)((p.X - objParent.DisplayObject.SurfaceRect.Width / 2) * moyenneRatio)).ToString().Replace(",", ".") + "," + ((float)((p.Y - objParent.DisplayObject.SurfaceRect.Height / 2) * moyenneRatio)).ToString().Replace(",", "."); } paramsPhysics += "}"; } } } paramsPhysics += "}"; } } else { paramsPhysics += "{ "; //Recuperer les properties paramsPhysics += ("bounce =" + Bounce).Replace(",", ".") + ","; paramsPhysics += ("density =" + Density).Replace(",", ".") + ","; paramsPhysics += ("friction =" + Friction).Replace(",", "."); paramsPhysics += ",filter = " + this.getCollisionFilter(this.CollisionGroupIndex); if (objParent.DisplayObject.Type.Equals("FIGURE") && objParent.DisplayObject.Figure.ShapeType.Equals("CIRCLE")) { Cercle cercle = objParent.DisplayObject.Figure as Cercle; paramsPhysics += ",radius =" + ((float)cercle.Rayon * moyenneRatio).ToString().Replace(",", "."); } else if (this.Radius > 0) { paramsPhysics += ",radius =" + ((float)this.Radius * XRatio).ToString().Replace(",", "."); } else { float halfContentWidth = (float)this.objectParent.DisplayObject.SurfaceRect.Width / (float)2 * (float)XRatio; float halfContentHeight = (float)this.objectParent.DisplayObject.SurfaceRect.Height / (float)2 * (float)YRatio; paramsPhysics += ",shape = {" + (-halfContentWidth).ToString().Replace(",", ".") + "," + (-halfContentHeight).ToString().Replace(",", ".") + "," + (halfContentWidth).ToString().Replace(",", ".") + "," + (-halfContentHeight).ToString().Replace(",", ".") + "," + (halfContentWidth).ToString().Replace(",", ".") + "," + (halfContentHeight).ToString().Replace(",", ".") + "," + (-halfContentWidth).ToString().Replace(",", ".") + "," + (halfContentHeight).ToString().Replace(",", ".") + "}"; } paramsPhysics += "}"; } return(paramsPhysics); }