image(bg, width/2, height/2); // this is the background image I called
tint(255, 40); // I want to fix the alpha of background image at 40
for(int k=0; k<13; k++)
{
if(time[k] < maxAlpha)
{
image(pat[k], width/2, height/2);
tint(255, maxAlpha-time[k]); //I want to give this tint() to only object images, not to background image
time[k] = time[k] + going;
}
}
}
void keyPressed()
{
if ( key == 'z' )
{
time[0] = 0;
}
if ( key == 'x' )
{
time[1] = 0;
}
if ( key == 'c' )
{
time[2] = 0;
}
if ( key == 'v' )
{
time[3] = 0;
}
if ( key == 'b' )
{
time[4] = 0;
}
if ( key == 'a' )
{
time[5] = 0;
}
if ( key == 's' )
{
time[6] = 0;
}
if ( key == 'd' )
{
time[7] = 0;
}
if ( key == 'f' )
{
time[8] = 0;
}
if ( key == 'g' )
{
time[9] = 0;
}
if ( key == 'q' )
{
time[10] = 0;
}
if ( key == 'w' )
{
time[11] = 0;
}
if ( key == 'e' )
{
time[12] = 0;
}
}
}
I thought that tint() would only have effect on object images(in this case, pat[] I mean)....But it also affect bg.
The alpha value of bg should be fixed at 40.
Would someone help me, please? I don't have any idea...
(I cannot use background(bg) because bg is smaller than application size and I don't want to change the size of image 'bg'. 'bg' is PNG image with transparent background and I just want to put it on the background(0,0,75), at the center of the screen.)
Hi, i'm testing something about circles fading out which are triggered by keyPressed().
I have made two sketches; one with an image fading out as time goes, the other with a short sound triggered by keyPressed().
i want to combine these two sketches, but the new sketch does not work well.
Can anybody help me?
Here's two codes;
'an image fading out as time goes'
PImage test13;
float time = 0;
float going = 1;
void setup()
{
size(500,500);
test13 = loadImage("pattern13.png");
}
void draw()
{
background(0);
time=time+going;
tint(255, 200-time);
imageMode(CENTER);
image(test13, width/2, height/2);
}
'a short sound triggered by keyPressed()'
/////////////setting for sound///////////////
import ddf.minim.*;
Minim minim;
//set names of intagers(which becomes random index for same sound values)
int indexHigh3;
//set names of sounds ([value] indicates the numbers of same sound)
AudioSample high3;
void setup()
{
size(1024, 768);
minim = new Minim(this);
// load a file, give the AudioPlayer buffers that are 512 samples long
high3 = minim.loadSample("3-3_1.wav", 512);
}
void draw()
{
background(0,0,75);
}
void keyPressed()
{
imageMode(CENTER);
if ( key == 'e' )
{
high3.trigger();
}
void stop()
{
// always close Minim audio classes when you are done with them
high3.close();
// always stop Minim before exiting
minim.stop();
super.stop();
}
The sound is 3-4sec long and it does not stop after releasing key 'e'.
However, when I adapt keyPressed to the first sketch, image disappears after 1 frame.(it blinks only once)
PImage test13;
float time = 0;
float going = 1;
void setup()
{
size(500,500);
test13 = loadImage("pattern13.png");
}
void draw()
{
background(0);
}
void keyPressed()
{
if (key == 'e')
{
time=time+going;
tint(255, 200-time);
imageMode(CENTER);
image(test13, width/2, height/2);
}
}
I think that the second sketch works because of trigger() from minim.
The document for minim says;
Triggers the sound to play once. Can be called again before the sound finishes playing.
Can I make my image stay and fade out even though key is released? (just like that a sound does not stop after releasing key)
I want similar effect of my second sketch, but on image not on sound.
I want to 'trigger' my image to appear and fade out by pressing key.
I think it might be possible if i create void display() or something...like class...? But I'm not sure and don't know how to make it.. I've tried it but stuck in the middle. My brain is messed up. Or should I use array? I don't know where to start....T_T
I want to repeat some actions in void draw(), but I cannot figure out how to do it.
In my code, several balls connected by lines are created at the start of application and fall down to the ground(limit line for falling). And by mouse clicking, new balls are created and fall down again.
I want to make falling balls be accumulated on the ground, but every time I click the mouse, balls on the ground disappear and their is only new balls on my screen.
I want to repeat actions over and over.. There should be an overlay of balls which have fallen on the ground.
All I know is that I should not use setup(); in void mousePressed() because setup() erase everything and make my sketch restart. However, I don't know how to make new balls.... setup() is the only method to create new balls which I found by searching in this forum.
Here's my code;
Circle[] circles;
int numCircles = 13; //number of circles
int maxDistance; //max distance between circles when draw lines
int minDistance;
int m;
float bgX;
float bgY;
PImage bg;
void setup() {
size(displayWidth, displayHeight); //size of window
smooth(); //draw circles with anti-aliased edge
m = millis();
bgX = (displayWidth-800)/2;
bgY = (displayHeight-800)/2;
bg = loadImage("bg_trans.png");
// create an array and fill it with circles
circles = new Circle[numCircles]; //create an array of circles
for (int i=0; i< numCircles; i++) {
//random position in the window, random size between 5-15
at line 50, error 'the operator < is undefined for the argument type(s) boolean, int' occurs.
When I wrote 'if(dist(circles[i].x, circles[i].y, circles[j].x, circles[j].y) < maxDistance){' at that line, the sketch worked.
In case of ' if((dist(circles[i].x, circles[i].y, circles[j].x, circles[j].y) > minDistance) & (dist(circles[i].x, circles[i].y, circles[j].x, circles[j].y) < maxDistance) < maxDistance){', it still does not work.
It might be really easy question for all of you, but is terribly hard to me as a little beginner for processing.
I want to make a visual which looks like the main image of processing.
Like this, I hope to connect several dots by some lines.
(x and y values of dots can be random or designated.)
However, I cannot find easy example for this one.
Though I spend much time looking at examples in processing itself and finding similar sketch at www.OpenProcessing.org, I could not find it...
Of course, there are some examples which have similar visual like the image above at OpenProcessing, but those are usually interactive and complex ones.... I cannot figure out where the codes for the visual are.
However, I cannot find the lines for creating visual in these sketches...)
I just want to look at THE EASIEST solution for the visual above. NO INTERACTION, NO COMPLEX CODES.
I guess that it would be something simple and easy....
But for me as a beginner with almost no knowledge for processing, it is really hard and perplexing...T_T
Can anybody help me? I beg your considerate advices....
Posting codes for the visual would be perfect, or giving URL of examples on OpenProcessing or other site(where I can download the file or read codes) would be great also.
PLEASE HELP ME!
Sorry for my poor English writing... English is not my mother language.^^;
Thank you for reading my question. Have a nice day!