Jump to content

Alcohol mixing calculator


Morthawt
 Share

Recommended Posts

This is a script I made to enable me to be able to combine either something non-alcoholic with something alcoholic and know how much to add (easy on a calculator) but then also to be able to deal with two alcoholic drinks and know how much of the second one will be needed to get to a desired strength (much much harder to figure out). It runs through by adding the second alcoholic liquid in increments of 0.5 ml until it meets exactly or the first number that exceeds the desired strength. It simplifies the whole process since it just tries all the combinations rather that doing complicated math to equate one thing to another and try and work it that way. it is very easy to use.

Supply it with the original liquid, whether its wine or lemonade etc, then the strength of that liquid in % or 0 for non-alcoholic drink. Then set the percentage of the alcoholic liquid you will be using to add to the first liquid and what strength you would like your drink to be. Hit the button and you get your answer.

AutoItSetOption('TrayAutoPause', 0)
Global $OrigQty, $OrigStr, $AddStr, $DesiredStr, $Result
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Alcohol Calculator", 288, 188, -1, -1)
$OrigQty = GUICtrlCreateInput("150", 16, 16, 121, 21, $ES_CENTER)
$OrigStr = GUICtrlCreateInput("12.5", 152, 16, 121, 21, $ES_CENTER)
$AddStr = GUICtrlCreateInput("40", 16, 72, 121, 21, $ES_CENTER)
$Label1 = GUICtrlCreateLabel("Amount of original liquid", 16, 40, 115, 17)
$Label2 = GUICtrlCreateLabel("Strength of original liquid", 152, 40, 119, 17)
$Label3 = GUICtrlCreateLabel("Strength of alcohol to use", 16, 96, 128, 17)
$DesiredStr = GUICtrlCreateInput("20", 152, 72, 121, 21, $ES_CENTER)
$Label4 = GUICtrlCreateLabel("Desired alcohol strength", 152, 96, 118, 17)
$calculate = GUICtrlCreateButton("Calculate", 104, 120, 83, 25)
$Result = GUICtrlCreateInput("", 5, 152, 277, 21, $ES_CENTER)
GUICtrlSetFont(-1, 8, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $calculate
Strength(GUICtrlRead($OrigQty), GUICtrlRead($OrigStr), GUICtrlRead($AddStr), GUICtrlRead($DesiredStr))

EndSwitch
WEnd



; #FUNCTION# ====================================================================================================================
; Name ..........: Desired alcoholic strength calculator
; Description ...: This example code lets you calculate how much of an alcoholic drink to add to something else to make the resulting drink a certain strength.
; Syntax ........: Strength($MillilitersOfOriginalDrink, $StrengthOfOriginalDrink, $StrengthOfAddedLiquid, $DesiredStrength)
; Parameters ....: $MillilitersOfOriginalDrink- How much of a certain drink you start out with (either alcoholic or otherwise).
; $StrengthOfOriginalDrink- If the original drink is alcoholic then put the percentage here else put 0.
; $StrengthOfAddedLiquid- What strength of alcohol do you have to work with?.
; $DesiredStrength - How strong do you want your resulting drink to be?.
; Return values .: Text string with the needed information.
; Author ........: Wesley G aka Morthawt
; ===============================================================================================================================
Func Strength($MillilitersOfOriginalDrink, $StrengthOfOriginalDrink, $StrengthOfAddedLiquid, $DesiredStrength)
If $DesiredStrength > $StrengthOfAddedLiquid And $StrengthOfOriginalDrink > 0 Then
MsgBox(0, 'Error', 'Your desired strength exceeds the strength of the liquid used to provide extra alcohol content.')
Exit
ElseIf $DesiredStrength <= $StrengthOfOriginalDrink And $StrengthOfOriginalDrink <> 0 Then
MsgBox(0, 'Error', 'Your desired strength is lower than is even possible with the chosen liquids.' & @CRLF & @CRLF & 'Pick a higher desired strength.')
Exit
EndIf

Local $Amount = 0, $AlcoholContent = 0
$ConstAlc = $MillilitersOfOriginalDrink * ($StrengthOfOriginalDrink / 100)
$StrengthOfAddedLiquid = $StrengthOfAddedLiquid / 100
Do
$Amount += 0.5 ; This is the increment of milliliters we will go up each time to try and reach the desired amount of strength.
$AlcoholContent = Round(((($ConstAlc + ($Amount * $StrengthOfAddedLiquid)) / ($MillilitersOfOriginalDrink + $Amount)) * 100), 2)

Until $AlcoholContent >= $DesiredStrength
GUICtrlSetData($Result, 'Add ' & $Amount & 'ml of alcoholic liquid to get to ' & $AlcoholContent & '%')
Return 1
EndFunc ;==>Strength
Link to comment
Share on other sites

I was in the process of designing an automatic (ie arduino) mixing machine. Then I realized I probably would never sell it and become a raging alcoholic...

What better way to become a raging alcoholic than knowing exactly how messed up you are going to get off your next drink lmao :D

Nice. Now we just need to make it interface with a robotic arm to mix drinks for us! :sorcerer:

If only...

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...