Canvas Optical Illusion
How do I make an canvas optical illusion?
Recreation of an optical illusion from a reddit thread.https://www.reddit.com/r/pics/comments/52bs6k/this_isnt_a_gif_your_eyes_just_cant_see_all_12/. What is a canvas optical illusion? How do you make a canvas optical illusion? This script and codes were developed by Kevin on 27 August 2022, Saturday.
Canvas Optical Illusion - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Canvas Optical Illusion</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <canvas id = "canvas"></canvas> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Canvas Optical Illusion - Script Codes CSS Codes
body{ margin: 0;
}
#canvas { display: block; height: 100vh; width: 100vw;
}
Canvas Optical Illusion - Script Codes JS Codes
function draw() { var canvas = document.getElementById("canvas"); canvas.width = window.innerWidth; canvas.height = window.innerHeight; window.addEventListener('resize', resizeCanvas, false); function resizeCanvas() { canvas.width = window.innerWidth; canvas.height = window.innerHeight; start(); } if (canvas.getContext) { var ctx = canvas.getContext("2d"); function start() { var size = canvas.width / 20; ctx.strokeStyle = "gray"; ctx.lineWidth = 6; for (var x = 0; x < canvas.width; x += size) { ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, canvas.height); ctx.stroke(); } for (var x = 0; x < canvas.height; x += size) { ctx.beginPath(); ctx.moveTo(0, x); ctx.lineTo(canvas.width, x); ctx.stroke(); } for (var x = 0; x < canvas.width; x += size) { ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x - canvas.height, canvas.height); ctx.stroke(); } for (var x = 0; x < canvas.height; x += size) { ctx.beginPath(); ctx.moveTo(0, x); ctx.lineTo(canvas.height - x, canvas.height); ctx.stroke(); } for (var x = 0; x < canvas.width; x += size) { ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x + canvas.height, canvas.height); ctx.stroke(); } for (var x = 0; x < canvas.height; x += size) { ctx.beginPath(); ctx.moveTo(canvas.width, x); ctx.lineTo(canvas.width - canvas.height + x, canvas.height); ctx.stroke(); } for (var x = 0; x < canvas.width; x += (canvas.width / 20) * 2) { for (var z = 0; z < canvas.height; z += (canvas.width / 20) * 2) { ctx.beginPath(); ctx.fillStyle = "white"; ctx.arc(x, z, 6, 0, Math.PI * 2); ctx.fill(); ctx.beginPath(); ctx.fillStyle = "black"; ctx.arc(x, z, 5, 0, Math.PI * 2); ctx.fill(); } } } start(); }
}
draw();
Developer | Kevin |
Username | KevinBruland |
Uploaded | August 27, 2022 |
Rating | 3 |
Size | 2,148 Kb |
Views | 26,312 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Canvas Circle Illusion | 3,285 Kb |
Pixel Painter Current | 4,014 Kb |
Memory | 4,680 Kb |
A Pen by Kevin | 2,831 Kb |
CSS Zen Garden Template | 8,867 Kb |
Canvas Gears | 2,800 Kb |
CSS Transform Sphere | 1,995 Kb |
Canvas Spiral Loader | 2,359 Kb |
Pomodoro Clock | 4,580 Kb |
Canvas Mouse Position Radial Gradient | 2,031 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Polygon Logo in CSS | Kai | 3,412 Kb |
Ripples in water | Nobitagit | 2,704 Kb |
RSW | JordanC | 3,726 Kb |
Haml Calendar | Katydecorah | 5,643 Kb |
IE flex collapse bug fix | Rowno | 2,678 Kb |
Planet Awesome | Bartuc | 3,554 Kb |
Practice using Wixel | Emnk | 3,057 Kb |
Main page display | BarryKe | 4,562 Kb |
Gradients | Karpovsystems | 2,394 Kb |
Word Wrap Algorithm for Multiline Canvas Text | Peterhry | 2,349 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!