Ein 2D-Karten-Renderer?

  • VB.NET

Es gibt 28 Antworten in diesem Thema. Der letzte Beitrag () ist von PhoenixBlaster.

    @Quadsoft:: Selbst wenn Du ihm diesen Code in VB.NET vorsetzt, guckt er wie ein ..... (von der Zensur gestrichen). :D
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Dafür brauchst Du einen C#-VB-Translator.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Hier mal eine Schritt-für-Schritt-Anleitung für dich:
    1. Öffne die Landscape2D.cs mit dem Editor
    2. Kopiere den Inhalt
    3. Füge ihn hier ein: developerfusion.com/tools/convert/csharp-to-vb/
    4. Drücke auf Convert to VB.NET
    Dann kriegst du den VB-Code angezeigt und kannst ihn in ein neues Projekt kopieren.
    @PhoenixBlaster:: Dies hier ist Dein Thread. Du bist hier der Ober-Moderator.
    Wir beantworten Fragen und machen Vorschläge.
    Die Arbeit aber musst Du selbst machen.
    Wenn Du hier nicht bald die Initiative ergreifst, wirst Du bei einigen Mitgliedern wohl auf der Ignore-Liste landen.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Okay hab jetzt den C# Code aus Landscape2D.cs in VB konvertiert und habe das bekommen:

    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System.Collections.Generic
    2. Imports System.Linq
    3. Imports System.Text
    4. Imports System.Threading.Tasks
    5. Imports System.Drawing
    6. Class Landscape2D
    7. Public Shared Function GetLandscape(width As Integer, height As Integer) As Bitmap
    8. Dim bmp As New Bitmap(64, 64)
    9. Dim a As Double(,) = CalculateLandscape(2.5, 64 \ 7, 64)
    10. For i As Integer = 0 To 63
    11. For j As Integer = 0 To 63
    12. bmp.SetPixel(i, j, Mix(Color.Blue, Color.Green, CSng(Math.Abs(a(i, j) / 10))))
    13. Next
    14. Next
    15. Return bmp
    16. End Function
    17. Private Shared Function Mix(from As Color, [to] As Color, percent As Single) As Color
    18. If percent > 1 Then
    19. percent = 1
    20. End If
    21. Dim amountFrom As Single = 1.0F - percent
    22. Return Color.FromArgb(CInt(Math.Truncate(from.A * amountFrom + [to].A * percent)), CInt(Math.Truncate(from.R * amountFrom + [to].R * percent)), CInt(Math.Truncate(from.G * amountFrom + [to].G * percent)), CInt(Math.Truncate(from.B * amountFrom + [to].B * percent)))
    23. End Function
    24. Private Shared Function CalculateLandscape(dimension As Double, scaleFactor As Double, width As Integer) As Double(,)
    25. Dim a As Double(,) = New Double(width, width) {}
    26. Dim rand As New Random()
    27. ' Startkofinguration
    28. a(0, 0) = 1
    29. a(0, width) = 1
    30. a(width, 0) = 1
    31. a(width, width) = 1
    32. Dim divisionStage As Integer = 1
    33. Dim maxDivisionStage As Integer = width \ 2
    34. Dim x As Integer, y As Integer
    35. While divisionStage <= maxDivisionStage
    36. ' Mittelpunkte
    37. x = 0
    38. While x < width
    39. y = 0
    40. While y < width
    41. a(x + (width \ (2 * divisionStage)), y + (width \ (2 * divisionStage))) = a(x, y) + a(x, y + (width \ divisionStage)) + a(x + (width \ divisionStage), y) + a(x + (width \ divisionStage), y + (width \ divisionStage))
    42. a(x + (width \ (2 * divisionStage)), y + (width \ (2 * divisionStage))) /= 4
    43. If divisionStage > maxDivisionStage Then
    44. a(x + (width \ (2 * divisionStage)), y + (width \ (2 * divisionStage))) += (GetGauss(rand) * scaleFactor)
    45. End If
    46. y += width \ divisionStage
    47. End While
    48. x += width \ divisionStage
    49. End While
    50. scaleFactor *= Math.Pow(0.5, 3 - dimension)
    51. ' Seitenpunkte
    52. x = 0
    53. While x <= width
    54. y = 0
    55. While y <= width
    56. If x = y OrElse a(x, y) <> 0 Then
    57. Continue While
    58. End If
    59. If y = 0 Then
    60. a(x, y) = a(x - width \ (2 * divisionStage), y) + a(x + width \ (2 * divisionStage), y) + a(x, y + width \ (2 * divisionStage))
    61. a(x, y) /= 3
    62. a(x, y) += (GetGauss(rand) * scaleFactor)
    63. ElseIf y = width Then
    64. a(x, y) = a(x - width \ (2 * divisionStage), y) + a(x + width \ (2 * divisionStage), y) + a(x, y - width \ (2 * divisionStage))
    65. a(x, y) /= 3
    66. a(x, y) += (GetGauss(rand) * scaleFactor)
    67. ElseIf x = 0 Then
    68. a(x, y) = a(x, y - width \ (2 * divisionStage)) + a(x, y + width \ (2 * divisionStage)) + a(x + width \ (2 * divisionStage), y)
    69. a(x, y) /= 3
    70. a(x, y) += (GetGauss(rand) * scaleFactor)
    71. ElseIf x = width Then
    72. a(x, y) = a(x, y - width \ (2 * divisionStage)) + a(x, y + width \ (2 * divisionStage)) + a(x - width \ (2 * divisionStage), y)
    73. a(x, y) /= 3
    74. a(x, y) += (GetGauss(rand) * scaleFactor)
    75. Else
    76. a(x, y) = a(x, y - width \ (2 * divisionStage)) + a(x, y + width \ (2 * divisionStage)) + a(x - width \ (2 * divisionStage), y) + a(x + width \ (2 * divisionStage), y)
    77. a(x, y) /= 4
    78. a(x, y) += (GetGauss(rand) * scaleFactor)
    79. End If
    80. y += width \ (2 * divisionStage)
    81. End While
    82. x += width \ (2 * divisionStage)
    83. End While
    84. scaleFactor *= Math.Pow(0.5, 3 - dimension)
    85. divisionStage *= 2
    86. End While
    87. Return a
    88. End Function
    89. Private Shared Function GetGauss(rand As Random) As Double
    90. Dim res As Double = Math.Cos(2 * Math.PI * rand.NextDouble()) * Math.Sqrt(-2 * Math.Log(rand.NextDouble()))
    91. If rand.[Next](-1, 1) < 0 Then
    92. res *= -1
    93. End If
    94. Return res
    95. End Function
    96. End Class



    Könnt ihr mir vielleicht auch ein Anwendungsbeispiel geben. Zum Beispiel mit Button und Picturebox.

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „PhoenixBlaster“ ()