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

const canvasSize = canvas.width

// draws a rectangle
function drawRect(x, y, size) {
    context.fillRect(x, y, size, size)
}

// recursive sierpinski sierpinskiCarpet function
function sierpinskiCarpet(x, y, size) {
    setTimeout(function(){

        // exit condition: rect is smaller than 1 (not visible anyway)
        if (size >= 1) {

            drawRect(x, y, size, size)

            const newSize = size / 3

            const xLeft = x - 2 * newSize
            const xMid = x + newSize
            const xRight = x + size + newSize

            const yTop = y - 2 * newSize
            const yMid = y + newSize
            const yBottom = y + size + newSize

            sierpinskiCarpet(xLeft, yTop, newSize)
            sierpinskiCarpet(xMid, yTop, newSize)
            sierpinskiCarpet(xRight, yTop, newSize)

            sierpinskiCarpet(xLeft, yMid, newSize)
            sierpinskiCarpet(xRight, yMid, newSize)

            sierpinskiCarpet(xLeft, yBottom, newSize)
            sierpinskiCarpet(xMid, yBottom, newSize)
            sierpinskiCarpet(xRight, yBottom, newSize)

       }
    },500)
}

const initialSize = canvasSize / 3

const initialXY = canvasSize / 2 - initialSize/2

sierpinskiCarpet(initialXY, initialXY, initialSize)<commit_msg>added colorful option to sierpinski carpet<commit_after>// setup canvas
const canvas = document.getElementById("fractalCanvas")
const context = canvas.getContext('2d')

// drawing parameters
const canvasSize = canvas.width
const colorful = true

// draws a rectangle
function drawRect(x, y, size) {
    if(colorful) {
        context.fillStyle = getRandomColorString()
    }
    context.fillRect(x, y, size, size)
}

// returns a random color in string format
function getRandomColorString() {
    const r = Math.floor(Math.random() * 255) + 1  
    const g = Math.floor(Math.random() * 255) + 1  
    const b = Math.floor(Math.random() * 255) + 1  

    return "rgb(" + r + "," + g + "," + b + ")"
}

// recursive sierpinski sierpinskiCarpet function
function sierpinskiCarpet(x, y, size) {
    setTimeout(function(){

        // exit condition: rect is smaller than 1 (not visible anyway)
        if (size >= 1) {

            drawRect(x, y, size, size)

            const newSize = size / 3

            const xLeft = x - 2 * newSize
            const xMid = x + newSize
            const xRight = x + size + newSize

            const yTop = y - 2 * newSize
            const yMid = y + newSize
            const yBottom = y + size + newSize

            sierpinskiCarpet(xLeft, yTop, newSize)
            sierpinskiCarpet(xMid, yTop, newSize)
            sierpinskiCarpet(xRight, yTop, newSize)

            sierpinskiCarpet(xLeft, yMid, newSize)
            sierpinskiCarpet(xRight, yMid, newSize)

            sierpinskiCarpet(xLeft, yBottom, newSize)
            sierpinskiCarpet(xMid, yBottom, newSize)
            sierpinskiCarpet(xRight, yBottom, newSize)

       }
    },500)
}

const initialSize = canvasSize / 3

const initialXY = canvasSize / 2 - initialSize/2

if(colorful) {
    context.fillStyle = "black"
    context.fillRect(0, 0, canvasSize, canvasSize)
}

sierpinskiCarpet(initialXY, initialXY, initialSize)
{'fraction_non_alphanumeric': 0.09750225699668974, 'fraction_numerical': 0.011435449894673488, 'mean_word_length': 2.430340557275542, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4786147', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1054, 'n_words': 284}