We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Basic interaction, scale and alpha
Page Index Toggle Pages: 1
Basic interaction, scale and alpha (Read 653 times)
Basic interaction, scale and alpha
Mar 15th, 2007, 9:53am
 
Hi Guys,

today i started Processing, comming from Flashs Actionscript i am a little confused. I wanted to make a sketch where i create new circles pressing the mouse, which scale continuosly bigger and loose their opacity until they are vanished.
My problem is, that there is now MovieClips ;-) How can i - in a class - make a function which says that a ellipse will be created and another one which is responsible for the scale and opacity?

i am stuck here:

class Objectmade
 {
 
   int px;
   
   int py;
   
   float a = 0.0;
   
   float s = 0.0;
   
 Objectmade(){
 
   ellipseMode(CENTER);
   
 }
 
 void render(int px, int py, int pxs, int pys){
     
     noFill();
     
     stroke(125,30);
   
//    scale(2.0);
     
     ellipse(px, py, pxs, pys);
     
 }
 
 void objScale(){
 
//  scale the created ellipse and make opacity which is decreasing??
 
 }



Thanks a lot!!!
Re: Basic interaction, scale and alpha
Reply #1 - Mar 15th, 2007, 12:28pm
 
Just imagine you're using the Flash drawing commands but on one MovieClip. In fact, if you took this practice back into Flash you'd find everything runs a hell of a lot faster. MovieClips tend to run off and do their own thing like misbehaving children.

Most stuff you will have to do painstakingly manually here in Processing. Plus you cannot eval ["asInEval"] code, and everything is super-super-strict. A lot of useful tricks and tips are here:

http://processing.org/learning/index.html

For self managing lists of objects that remove themselves you're going to need to search the board for Vectors and ArrayLists and read those topics.

For now, here's what you wanted to do (but with shrinking circles instead of growing):

Code:

Fadey [] f;
int pointer = 0;
void setup(){
size(400,400);
background(0);
smooth();
noStroke();
f = new Fadey[255];
for(int i = 0; i < f.length; i++){
f[i] = new Fadey(0, 0, 0, 0);
}
}
void draw(){
background(0);
for(int i = 0; i < f.length; i++){
if(f[i].active){
f[i].draw();
}
}
if(mousePressed){
if(!f[pointer].active){
f[pointer] = new Fadey(mouseX, mouseY, 255, 50);
f[pointer].active = true;
pointer = (pointer + 1) % f.length;
}
}
}
class Fadey{
float x,y,a,s;
boolean active = false;
Fadey(float x, float y, float a, float s){
this.x = x;
this.y = y;
this.a = a;
this.s = s;
}
void draw(){
if(active){
fill(255, a);
ellipse(x, y, s, s);
a -= 1.2;
s -= 0.2;
if(a < 0.0 || s < 0.0){
this.active = false;
}
}
}
}


Play with it and try to break it, then see if you can get it to do what you want.
Re: Basic interaction, scale and alpha
Reply #2 - Mar 15th, 2007, 12:33pm
 
Thanks a lot st33d!
Page Index Toggle Pages: 1