A Pen by Brian J. Cardiff on CodePen.
Last active
February 19, 2022 15:13
-
-
Save bcardiff/3b39ba8e2d00fed68435 to your computer and use it in GitHub Desktop.
hex with alpha in p5js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(',') + ')'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was very helpful, thank you!