Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Drawing.Imaging.ImageFormat
Public Class Form1
Public font1 As New FontDialog
Public b As Bitmap
Public g As Graphics
Dim ListaParoleInutili As New Dictionary(Of String, Boolean)
Dim carattere As Font
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListBox1.Items.Clear()
Dim fonts As New InstalledFontCollection
For Each one As FontFamily In fonts.Families
ListBox1.Items.Add(one.Name)
Next
ListaParoleInutili.Add("di", Nothing)
ListaParoleInutili.Add("a", Nothing)
ListaParoleInutili.Add("da", Nothing)
ListaParoleInutili.Add("in", Nothing)
ListaParoleInutili.Add("con", Nothing)
ListaParoleInutili.Add("su", Nothing)
ListaParoleInutili.Add("per", Nothing)
ListaParoleInutili.Add("tra", Nothing)
ListaParoleInutili.Add("fra", Nothing)
ListaParoleInutili.Add("il", Nothing)
ListaParoleInutili.Add("la", Nothing)
ListaParoleInutili.Add("lo", Nothing)
ListaParoleInutili.Add("un", Nothing)
ListaParoleInutili.Add("una", Nothing)
ListaParoleInutili.Add("uno", Nothing)
ListaParoleInutili.Add("del", Nothing)
ListaParoleInutili.Add("dello", Nothing)
ListaParoleInutili.Add("degli", Nothing)
ListaParoleInutili.Add("dei", Nothing)
ListaParoleInutili.Add("i", Nothing)
ListaParoleInutili.Add("le", Nothing)
ListaParoleInutili.Add("alle", Nothing)
ListaParoleInutili.Add("agli", Nothing)
ListaParoleInutili.Add("dai", Nothing)
ListaParoleInutili.Add("fa", Nothing)
ListaParoleInutili.Add("ci", Nothing)
ListaParoleInutili.Add("si", Nothing)
ListaParoleInutili.Add("e", Nothing)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim inutile As String
inutile = Microsoft.VisualBasic.Interaction.InputBox("Inserisci la parola che vuoi ignorare! (premere di nuovo il pulsante -Crea Word Tag-)", "Parole Da Ignorare", "")
If ListaParoleInutili.ContainsKey(inutile.ToLower) Then
Else
ListaParoleInutili.Add(inutile.ToLower, Nothing)
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim Corpus As String = Me.RichTextBox1.Text
Dim corpus_N As String = Corpus.ToLower.Replace(",", " ").Replace(vbCrLf, " ").Replace(" ", " ").Replace(".", " ").Replace("!", " ").Replace("?", " ").Replace(")", " ").Replace("(", " ").Replace("-", " ").Replace("'", " ")
Dim Parole() As String = corpus_N.Split((vbCrLf & " ").ToCharArray, StringSplitOptions.RemoveEmptyEntries)
Dim minimadimensionefont As Integer = 10
Dim massimadimensionefont As Integer = 50
Dim ListaParoleDiverse As New SortedList(Of String, Boolean)
For Each parola As String In Parole
If Not ListaParoleInutili.ContainsKey(parola) Then
If Not ListaParoleDiverse.ContainsKey(parola) Then ListaParoleDiverse.Add(parola, Nothing)
End If
Next
b = New Bitmap(Me.PictureBox1.Width, Me.PictureBox1.Height)
g = Graphics.FromImage(b)
g.SmoothingMode = SmoothingMode.HighQuality
g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
'RANDOM
Dim RND As New Random
Dim NumeroCasuale0_1 As Double = RND.NextDouble
Dim Raggio As Double = b.Height / 3
Dim colorNames As String() = System.Enum.GetNames(GetType(KnownColor))
Dim lstColors As New List(Of String)(colorNames)
Dim PathRettangoli As New GraphicsPath
Do While ListaParoleDiverse.Count > 0
Dim Parola As String = ListaParoleDiverse.Keys.Item(0)
Dim frequenza As Integer = 1
For Each parolina As String In Parole
If parolina = Parola Then
frequenza += 1
End If
Next
Dim dimensione As Single = 4 * frequenza
Dim ANgoloCasuale As Double = RND.NextDouble * 2 * Math.PI
Dim DIstanzaCasuale As Double = RND.NextDouble * Raggio
Dim x As Double = b.Width / 2 + Math.Cos(ANgoloCasuale) * DIstanzaCasuale
Dim y As Double = b.Height / 2 + Math.Sin(ANgoloCasuale) * DIstanzaCasuale
Dim IndiceCasuale As Integer = RND.Next(0, lstColors.Count - 1)
Dim COloreCasuale As Color = System.Drawing.Color.FromName(lstColors(IndiceCasuale))
Dim MyFont As Font = New Font(ListBox1.Text, dimensione, FontStyle.Italic)
Dim SIzeFString As SizeF = g.MeasureString(Parola, MyFont)
Dim RettangoloStringa As New Rectangle(New Point(x, y), SIzeFString.ToSize)
Dim R As New Region(PathRettangoli)
If Not R.IsVisible(RettangoloStringa) Then
g.DrawString(Parola, MyFont, New SolidBrush(COloreCasuale), x, y)
ListaParoleDiverse.RemoveAt(0)
PathRettangoli.AddRectangle(RettangoloStringa)
End If
Me.PictureBox1.Image = b
Application.DoEvents()
Loop
Catch exc As Exception
MsgBox("Errore non previsto" & vbCrLf & exc.Message)
End Try
Me.PictureBox1.Image = b
End Sub
End Class
Nessun commento:
Posta un commento
Nota. Solo i membri di questo blog possono postare un commento.