<commit_before>class SnowflakePen {
  constructor(x, y){
    this.x = x;
    this.y = y;
    this.slope = Math.tan(2 * Math.PI / 12);
    this.prevPos = createVector(0, 0);
    this.penWasDown = false;
  }

  isPointInFirstSegment(x, y){
    // assumes Snowflakw has a segment pointing directly upward
    return x > this.x 
        && y < this.y
        && (x - this.x) < (this.y - y) * this.slope;
  }

  draw(){
    if (mouseIsPressed && this.isPointInFirstSegment(mouseX, mouseY)){
      if (this.penWasDown){
        line(this.prevPos.x, this.prevPos.y, mouseX, mouseY);
      }
      this.penWasDown = true;
      this.prevPos.x = mouseX;
      this.prevPos.y = mouseY;
    }else{
      this.penWasDown = false;
    }
  }
}<commit_msg>p5js/snowflake-pen - Allow for drawing half-of-first slice<commit_after>class SnowflakePen {
  constructor(x, y){
    this.x = x;
    this.y = y;
    this.prevPos = createVector(0, 0);
    this.penWasDown = false;
    this.numSlices = 6;
    this.rotationPerSlice = 2 * Math.PI / this.numSlices;
    this.halfRotation = this.rotationPerSlice / 2;
    this.slope = Math.tan(this.halfRotation);
  }

  isPointInFirstSegment(x, y){
    // assumes Snowflakw has a segment pointing directly upward
    return x > this.x 
        && y < this.y
        && (x - this.x) < (this.y - y) * this.slope;
  }

  drawRepeatedly(newX, newY){
    let penLocation = createVector(this.x - newX, this.y - newY);

    for(var i = 0; i < this.numSlices; i++){
      line(this.prevPos.x, this.prevPos.y, penLocation.x, penLocation.y);

      penLocation.rotate(this.rotationPerSlice);
      this.prevPos.rotate(this.rotationPerSlice);
    }

    this.prevPos.rotate(this.rotationPerSlice);
  }

  draw(){
    push();
    translate(this.x, this.y);

    if (mouseIsPressed && this.isPointInFirstSegment(mouseX, mouseY)){
      if (this.penWasDown){
        this.drawRepeatedly(mouseX, mouseY);
      }
      this.penWasDown = true;
      this.prevPos.x = this.x - mouseX;
      this.prevPos.y = this.y - mouseY;
    }else{
      this.penWasDown = false;
    }

    pop();
  }
}
{'fraction_non_alphanumeric': 0.1408787010506208, 'fraction_numerical': 0.0057306590257879654, 'mean_word_length': 2.4344262295081966, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '402745', 'n_tokens_mistral': 784, 'n_tokens_neox': 762, 'n_words': 151}