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 › Is it smooth() that is making this help please.
Page Index Toggle Pages: 1
Is it smooth() that is making this? help please. (Read 350 times)
Is it smooth() that is making this? help please.
Nov 4th, 2008, 5:32am
 
Hello
I'm working in an array of squares that varies size according to it distance of the mouse.
It's part of a bigger stuff.
I got this weird circle of "bigger than should be" squares in an specific distance.
I don't know why this is happening.
Any help most welcome.
Thanks

I've made a clean version just with this part of the sketch, so it's easy to read.

The sketch is at:
www.kubrusly.com/vicente/erro/


and the code is also here:


Quote:
int d1=200,d2=150,incr=4;
int marginL=0,marginT=0;
float tamQ=0;
color c1;
color c2;
Vivo v[][] = new Vivo[d1][d2];


void setup() {
  size(800,600);
  smooth();
  imageMode(CENTER);
  rectMode(CENTER);
  background (255);
  noStroke();
  for(int i=0;i<d1; i++){
    for(int a=0;a<d2; a++){
      v[i][a]= new Vivo (incr*i,incr*a);
    }
  }
}



[color=#CC6600]void
draw(){
  c2=color(0);
  c1=color(255);
  fill(c1);
  rect(width/2,height/2,width,height);
  fill(c2);
  for(int i=0;i<d1; i++){                // <- draw the array
    for(int a=0;a<d2; a++){
      v[i][a].born_quad(); 
    }
  }
}




class Vivo{
  float var, centX,centY,x=-0.6;

  Vivo(float in_centX,float in_centY){
    centX=in_centX;
    centY=in_centY;

  }

  void born_quad(){
    this.var= dist(this.centX,this.centY,
mouseX
,mouseY)/100;                   // <- get distance from mouse
    rect(this.centX+marginL,this.centY+marginT,tamQ-this.var*x,tamQ-this.var*x);    // <- use it to set size
  }



}











Re: Is it smooth() that is making this? help pleas
Reply #1 - Nov 10th, 2008, 10:10pm
 
no help at all... is this a stupid question?
Re: Is it smooth() that is making this? help pleas
Reply #2 - Nov 10th, 2008, 11:40pm
 
I'm not sure I understand the problem, it looks as if the code you wrote works fine on a larger scale (See example below)

When it gets down to the sub pixel level and all those rects are very close together I think your guess is correct that the smoothing is messing with the surrounding pixels and causing the artifacts.


Code:

int d1=40,d2=30,incr=20;
int marginL=0,marginT=0;
float tamQ=0;
color c1;
color c2;
Vivo v[][] = new Vivo[d1][d2];


void setup() {
size(800,600);
smooth();
imageMode(CENTER);
rectMode(CENTER);
background (255);
noStroke();
for(int i=0;i<d1; i++){
for(int a=0;a<d2; a++){
v[i][a]= new Vivo (incr*i,incr*a);
}
}
}

void draw(){
c2=color(0);
c1=color(255);
fill(c1);
rect(width/2,height/2,width,height);
fill(c2);
for(int i=0;i<d1; i++){ // <- draw the array
for(int a=0;a<d2; a++){
v[i][a].born_quad();
}
}
}

class Vivo{
float var,centX,centY,x=-0.9f;

Vivo(float in_centX,float in_centY){
centX=in_centX;
centY=in_centY;
}

void born_quad(){
this.var = dist(this.centX,this.centY, mouseX, mouseY) / 30; // <- get distance from mouse
rect(this.centX+marginL,this.centY+marginT,tamQ-this.var*x,tamQ-this.var*x); // <- use it to set size
}
}
Re: Is it smooth() that is making this? help pleas
Reply #3 - Nov 10th, 2008, 11:44pm
 
Also, after re-reading, you might want to throw a constrain() in there and tweak the values to keep your scalar from getting to large:

Code:

void born_quad(){
this.var = dist(this.centX,this.centY, mouseX, mouseY) / 100; // <- get distance from mouse
this.var = constrain(this.var, 0.f,1.f);
rect(this.centX+marginL,this.centY+marginT,tamQ-this.var*x,tamQ-this.var*x); // <- use it to set size
}
Re: Is it smooth() that is making this? help pleas
Reply #4 - Nov 11th, 2008, 1:24am
 
Thanks for your time WD. Actually i want it to go until black.
What's this " 0.f, 1.f"? I mean, i understand constrain, but this "dot f" i've never seen. Do you just mean any value?
Anyway there's another question there is one pixel just under the pointer that also should not be there. Did you noticed?
Re: Is it smooth() that is making this? help pleas
Reply #5 - Nov 11th, 2008, 3:36am
 
Is this what you mean?

Code:

int d1=40,d2=30,incr=20;
int marginL=0,marginT=0;
float tamQ=20;
color c1;
color c2;
Vivo v[][] = new Vivo[d1][d2];


void setup() {
size(800,600);
smooth();
imageMode(CENTER);
rectMode(CENTER);
background (255);
noStroke();
for(int i=0;i<d1; i++){
for(int a=0;a<d2; a++){
v[i][a]= new Vivo (incr*i,incr*a);
}
}
}

void draw(){
c2=color(0);
c1=color(255);
fill(c1);
rect(width/2,height/2,width,height);
fill(c2);
for(int i=0;i<d1; i++){ // <- draw the array
for(int a=0;a<d2; a++){
v[i][a].born_quad();
}
}
}

class Vivo{
float var,centX,centY;

Vivo(float in_centX,float in_centY){
centX=in_centX;
centY=in_centY;
}

void born_quad(){
this.var = dist(this.centX,this.centY, mouseX, mouseY) / 100;
this.var = tamQ * constrain(this.var, 0.f,1.f);
rect(this.centX+marginL,this.centY+marginT,this.var,this.var); // <- use it to set size
}
}
Page Index Toggle Pages: 1