Making a snowflake

edited November 2015 in Programming Questions

Hi guys,

I've got a problem with making a snowflake. I have created a part of the snowflake and tried to rotate it with 60 degrees. But the anchor point is not right. In this program I wrote, the anchor point rotates in the upper left corner of the snowflakepart instead of the lower point.

And I thought maybe if I translate it to the upperright corner, that the anchor point might change. But that didn't work either.

This is btw my program:

PShape snow;

void setup() {

size(200, 200, P2D);

snow = createShape();

snow.beginShape();

snow.fill( 153, 255, 255 );

snow.stroke( 0, 190, 200 );

snow.vertex( 22, 50 ); //lower point

snow.vertex( 17, 42 ); //begin left side

snow.vertex( 17, 23 );

snow.vertex( 0, 16 );

snow.vertex( 0, 10 );

snow.vertex( 4, 7 );

snow.vertex( 17, 12 );

snow.vertex( 17, 2 ); //end left side

snow.vertex( 22, 0 ); //top point

snow.vertex( 27, 2 ); //begin right side

snow.vertex( 27, 12 );

snow.vertex( 40, 7 );

snow.vertex( 44, 10 );

snow.vertex( 44, 16 );

snow.vertex( 27, 23 );

snow.vertex( 27, 42 ); //end right side

snow.endShape(CLOSE); }

void draw() {

shape(snow, 100, 100);

//snow.rotate(radians(60));

}

Many thanks in advance!

Answers

  • CTRL+K is your bestfriend, as is the little C right here in the commenting box.

  • PShape snow;
    
    void setup() {
    
    size(200, 200, P2D);
    
    snow = createShape();
     }
    
    void draw() {
    
      snow.beginShape();
    
    snow.fill( 153, 255, 255 );
    
    snow.stroke( 0, 190, 200 );
    
    snow.vertex( 22, 50 ); //lower point
    
    snow.vertex( 17, 42 ); //begin left side
    
    snow.vertex( 17, 23 );
    
    snow.vertex( 0, 16 );
    
    snow.vertex( 0, 10 );
    
    snow.vertex( 4, 7 );
    
    snow.vertex( 17, 12 );
    
    snow.vertex( 17, 2 ); //end left side
    
    snow.vertex( 22, 0 ); //top point
    
    snow.vertex( 27, 2 ); //begin right side
    
    snow.vertex( 27, 12 );
    
    snow.vertex( 40, 7 );
    
    snow.vertex( 44, 10 );
    
    snow.vertex( 44, 16 );
    
    snow.vertex( 27, 23 );
    
    snow.vertex( 27, 42 ); //end right side
    
    snow.endShape(CLOSE);
    
    shape(snow, 100, 100);
    
    snow.rotate(radians(60));
    
    }
    

    So I am not quite sure if this is what you wanted, but what I did is I copied everything after snow = createShape(); and put it in void draw(){ } and then I took away the comment from the rotate part. Hope that helps.

  • edited November 2015

    Well no hahaha.

    What I'm trying to make is this:

    [20 pages of base64 encoded png deleted...]

    So I thought if I custom draw one part of this snowflake and let it continuously rotating around the center with 60 degrees (in this case the lower point). I can remake this snowflake.

    But it does not rotate correctly...

  • edited November 2015

    http://azcoloring.com/coloring-page/1056760 Wait this is a shorter link.

  • it's ctrl-o nowaday, not ctrl-k anymore

    test
    test B
    
  • Answer ✓
    PShape snow;
    int i; 
    
    void setup() {
    
      size(500, 400, P2D);
    
    
      snow = createShape();
    
      snow.beginShape();
    
      snow.translate(-22, -50);
    
      snow.fill( 153, 255, 255 );
    
      snow.stroke( 0, 190, 200 );
    
      //snow.noStroke(); 
    
    
      snow.vertex( 22, 50 ); //lower point
    
      snow.vertex( 17, 42 ); //begin left side
    
      snow.vertex( 17, 23 );
    
      snow.vertex( 0, 16 );
    
      snow.vertex( 0, 10 );
    
      snow.vertex( 4, 7 );
    
      snow.vertex( 17, 12 );
    
      snow.vertex( 17, 2 ); //end left side
    
      snow.vertex( 22, 0 ); //top point
    
      snow.vertex( 27, 2 ); //begin right side
    
      snow.vertex( 27, 12 );
    
      snow.vertex( 40, 7 );
    
      snow.vertex( 44, 10 );
    
      snow.vertex( 44, 16 );
    
      snow.vertex( 27, 23 );
    
      snow.vertex( 27, 42 ); //end right side
    
      snow.endShape(CLOSE);
    }
    
    void draw() {
    
      translate(width/2, height/2);
    
    
      shape(snow, 0, 0);
    
      stroke(255, 2, 2);
      point(0, 0);
    
      snow.rotate(radians(60));
    
      i++;
    
      if (i>6) { 
        noLoop();
      }
    }
    //
    
  • edited November 2015 Answer ✓

    the rotation takes place around the origin (0,0). Upper left corner.

    therefore you must place the one arm of the snowflakes so that its exact rotating point (the tip of the arm) lies exactly on the origin

    the idea is that you rotate around the origin, so the point of the initial arm that lies on the origin gets rotated on.

    So I moved the one arm so that the tip lies on the origin

    I did this in line 13

    then the rotating works

    PShape snow;
    int i; 
    
    void setup() {
    
      size(500, 400, P2D);
    
    
      snow = createShape();
    
      snow.beginShape();
    
      snow.translate(-22, -50);
    
      snow.fill( 153, 255, 255 );
    
      snow.stroke( 0, 190, 200 );
    
      //snow.noStroke(); 
    
    
      snow.vertex( 22, 50 ); //lower point
    
      snow.vertex( 17, 42 ); //begin left side
    
      snow.vertex( 17, 23 );
    
      snow.vertex( 0, 16 );
    
      snow.vertex( 0, 10 );
    
      snow.vertex( 4, 7 );
    
      snow.vertex( 17, 12 );
    
      snow.vertex( 17, 2 ); //end left side
    
      snow.vertex( 22, 0 ); //top point
    
      snow.vertex( 27, 2 ); //begin right side
    
      snow.vertex( 27, 12 );
    
      snow.vertex( 40, 7 );
    
      snow.vertex( 44, 10 );
    
      snow.vertex( 44, 16 );
    
      snow.vertex( 27, 23 );
    
      snow.vertex( 27, 42 ); //end right side
    
      snow.endShape(CLOSE);
    }
    
    void draw() {
    
      translate(width/2, height/2);
    
    
      shape(snow, 0, 0);
    
      stroke(255, 2, 2);
      point(0, 0);
    
      snow.rotate(radians(60));
    
      i++;
    
      if (i>6) { 
        noLoop();
      }
    }
    //
    
  • Oh yes, this is it! Thank you very much!

Sign In or Register to comment.