elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Sigue las noticias más importantes de seguridad informática en el Twitter! de elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Movimiento armónico simple [SOLUCIONADO]
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Movimiento armónico simple [SOLUCIONADO]  (Leído 2,196 veces)
Meta


Desconectado Desconectado

Mensajes: 3.438



Ver Perfil WWW
Movimiento armónico simple [SOLUCIONADO]
« en: 1 Agosto 2020, 01:25 am »

Hola:

Hace siglos que quice hacerlo pero no me salió. añado en el Windows Form un pictureBox, ahí dentro creo dos rayas, una vertical y otra horizontal con el círculo en medio, tal como indica la imagen de abajo.



Los puntos que muestran se tiene que mover tal como lo hace en el vídeo de abajo.

Ver vídeo.


Código hasta ahora.
Código
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Movimiento_armonico_simple_01_cs
  12. {
  13.    public partial class Form1 : Form
  14.    {
  15.        private int pt1a = 0, pt2y = 300, pt2s = -1, pt3x = 80, pt3s = 1;
  16.  
  17.        private void Form1_Load(object sender, EventArgs e)
  18.        {
  19.            timer1.Start();
  20.        }
  21.  
  22.        private void pictureBox1_Paint(object sender, PaintEventArgs e)
  23.        {
  24.            Graphics g = e.Graphics;
  25.            int ptx, pty;
  26.            g.Clear(Color.White);
  27.            g.DrawEllipse(Pens.Black, new Rectangle(40, 40, 300, 300));
  28.            g.DrawLine(Pens.Black, 20, 40, 20, 340);
  29.            g.DrawLine(Pens.Black, 40, 360, 340, 360);
  30.  
  31.            ptx = (int)(Math.Cos((double)pt1a * Math.PI / 180.0) * 150.0);
  32.            pty = (int)(Math.Sin((double)pt1a * Math.PI / 180.0) * 150.0);
  33.            g.FillEllipse(Brushes.Black, new Rectangle(190 + ptx - 5, 190 - pty - 5, 11, 11));
  34.  
  35.            g.FillEllipse(Brushes.Black, new Rectangle(15, pt2y - 5, 11, 11));
  36.  
  37.            g.FillEllipse(Brushes.Black, new Rectangle(pt3x - 5, 355, 11, 11));
  38.        }
  39.  
  40.        private void timer1_Tick(object sender, EventArgs e)
  41.        {
  42.            pt1a += 2;
  43.            if (pt1a >= 360)
  44.                pt1a -= 360;
  45.  
  46.            pt2y += 4 * pt2s;
  47.            if (pt2y <= 40 || pt2y >= 340)
  48.                pt2s = -pt2s;
  49.  
  50.            pt3x += 4 * pt3s;
  51.            if (pt3x <= 40 || pt3x >= 340)
  52.                pt3s = -pt3s;
  53.  
  54.            pictureBox1.Invalidate();
  55.        }
  56.  
  57.        public Form1()
  58.        {
  59.            InitializeComponent();
  60.        }
  61.    }
  62. }

¿Alguna idea?

Saludos.


« Última modificación: 1 Agosto 2020, 13:21 pm por Meta » En línea

Meta


Desconectado Desconectado

Mensajes: 3.438



Ver Perfil WWW
Re: Movimiento armónico simple
« Respuesta #1 en: 1 Agosto 2020, 13:20 pm »

Hola:

Hecho.
Código
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4.  
  5. namespace Movimiento_armonico_simple_01_cs
  6. {
  7.    public partial class Form1 : Form
  8.    {
  9.        private int pt1a = 0;
  10.  
  11.        private void timer1_Tick(object sender, EventArgs e)
  12.        {
  13.            pt1a += 2;
  14.            if (pt1a >= 360)
  15.                pt1a -= 360;
  16.  
  17.            pictureBox1.Invalidate();
  18.        }
  19.  
  20.        private void Form1_Load(object sender, EventArgs e)
  21.        {
  22.            timer1.Start();
  23.        }
  24.  
  25.        private void pictureBox1_Paint(object sender, PaintEventArgs e)
  26.        {
  27.            Graphics g = e.Graphics;
  28.            int ptx, pty;
  29.            g.Clear(Color.White);
  30.            g.DrawEllipse(Pens.Black, new Rectangle(40, 40, 300, 300));
  31.            g.DrawLine(Pens.Black, 20, 40, 20, 340);
  32.            g.DrawLine(Pens.Black, 40, 360, 340, 360);
  33.  
  34.            ptx = (int)(Math.Cos((double)pt1a * Math.PI / 180.0) * 150.0);
  35.            pty = (int)(Math.Sin((double)pt1a * Math.PI / 180.0) * 150.0);
  36.  
  37.            // Punto del círculo.
  38.            g.FillEllipse(Brushes.Black, new Rectangle(190 + ptx - 5, 190 - pty - 5, 11, 11));
  39.  
  40.            // Punto de la recta Y.
  41.            g.FillEllipse(Brushes.Black, new Rectangle(15, 190 - pty - 5, 11, 11));
  42.  
  43.  
  44.            // Punto de la recta X.
  45.            g.FillEllipse(Brushes.Black, new Rectangle(190 + ptx - 5, 355, 11, 11));
  46.  
  47.  
  48.            label_X.Text = "X:" + ptx.ToString();
  49.            label_Y.Text = "Y:" + pty.ToString();
  50.        }
  51.  
  52.        public Form1()
  53.        {
  54.            InitializeComponent();
  55.        }
  56.    }
  57. }

Saludos.


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Ayuda calculadora simple en PHP(solucionado)
PHP
Senior++ 2 3,526 Último mensaje 16 Noviembre 2013, 18:20 pm
por Senior++
[Solucionado] Problema con simple código en C++
Programación C/C++
Mario Olivera 1 1,837 Último mensaje 14 Agosto 2014, 21:57 pm
por Eternal Idol
[Solucionado] -seguridad en chat simple « 1 2 »
Programación Visual Basic
elezekiel 15 6,237 Último mensaje 1 Noviembre 2014, 04:11 am
por engel lex
Constructor de movimiento y asignacion de movimiento
Programación C/C++
AnthonyS 2 1,904 Último mensaje 1 Marzo 2017, 19:32 pm
por AnthonyS
Movimiento simple de un hexápodo
Programación C/C++
JoseRomero 0 1,069 Último mensaje 5 Octubre 2018, 20:48 pm
por JoseRomero
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines