DEV Community

0 seconds of 0 secondsVolume 90%
Press shift question mark to access a list of keyboard shortcuts
00:00
00:00
00:00
 
Prince
Prince

Posted on

1

Illusionistic Pattern Making using the basic html,css and javascript. Follow for more....

Full code for the above pattern is:
`<!DOCTYPE html>




Infinity Grid Illusion
<br> * { margin: 0; padding: 0; box-sizing: border-box; }<br> body {<br> background: black;<br> overflow: hidden;<br> display: flex;<br> align-items: center;<br> justify-content: center;<br> height: 100vh;<br> }<br> canvas {<br> position: absolute;<br> }<br>


<script>
    const canvas = document.getElementById("gridCanvas");
    const ctx = canvas.getContext("2d");
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;

    let cols = 20, rows = 20;
    let cellSize = Math.min(canvas.width, canvas.height) / cols;
    let time = 0;

    function getColor(x, y) {
        const colors = ["#FF0077", "#00FFD1", "#FFAA00", "#8822FF", "#00CCFF"];
        return colors[(Math.floor(x / cellSize) + Math.floor(y / cellSize) + Math.floor(time * 2)) % colors.length];
    }

    function drawGrid() {
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        ctx.lineWidth = 2;

        for (let i = -1; i < cols; i++) {
            for (let j = -1; j < rows; j++) {
                let x = i * cellSize;
                let y = j * cellSize;

                let dx = x - canvas.width / 2;
                let dy = y - canvas.height / 2;
                let dist = Math.sqrt(dx * dx + dy * dy);

                // Warping effect
                let warpFactor = Math.sin(dist * 0.015 + time) * 15;

                let offsetX = warpFactor * Math.cos(time * 0.5);
                let offsetY = warpFactor * Math.sin(time * 0.5);

                ctx.strokeStyle = getColor(x, y);

                ctx.beginPath();
                ctx.rect(x + offsetX, y + offsetY, cellSize, cellSize);

                // Random flickering effect on some cells
                if (Math.random() > 0.97) {
                    ctx.fillStyle = ctx.strokeStyle;
                    ctx.fill();
                }

                ctx.stroke();
            }
        }

        time += 0.02;
        requestAnimationFrame(drawGrid);
    }

    drawGrid();
</script>



`

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay