CodingTrain / Suggestion-Box

A repo to track ideas for topics
572 stars 86 forks source link

[HELP] ellipses not drawing, things not working...why? #638

Open danielx-art opened 7 years ago

danielx-art commented 7 years ago

Okay, so I've been trying to generate branches of balls with this code. I've been trying different aproaches since 3 days ago and things do not work for some reason. Please If anyone could take a look I would be very grateful.

`ArrayList galhos = new ArrayList(); float raio_in; int max_iteracoes = 100; int it = 0;

void setup(){ size(600,600); background(170); raio_in = width/30; PVector primeira_pos_mae = new PVector(width/2,0); PVector primeiro_aponta = new PVector(0,raio_in*1,2); galhos.add(new bgalho(primeira_pos_mae, primeiro_aponta, raio_in, 1)); //EN: generates the first one;

//EN: Debugging to see if its working noStroke(); fill(255); ellipse(galhos.get(0).pos.x, galhos.get(0).pos.y, 2raio_in, 2raio_in); println(galhos.get(0).pos); }

void draw(){

//EN: shows every object
for(int j=0; j<galhos.size();j++){ galhos.get(j).mostra();
}

//EN: proliferate the ones that are not "mothers" still. for(int k=0; k<galhos.size(); k++){ if(galhos.get(k).mae == false && it<max_iteracoes){ galhos.get(k).prolifera(); } }

}`

and the object:

`class bgalho{

PVector pos = new PVector(); //EN: position PVector aponta = new PVector(); //EN: points somewhere int geracao; float raio; boolean mae = false;

bgalho(PVector mae_pos, PVector mae_apo, float rad, int ger){

pos = mae_pos.add(mae_apo);   //EN: position of children equals position of mother plus where the mother points
aponta = mae_apo.copy();
aponta.normalize();
aponta.mult(3*rad+3);
aponta.rotate(random(-PI/6, PI/6));        //EN: now it points to a new direction based on where the mother points
geracao = ger;
raio = rad;

//primeiro bgalho deve ter mae_pos = (width/2, 0) e mae_apo proporcional a (0,1);
//EN: the first object bgalho should receive mae_pos = (width/2, 0) and mae_apo proportional to (0,1);

}

//prolifera/cresce o galho //EN: proliferate/grow the branch void prolifera(){ float novo_raio = raio*0.9; int nova_ger = geracao+1; galhos.add(new bgalho(pos, aponta, novo_raio, nova_ger)); stroke(1); line(pos.x, pos.y, pos.x +aponta.x, pos.y +aponta.y);

//chance de gerar um segundo galho rodado de ~PI/2
//EN: chance to generate a second branch rotated from ~PI/2
float sorte = random(0,100);
if( sorte > 98){
  PVector aponta2 = new PVector();
  aponta2 = aponta.copy();
  aponta2.rotate(random(PI/2-PI/6, PI/2+PI/6));
  galhos.add(new bgalho(pos, aponta2, novo_raio, nova_ger));

  //EN: debugging to see if it is actually working:
  println("lucky!");
  stroke(255);                                                       
  line(pos.x, pos.y, pos.x +aponta.x, pos.y +aponta.y);
}

//depois de proliferar/crescer é mãe
//EN: after it proliferates/grows it becomes a "mother" and no longer does this.
mae = true;
it++;

}

void mostra(){ //EN: show function noStroke(); fill(0, 255-geracao); ellipse(pos.x, pos.y, 2raio, 2raio); }

}`

aimorris commented 6 years ago

I suggest adding the question or help wanted label to this issue. If you want I could start adding labels to the issues corresponding to what the issue is about. Don't have the ability to do that right now so you would have to do something magical and give me the ability to.

@shiffman

mike239x commented 6 years ago

@metacarpo10 Well, I think you got it by now, but here you go: in line 17 you write 2raio_in, twice. This should be 2 raio_in. Near the end you write 2raio (also twice), should be changed to 2 raio. After making this changes it will indeed draw something.