Skip to content

Instantly share code, notes, and snippets.

@bcardiff
Last active February 19, 2022 15:13
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcardiff/3b39ba8e2d00fed68435 to your computer and use it in GitHub Desktop.
Save bcardiff/3b39ba8e2d00fed68435 to your computer and use it in GitHub Desktop.
hex with alpha in p5js
<html>
<head>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.17/p5.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
</body>
</html>
function setup() {
createCanvas(100, 100);
background(colorAlpha('#ff0000', 0.2));
}
function draw() {
fill(colorAlpha('#00ff00', 0.1));
rect(30,10,40,40);
fill(colorAlpha('#00ff00', 0.9));
rect(50,20,40,40);
}
function colorAlpha(aColor, alpha) {
var c = color(aColor);
return color('rgba(' + [red(c), green(c), blue(c), alpha].join(',') + ')');
}
@felipecustodio
Copy link

This was very helpful, thank you!

@julian-a-avar-c
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment