<commit_before>package doodle.examples

import doodle.core._
import doodle.syntax._

object Koch extends Drawable {
  def koch(depth: Int, start: Vec, angle: Angle, length: Double): Seq[PathElement] = {
    if(depth == 0) {
      Seq(LineTo(start + Vec.polar(angle, length)))
    } else {
      val lAngle = angle - 60.degrees
      val rAngle = angle + 60.degrees

      val third  = length / 3.0
      val edge   = Vec.polar(angle, third)

      val mid1 = start + edge
      val mid2 = mid1 + edge.rotate(-60.degrees)
      val mid3 = mid2 + edge.rotate( 60.degrees)
      val end  = mid3 + edge

      koch(depth-1, start,  angle, third) ++
      koch(depth-1,  mid1, lAngle, third) ++
      koch(depth-1,  mid2, rAngle, third) ++
      koch(depth-1,  mid3,  angle, third)
    }
  }

  def draw = {
    val size  = 405
    val depth = 4
    Path(koch(depth, Vec.zero, 0.degrees, size))
  }
}<commit_msg>`Koch` example shows n=1 to 4 triangles<commit_after>package doodle.examples

import doodle.core._
import doodle.syntax._

object Koch extends Drawable {
  def kochElements(depth: Int, start: Vec, angle: Angle, length: Double): Seq[PathElement] = {
    if(depth == 0) {
      Seq(LineTo(start + Vec.polar(angle, length)))
    } else {
      val lAngle = angle - 60.degrees
      val rAngle = angle + 60.degrees

      val third  = length / 3.0
      val edge   = Vec.polar(angle, third)

      val mid1 = start + edge
      val mid2 = mid1 + edge.rotate(-60.degrees)
      val mid3 = mid2 + edge.rotate( 60.degrees)
      val end  = mid3 + edge

      kochElements(depth-1, start,  angle, third) ++
      kochElements(depth-1,  mid1, lAngle, third) ++
      kochElements(depth-1,  mid2, rAngle, third) ++
      kochElements(depth-1,  mid3,  angle, third)
    }
  }

  def koch(depth: Int, length: Double): Image = {
    val origin = Vec(0, length/6)
    Path(MoveTo(origin) +: kochElements(depth, origin, 0.degrees, length))
  }

  val draw = allAbove((1 to 4) map { depth =>
    koch(depth, 512)
  })
}
{'fraction_non_alphanumeric': 0.12985074626865672, 'fraction_numerical': 0.03134328358208955, 'mean_word_length': 2.5592920353982302, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '5556329', 'n_tokens_mistral': 770, 'n_tokens_neox': 715, 'n_words': 192}