Skip to content

Background Alpha #1906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Crashnorun opened this issue Apr 20, 2017 · 6 comments
Closed

Background Alpha #1906

Crashnorun opened this issue Apr 20, 2017 · 6 comments

Comments

@Crashnorun
Copy link

Hi, I'm new to P5 but familiar with Processing, and this issue seems to be existent in both environments. When I use the background() command and apply an alpha, the value doesn't really do anything. According to this link: https://p5js.org/reference/#/p5/background the alpha value is meant to be between 0-100 and apply a level of transparency, but it doesn't seem to work. Regardless what value I put for alpha, I can never get transparency. My workaround for this was to just draw a rectangle in the back and give it a fill color with an alpha value. This issue isn't a priority but would be nice to have it functioning.

All in all great job, P5 & processing are amazing!!

@Crashnorun
Copy link
Author

Please disregard my issue, I was able to get it to function as stated in the reference documentation.
My apologies.

@arphenlin
Copy link

arphenlin commented Aug 11, 2019

I have the same problem about alpha of background(). Below is my code, I don't know what's wrong with it.
Can you give an example? Thanks!

var bg;
function setup() {
  bg = loadImage('assets/bg.png');
  createCanvas(1000, 1000);
}

function draw() {
  background(bg, 100);  // the [alpha] argument doesn't work here!
}

@Crashnorun Crashnorun reopened this Aug 12, 2019
@limzykenneth
Copy link
Member

Hi @arphen, are you trying to draw an image as the background? If so you should use image() to draw the loaded image directly onto the canvas instead of using background, as that accepts only color values.

@arphenlin
Copy link

Hi @arphen, are you trying to draw an image as the background? If so you should use image() to draw the loaded image directly onto the canvas instead of using background, as that accepts only color values.

I can use image() to draw an image as the background. However, it doesn't support transparency effect.

@limzykenneth
Copy link
Member

@arphen You can either directly load in a png image with transparency already baked in or you can go through the pixels[] array of the image and set the individual pixels to have the alpha value you wanted. If you still want an easier way to do this, do open a new issue.

@paulcanning
Copy link

paulcanning commented Apr 12, 2021

@limzykenneth from the documentation https://p5js.org/reference/#/p5/background

A p5.Image can also be provided to set the background image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants