Skip to content

Instantly share code, notes, and snippets.

@aabele
Created October 18, 2023 12:40
Show Gist options
  • Save aabele/ca14cc6ea09be9caaa612311d31b76d5 to your computer and use it in GitHub Desktop.
Save aabele/ca14cc6ea09be9caaa612311d31b76d5 to your computer and use it in GitHub Desktop.
When you have input color and output color and you want to calculate the right `amount` value.
import subprocess
desired_output = '*{color:#2290f0}'
# Iterate through possible values of 'amount'
for amount in range(1, 100): # Adjust the range as needed
# Create the Sass code with the current 'amount'
sass_code = f'*{{color:darken(#3a9cf2, {amount})}}'
# Run the Sass command and capture the output
result = subprocess.run(
f'echo "{sass_code}" | sass --stdin --style=compressed',
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
# Check if the resulting CSS matches the desired output
if result.stdout.strip() == desired_output:
print(f"Found the correct 'amount' value: {amount}")
break
sudo npm install -g sass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment