Transparency Algorithm Calculator

By foshizzle on May 17, 2008

This is a simple app I made in vb.net that finds the RGB of a color based on its alpha value and the background color
example:
R1=255 G1=255 B1=128
R2=0 G2=0 B2=0
Alpha=50
returns: 128,128,64

note: its a little buggy because I'm not good in vb.net

'Form 1 Code
Public Class Form1

    Private Sub solve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles solve.Click
        Dim rcol As Integer
        Dim gcol As Integer
        Dim bcol As Integer
        Dim Al As Integer
        Al = (100 / Val(a.Text))
        rcol = ((Val(r1.Text) / Al) + (Val(r2.Text) / Al))
        gcol = ((Val(g1.Text) / Al) + (Val(g2.Text) / Al))
        bcol = ((Val(b1.Text) / Al) + (Val(b2.Text) / Al))
        output.Text = rcol & "," & gcol & "," & bcol
    End Sub
End Class
'dialog code
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.r1 = New System.Windows.Forms.TextBox
        Me.g1 = New System.Windows.Forms.TextBox
        Me.b1 = New System.Windows.Forms.TextBox
        Me.fore = New System.Windows.Forms.GroupBox
        Me.GroupBox2 = New System.Windows.Forms.GroupBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.Label6 = New System.Windows.Forms.Label
        Me.r2 = New System.Windows.Forms.TextBox
        Me.g2 = New System.Windows.Forms.TextBox
        Me.b2 = New System.Windows.Forms.TextBox
        Me.txt = New System.Windows.Forms.Label
        Me.a = New System.Windows.Forms.TextBox
        Me.output = New System.Windows.Forms.TextBox
        Me.solve = New System.Windows.Forms.Button
        Me.fore.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(6, 25)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(15, 13)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "R"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(7, 51)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(15, 13)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "G"
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(7, 77)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(14, 13)
        Me.Label3.TabIndex = 2
        Me.Label3.Text = "B"
        '
        'r1
        '
        Me.r1.Location = New System.Drawing.Point(30, 22)
        Me.r1.Name = "r1"
        Me.r1.Size = New System.Drawing.Size(62, 20)
        Me.r1.TabIndex = 3
        '
        'g1
        '
        Me.g1.Location = New System.Drawing.Point(30, 48)
        Me.g1.Name = "g1"
        Me.g1.Size = New System.Drawing.Size(62, 20)
        Me.g1.TabIndex = 4
        '
        'b1
        '
        Me.b1.Location = New System.Drawing.Point(30, 74)
        Me.b1.Name = "b1"
        Me.b1.Size = New System.Drawing.Size(62, 20)
        Me.b1.TabIndex = 5
        '
        'fore
        '
        Me.fore.Controls.Add(Me.Label1)
        Me.fore.Controls.Add(Me.Label2)
        Me.fore.Controls.Add(Me.Label3)
        Me.fore.Controls.Add(Me.r1)
        Me.fore.Controls.Add(Me.g1)
        Me.fore.Controls.Add(Me.b1)
        Me.fore.Location = New System.Drawing.Point(12, 12)
        Me.fore.Name = "fore"
        Me.fore.Size = New System.Drawing.Size(112, 108)
        Me.fore.TabIndex = 12
        Me.fore.TabStop = False
        Me.fore.Text = "Foreground Colors"
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.Add(Me.Label4)
        Me.GroupBox2.Controls.Add(Me.Label5)
        Me.GroupBox2.Controls.Add(Me.Label6)
        Me.GroupBox2.Controls.Add(Me.r2)
        Me.GroupBox2.Controls.Add(Me.g2)
        Me.GroupBox2.Controls.Add(Me.b2)
        Me.GroupBox2.Location = New System.Drawing.Point(139, 12)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(112, 108)
        Me.GroupBox2.TabIndex = 13
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "Background Colors"
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(6, 25)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(15, 13)
        Me.Label4.TabIndex = 0
        Me.Label4.Text = "R"
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.Location = New System.Drawing.Point(7, 51)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(15, 13)
        Me.Label5.TabIndex = 1
        Me.Label5.Text = "G"
        '
        'Label6
        '
        Me.Label6.AutoSize = True
        Me.Label6.Location = New System.Drawing.Point(7, 77)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(14, 13)
        Me.Label6.TabIndex = 2
        Me.Label6.Text = "B"
        '
        'r2
        '
        Me.r2.Location = New System.Drawing.Point(30, 22)
        Me.r2.Name = "r2"
        Me.r2.Size = New System.Drawing.Size(62, 20)
        Me.r2.TabIndex = 3
        '
        'g2
        '
        Me.g2.Location = New System.Drawing.Point(30, 48)
        Me.g2.Name = "g2"
        Me.g2.Size = New System.Drawing.Size(62, 20)
        Me.g2.TabIndex = 4
        '
        'b2
        '
        Me.b2.Location = New System.Drawing.Point(30, 74)
        Me.b2.Name = "b2"
        Me.b2.Size = New System.Drawing.Size(62, 20)
        Me.b2.TabIndex = 5
        '
        'txt
        '
        Me.txt.AutoSize = True
        Me.txt.Location = New System.Drawing.Point(19, 128)
        Me.txt.Name = "txt"
        Me.txt.Size = New System.Drawing.Size(70, 13)
        Me.txt.TabIndex = 14
        Me.txt.Text = "Alpha (0-100)"
        '
        'a
        '
        Me.a.Location = New System.Drawing.Point(95, 125)
        Me.a.Name = "a"
        Me.a.Size = New System.Drawing.Size(82, 20)
        Me.a.TabIndex = 15
        '
        'output
        '
        Me.output.Location = New System.Drawing.Point(12, 149)
        Me.output.Name = "output"
        Me.output.ReadOnly = True
        Me.output.Size = New System.Drawing.Size(240, 20)
        Me.output.TabIndex = 16
        '
        'solve
        '
        Me.solve.Location = New System.Drawing.Point(183, 123)
        Me.solve.Name = "solve"
        Me.solve.Size = New System.Drawing.Size(68, 23)
        Me.solve.TabIndex = 17
        Me.solve.Text = "Calculate"
        Me.solve.UseVisualStyleBackColor = True
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(264, 181)
        Me.Controls.Add(Me.solve)
        Me.Controls.Add(Me.output)
        Me.Controls.Add(Me.a)
        Me.Controls.Add(Me.txt)
        Me.Controls.Add(Me.GroupBox2)
        Me.Controls.Add(Me.fore)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Alpha Calculator"
        Me.fore.ResumeLayout(False)
        Me.fore.PerformLayout()
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox2.PerformLayout()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents r1 As System.Windows.Forms.TextBox
    Friend WithEvents g1 As System.Windows.Forms.TextBox
    Friend WithEvents b1 As System.Windows.Forms.TextBox
    Friend WithEvents fore As System.Windows.Forms.GroupBox
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents r2 As System.Windows.Forms.TextBox
    Friend WithEvents g2 As System.Windows.Forms.TextBox
    Friend WithEvents b2 As System.Windows.Forms.TextBox
    Friend WithEvents txt As System.Windows.Forms.Label
    Friend WithEvents a As System.Windows.Forms.TextBox
    Friend WithEvents output As System.Windows.Forms.TextBox
    Friend WithEvents solve As System.Windows.Forms.Button

End Class
'icon: http://www.mediafire.com/?dxk9bxbim1d

Comments

Sign in to comment.
T012m3n7oR   -  Jun 06, 2008

Rofl

 Respond  
Jonesy44   -  May 17, 2008

It\'s like telling VB to politely do what you want.. lulz

Kindly while loop x while the a variable is equal to one, thank you. And if you wouldn\'t mind an if statement in there?
 Respond  
foshizzle   -  May 17, 2008

Sorry, but the algorithm is correct but VB is rounding weirdly, i sux at vb.net :(

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.