LightbulbDrawing 3-D Cube

Posts 1–3 of 3 · Page 1 of 1
Drawing 3-D Cube
Was bored to decided to draw an image of a 3-D cube in VB.net. Heres the function I created. Was checking the internet on how to do it, but the code I found was really long and complicated.

Code:
    Private Function DrawCube(ByVal Pen As Pen, ByVal Location As Point, ByVal Size As Integer) As Bitmap
        Dim _Bitmap As New Bitmap(Me.Width, Me.Height)
        Dim _Graphics As Graphics = Graphics.FromImage(_Bitmap)
        _Graphics.DrawRectangle(Pen, New Rectangle(Location, New Size(Size, Size)))
        _Graphics.DrawRectangle(Pen, New Rectangle(New Point(Size / 2, Size / 2), New Size(Size, Size)))
        _Graphics.DrawLine(Pen, Location, New Point(Location.X + Size / 2 - Location.X, Location.Y + Size / 2 - Location.Y))
        _Graphics.DrawLine(Pen, New Point(Location.X + Size, Location.Y), New Point(Size + Size / 2, Size / 2))
        _Graphics.DrawLine(Pen, New Point(Location.X, Location.Y + Size), New Point(Location.X + Size / 2 - Location.X, Location.Y + Size + Size / 2 - Location.Y))
        _Graphics.DrawLine(Pen, New Point(Location.X + Size, Location.Y + Size), New Point(Size + Size / 2, Size + Size / 2))
        Return _Bitmap
    End Function


Code:
  'Example
  PictureBox1.Image = DrawCube(Pens.Red, New Point(15, 15), 50)
However, it does have it's flaws. Which you'll eventually find after using the code.
thank you

looks like I left my



Code
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
PictureBox1.Image = DrawCube(Pens.Blue, New Point(TextBox1.Text, TextBox2.Text), TextBox3.Text)
End Sub
Quote Originally Posted by viniciuscbb View Post
thank you

looks like I left my



Code
Glad someone actually tried it ^^
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us