Programas para Robots.
  Bresenham 2D
 
Me he trasladado a este "Site":

http://sites.google.com/site/proyectosroboticos/

Esta web dejó de actualizarse el 3 de marzo de 2009 a las 21:51h.






Este programa traza líneas en cualquier sentido.

El valor inicial es de (0,0).

Introduce valores para X entre 0 y 640, para Y entre 0 y 480.

Si implementas este programa para otra cosa (NO en este programa), comprobarás que también puedes introducir números negativos.

Bájate el programa cliqueando aquí.

Dim    As Integer   x,  y, Incrd1, Incrd2, IncrXold, IncrXnew, IncrYold, IncrYnew 
Dim    As Integer   DistX, DistY, NumPixel, Decision, Bucle
Dim    As Integer   Xnew, Ynew, Xold, Yold

Screen 12 ' Pantalla Grafica
  
Xold=0
Yold=0
  
While (1)
 Input "Eje X:", Xnew
 Input "Eje Y:", Ynew

 DistX = Abs(Xnew - Xold)

 DistY = Abs(Ynew - Yold)
  
 If DistX >= DistY Then
    NumPixel = DistX + 1
    Decision = (2 * DistY) - DistX
    Incrd1 = DistY * 2
    Incrd2 = (DistY - DistX) * 2
    IncrXold = 1
    IncrXnew = 1
    IncrYold = 0
    IncrYnew = 1
 Else
    NumPixel = DistY + 1
    Decision = (2 * DistX) - DistY
    Incrd1 = DistX * 2
    Incrd2 = (DistX - DistY) * 2
    IncrXold = 0
    IncrXnew = 1
    IncrYold = 1
    IncrYnew = 1
 End If
  
 If Xold > Xnew Then
    IncrXold = -IncrXold
    IncrXnew = -IncrXnew
 End If
  
 If Yold > Ynew Then
    IncrYold = -IncrYold
    IncrYnew = -IncrYnew
 End If
  
 x = Xold
 y = Yold
  
 For Bucle = 1 To NumPixel
 
       PSet (x,y), 1
      If Decision < 0 Then
        Decision = Decision + Incrd1
        x = x + IncrXold
        y = y + IncrYold
     Else
        Decision = Decision + Incrd2
        x = x + IncrXnew
        y = y + IncrYnew
     End If
   
 Next Bucle
  
 Xold = Xnew
 Yold = Ynew 

Wend

End
 
  19493 visitantes (37207 clics a subpáginas)  
 
Este sitio web fue creado de forma gratuita con PaginaWebGratis.es. ¿Quieres también tu sitio web propio?
Registrarse gratis