Jump to content

[GDI+] - Árvore de Natal de 2009 [transferido para wiki]


ribeiro55
 Share

Recommended Posts

[glow=red,1,100]Ora então um feliz Natal para todos na comunidade![/glow]

'depois de abrir um projecto novo, no código do form:
Imports System.Drawing
Imports System.Drawing.Drawing2D

Public Class Form1

   Private Luzes As New List(Of Point)
   Private R As New Random
   Private FNT As New Font("Arial", 20, FontStyle.Bold)
   Private WithEvents Piscar As New Timer With {.Interval = 500, .Enabled = True}

   Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
       End
   End Sub

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Me.Size = New Size(250, 600)
       Me.Top = CInt((Screen.PrimaryScreen.Bounds.Height / 2) - (Me.Height / 2))
       Me.Left = CInt((Screen.PrimaryScreen.Bounds.Width / 2) - (Me.Width / 2))
       Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None

       Dim B As New Bitmap(ClientSize.Width, ClientSize.Height)
       Dim G As Graphics = Graphics.FromImage(B)

       Dim BGLGB As New LinearGradientBrush(New Point(CInt(B.Width / 2), 0), New Point(CInt(B.Width / 2), 600), Color.DarkBlue, Color.Blue)

       Dim LGB1 As New LinearGradientBrush(New Point(125, 20), New Point(125, 470), Color.White, Color.DarkGreen)
       Dim LGB2 As New LinearGradientBrush(New Point(125, 20), New Point(125, 353), Color.White, Color.DarkGreen)
       Dim LGB3 As New LinearGradientBrush(New Point(125, 0), New Point(125, 236), Color.White, Color.DarkGreen)
       Dim LGB4 As New LinearGradientBrush(New Point(125, 0), New Point(125, 120), Color.White, Color.DarkGreen)

       Dim T1() As PointF = {New PointF(125, 20), New Point(10, 470), New PointF(230, 470)}
       Dim T2() As PointF = {New PointF(125, 20), New Point(20, 353), New PointF(220, 353)}
       Dim T3() As PointF = {New PointF(125, 20), New Point(30, 236), New PointF(210, 236)}
       Dim T4() As PointF = {New PointF(125, 20), New Point(40, 120), New PointF(200, 120)}

       G.FillRectangle(BGLGB, 0, 0, B.Width, B.Height)

       Dim R As New Random

       For P = 1 To 500
           G.FillEllipse(Brushes.White, R.Next(0, B.Width), R.Next(0, B.Height), 2, 2)
       Next

       Dim Estrela() As PointF = {New PointF(0 + 115, 10), New PointF(5 + 115, 10), _
                                  New PointF(10 + 115, 0), New PointF(15 + 115, 10), _
                                  New PointF(20 + 115, 10), New PointF(15 + 115, 15), _
                                  New PointF(20 + 115, 25), New PointF(10 + 115, 18), _
                                  New PointF(0 + 115, 25), New PointF(5 + 115, 15), _
                                  New PointF(0 + 115, 10), New PointF(0 + 115, 0)}

       G.FillPolygon(LGB1, T1) : G.DrawPolygon(New Pen(Color.Black, 2), T1)
       G.FillPolygon(LGB2, T2) : G.DrawPolygon(New Pen(Color.Black, 2), T2)
       G.FillPolygon(LGB3, T3) : G.DrawPolygon(New Pen(Color.Black, 2), T3)
       G.FillPolygon(LGB4, T4) : G.DrawPolygon(New Pen(Color.Black, 2), T4)

       G.FillPolygon(Brushes.Yellow, Estrela)

       G.FillRectangle(Brushes.Brown, 100, 470, 50, (600 - 470))

       G.DrawRectangle(New Pen(Color.Black, 2), 100, 470, 50, (600 - 470))

       Luzes.Add(New Point(72, 105)) : Luzes.Add(New Point(100, 70)) :
       Luzes.Add(New Point(136, 101)) : Luzes.Add(New Point(176, 105))
       Luzes.Add(New Point(127, 52)) : Luzes.Add(New Point(90, 134))
       Luzes.Add(New Point(149, 139)) : Luzes.Add(New Point(121, 160))
       Luzes.Add(New Point(69, 206)) : Luzes.Add(New Point(133, 215))
       Luzes.Add(New Point(106, 186)) : Luzes.Add(New Point(167, 180))
       Luzes.Add(New Point(152, 217)) : Luzes.Add(New Point(68, 251))
       Luzes.Add(New Point(128, 298)) : Luzes.Add(New Point(165, 253))
       Luzes.Add(New Point(109, 256)) : Luzes.Add(New Point(52, 333))
       Luzes.Add(New Point(75, 296)) : Luzes.Add(New Point(127, 328))
       Luzes.Add(New Point(187, 328)) : Luzes.Add(New Point(170, 286))
       Luzes.Add(New Point(63, 369)) : Luzes.Add(New Point(169, 394))
       Luzes.Add(New Point(94, 418)) : Luzes.Add(New Point(120, 368))
       Luzes.Add(New Point(36, 441)) : Luzes.Add(New Point(113, 453))
       Luzes.Add(New Point(201, 429)) : Luzes.Add(New Point(142, 447))
       Luzes.Add(New Point(186, 386))

       Me.BackgroundImage = B
   End Sub

   Private Sub Piscar_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Piscar.Tick
       Dim G As Graphics = Me.CreateGraphics
       For Each P As Point In Luzes
           Dim TB As New SolidBrush(DarCor())
           G.FillEllipse(TB, P.X, P.Y, 10, 10)
       Next

       Dim TempMsg As String = "FELIZ NATAL"
       Dim TempTam As SizeF = G.MeasureString(TempMsg, FNT)
       G.DrawString(TempMsg, FNT, New SolidBrush(DarCor), 125 - (TempTam.Width / 2), 500)
       G.DrawString(TempMsg, FNT, New SolidBrush(DarCor), 125 - (TempTam.Width / 2) + 2, 500 + 2)
       G.DrawString(TempMsg, FNT, New SolidBrush(DarCor), 125 - (TempTam.Width / 2) + 4, 500 + 4)
   End Sub

   Private Function DarCor() As Color
       Dim Cor1 As Color = Color.LightGreen
       Dim Cor2 As Color = Color.Blue
       Dim Cor3 As Color = Color.Red
       Dim Cor4 As Color = Color.Yellow

       Select Case CInt(R.Next(1, 4))
           Case 1 : Return Cor1
           Case 2 : Return Cor2
           Case 3 : Return Cor3
           Case 4 : Return Cor4
       End Select

   End Function

End Class

Sérgio Ribeiro


"Great coders aren't born. They're compiled and released"
"Expert coders do not need a keyboard. They just throw magnets at the RAM chips"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.