We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello community, I am in need of your assistance; I've been working on a project for school, here's the code;
float x;
float y;
float[][] points;
float amplitude = 150.0;
int num_waves = 15;
int[][] grid;
float increment = 0.02;
void setup()
{
size(640,640);
}
void draw()
{
background(0);
float yoff=0.0;
loadPixels();
for(int y=0; y<height; y++)
{
float xoff = 0.0;
for (int x=0; x<width; x++)
{
int index = (x+y*width);
float r = noise(xoff,yoff)*100;
pixels[index]= color(r,0,r,140);
xoff+=.01;
}
yoff+=.01;
}
updatePixels();
noLoop();
println(randomGaussian()*pixels.length);
float b=0;
while (b < width)
{
point(b, height*noise(b));
b=b+1;
}
translate(0,height/2);
for(int j=0; j<num_waves; j++)
{
strokeWeight(1);
stroke(0,120,120);
translate(-2,4);
sineWave();
}
}
float[][] Points()
{
points = new float[width*3][2];
x = 0.0;
for(int j=0; j<points.length; j++)
{
y = amplitude*pow(sin(.015*x),5)*cos(.015*x);
for(int i=0; i<2; i++)
{
switch(i)
{
case 0:
points[j][i]=x;
break;
case 1:
points[j][i]=y;
break;
}
}
x+=PI/4;
}
return(points);
}
void sineWave()
{
float[][] points = Points();
beginShape();
vertex(0,0);
noFill();
for(int n=0; n<points.length; n++)
{
vertex(points[n][0],points[n][1]);
}
endShape();
}
Sorry that it's not the cleanest of code, I need to go back and clean it up later. But anyway, inside of the draw function, I've used the noise function to create a simple purple and black texture that fits the whole screen. What I would like to do is have the texture only take up a specified shape within the screen, such as in this image:
(For example in this image the noise is not really applied in any of the four corners of the image) I think I might be able to accomplish this by first drawing the shape that I want with bezier vertices, and then choose a fill color such as white, and then go through each of the pixels and testing to see if the color of the pixel is white, and then if so then apply the noise function to those pixels. I'm not sure if that would work though, and even if it does, it seems like it would be extremely tedious. Also an added bonus would be to be able to make the outer edges of the noise have a lower color saturation but that's not my primary concern.
Thanks for the help!
Answers
Why not draw the background first and then draw the shape over the top of it?
Oh, that would make sense, like drawing a black and transparent gradient over it?
That's right. You can use an overlay to black out the underlying image.
An alternative is to use masking with PGraphics.mask() -- this is like the procedure you were describing, but you don't have to implement it manually within the same buffer -- you instead create one source image and one mask image, then mask the source.
https://forum.processing.org/two/discussion/18819/how-to-copy-a-triangle-out-of-an-image