const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');

const DOT_SIZE = 5;
const GRID_SIZE = 50;
const DOT_SPACING = 10;
const NUM_DOTS = GRID_SIZE * GRID_SIZE;
const dots = [];

function init() {
    canvas.width = GRID_SIZE * DOT_SPACING;
    canvas.height = GRID_SIZE * DOT_SPACING;

    for (let i = 0; i < NUM_DOTS; i++) {
        dots.push({x: i % GRID_SIZE * DOT_SPACING, y: Math.floor(i / GRID_SIZE) * DOT_SPACING});
    }

    drawDots();
}

function drawDots() {
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    ctx.fillStyle = 'black';

    for (let i = 0; i < NUM_DOTS; i++) {
        ctx.beginPath();
        ctx.arc(dots[i].x, dots[i].y, DOT_SIZE, 0, Math.PI * 2);
        ctx.fill();
    }
}

function transform() {
    const matrixString = document.getElementById('matrix').value;
    const matrixArray = matrixString.trim().split(/\s+/).map(Number);

    if (matrixArray.length !== 6 || matrixArray.some(isNaN)) {
        alert('Invalid transformation matrix.');
        return;
    }

    const a = matrixArray[0];
    const b = matrixArray[1];
    const c = matrixArray[2];
    const d = matrixArray[3];
    const e = matrixArray[4];
    const f = matrixArray[5];

    const newDots = [];

    for (let i = 0; i < NUM_DOTS; i++) {
        const x = dots[i].x;
        const y = dots[i].y;

        const newX = a * x + c * y + e;
        const newY = b * x + d * y + f;

        newDots.push({x: newX, y: newY});
    }

    dots.splice(0, NUM_DOTS, ...newDots);

    drawDots();
}

init();
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence