Why won't my code run? (hex grid)

I get a grey screen and then it times out. I commented the texture part out, but that didn't help.

PImage img;
PImage newimg;

int radius = 100;
float alpha = 0;
float r = 0.5;
float seed = -0.6;
float segments = 6;
float part = segments/2;
float x, y;
float angle_steps;
float angle_deg;

int col = 2;
int row = 2;

void setup() {
  size(800, 600, P2D);
  smooth(6);
  textureMode(NORMAL);
  //img = loadImage("ilrae.jpg");
}

void draw() {
  background(255);
  hexGrid();
}

void hexGrid(){
  for(int y=0; y<row+1; y++){
    for(int x=0; x<col+1; y++){
      int hexHeight = radius*2;
      int hexWidth = (int) sqrt(3)/2 * hexHeight;      

      int xPos = x * hexWidth;
      int yPos = y * hexHeight;
      hexShape(radius, xPos, yPos);
    }
  }
}

void hexShape(int _radius, int _xPos, int _yPos) {
  noFill();
  stroke(0); 
  //noStroke();   

  pushMatrix();
  beginShape(TRIANGLE_FAN);
  translate(_xPos, _yPos);
  rotate(-PI/2);
  //texture(img);
  vertex(0, 0, 0.5, 0.5); // center
  for (int i=0; i<segments+1; i++) {
    angle_steps = 360/segments;
    angle_deg = angle_steps * i;

    x = cos(radians(angle_deg)) * _radius;
    y = sin(radians(angle_deg)) * _radius;

    vertex(x,y);
    //if (i%2 == 0) {
    //  vertex(x, y, .5 + r * cos(alpha + PI / part), .5 + r * sin(alpha + PI / part));
    //} else {
    //  vertex(x, y, .5 + r * cos(alpha), .5 + r * sin(alpha));
    //}
  }
  endShape();
  popMatrix();

  alpha = 1.9*sin(seed);
  seed += 0.001;
}

//void mouseWheel(MouseEvent event) {
//  int e = event.getCount(); //returns UP:-1 DOWN:1
//  segments += (e*2)*-1;
//}

Answers

  • Answer ✓

    Hey

    Check the counters in your hexGrid(). You copy and paste the loop lines and you missed updating one of those counters.

    Also consider not using for loops inside draw. Maybe create the pattern and duplicate it across your screen, if that is what you are trying to do.

    I Hope this helps,

    Kf

  • edited July 2016

    Thanks for the reply @kfrajer

    But what do you mean by 'counters'?

    And where should you use for loops then?

  • Answer ✓

    line 31

  • x and x and x !!!!!!!

  • Oh shit, thanks for point that out.

Sign In or Register to comment.