<commit_before>// setup canvas
const canvas = document.getElementById("fractalCanvas")
const context = canvas.getContext('2d')

// draws a line
function drawLine(startPoint, endPoint) {
    context.beginPath()
    context.moveTo(startPoint.x, startPoint.y)
    context.lineTo(endPoint.x, endPoint.y)
    context.stroke()
}

// converts a degree angle to radians
function degToRad(angleDeg) {
    return angleDeg * (Math.PI / 180)
}

// draws a tree (recursively)
function drawTree(startPoint, endPoint, angleDeg) {

    // exit condition for recursion
    const diffX = startPoint.x - endPoint.x
    const diffY = startPoint.y - endPoint.y
    const lineLength = Math.sqrt(Math.pow(diffX, 2) + Math.pow(diffY, 2))

    if(lineLength<1) {
        return
    }

    // draw line between the two points
    drawLine(startPoint, endPoint)

    // calculate length of next lines
    const newLength = lineLength * 2/3

    // calculate angle between the two points
    const existingAngle = Math.atan2(endPoint.y - startPoint.y, endPoint.x - startPoint.x)

    // calculate new end points
    const pointRight = {
        x: endPoint.x + newLength * Math.cos((existingAngle - degToRad(angleDeg))),
        y: endPoint.y + newLength * Math.sin((existingAngle - degToRad(angleDeg)))
    }

    const pointLeft = {
        x: endPoint.x + newLength * Math.cos((existingAngle + degToRad(angleDeg))),
        y: endPoint.y + newLength * Math.sin((existingAngle + degToRad(angleDeg)))
    }

    drawTree(endPoint, pointRight, angleDeg)
    drawTree(endPoint, pointLeft, angleDeg)


}

//start the recursion
drawTree({x: 400, y: 700}, {x: 400, y: 550}, 30)<commit_msg>animated version possible<commit_after>// setup canvas
const canvas = document.getElementById("fractalCanvas")
const context = canvas.getContext('2d')

// drawing parameters
const shortenFactor = 0.7

// draws a line
function drawLine(startPoint, endPoint) {
    context.beginPath()
    context.moveTo(startPoint.x, startPoint.y)
    context.lineTo(endPoint.x, endPoint.y)
    context.stroke()
}

// converts a degree angle to radians
function degToRad(angleDeg) {
    return angleDeg * (Math.PI / 180)
}

// draws a tree (recursively)
function drawTree(startPoint, endPoint, angleDeg) {

    // exit condition for recursion
    const diffX = startPoint.x - endPoint.x
    const diffY = startPoint.y - endPoint.y
    const lineLength = Math.sqrt(Math.pow(diffX, 2) + Math.pow(diffY, 2))

    if(lineLength<1) {
        return
    }

    // draw line between the two points
    drawLine(startPoint, endPoint)

    // calculate length of next lines
    const newLength = lineLength * shortenFactor

    // calculate angle between the two points
    const existingAngle = Math.atan2(endPoint.y - startPoint.y, endPoint.x - startPoint.x)

    // calculate new end points
    const pointRight = {
        x: endPoint.x + newLength * Math.cos((existingAngle - degToRad(angleDeg))),
        y: endPoint.y + newLength * Math.sin((existingAngle - degToRad(angleDeg)))
    }

    const pointLeft = {
        x: endPoint.x + newLength * Math.cos((existingAngle + degToRad(angleDeg))),
        y: endPoint.y + newLength * Math.sin((existingAngle + degToRad(angleDeg)))
    }

    drawTree(endPoint, pointRight, angleDeg)
    drawTree(endPoint, pointLeft, angleDeg)


}

// static
drawTree({x: 400, y: 700}, {x: 400, y: 550}, 45)

// // animated
// let direction = 1
// let angle = 1

// setInterval(function() {
//     context.clearRect(0, 0, canvas.width, canvas.height)

//     if(angle === 0 || angle === 90) {
//         direction = - direction
//     }

//     drawTree({x: 400, y: 700}, {x: 400, y: 550}, angle)

//     angle += direction

// }, 5)
{'fraction_non_alphanumeric': 0.12597999459313328, 'fraction_numerical': 0.018383346850500134, 'mean_word_length': 3.0481400437636763, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1006252', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1159, 'n_words': 306}