Skip to content

Commit

Permalink
Merge pull request #48 from nihalsaran/main
Browse files Browse the repository at this point in the history
test small k
  • Loading branch information
ishantdei authored Oct 11, 2024
2 parents 5321880 + df6a24e commit a7e1ecd
Show file tree
Hide file tree
Showing 10 changed files with 793 additions and 0 deletions.
330 changes: 330 additions & 0 deletions experiment/simulation/LettersPage/SmaK/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,330 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Connect Dots</title>
<style>
body {
display: flex;
justify-content: center; /* Center horizontally */
align-items: center; /* Center vertically */
height: 100vh; /* Full height of the viewport */
margin: 0; /* Remove default margin */
}

#canvas-container {
position: relative;
width: 400px;
height: 400px;
border: 1px solid black;
display: flex;
justify-content: center;
align-items: center;
}

#canvas {
position: absolute;
top: 0;
left: 0;
border: 1px solid black;
z-index: 10;
}

.dot {
position: absolute;
width: 10px;
height: 10px;
background-color: red;
border-radius: 50%;
transform: translate(-50%, -50%);
}




#stroke1 {

display: none;
position: absolute;
top: 08px;
left: 90px;
width: 15px;
height: 305px;


}

#stroke2 {

display: none;
position: absolute;
top: 50px;
left: 170px;
width: 15px;
height: 210px;
transform: rotate(54deg);

}

#stroke3 {

display: none;
position: absolute;
top: 155px;
left: 200px;
width: 15px;
height: 183px;
transform: rotate(137deg);

}

#stroke4 {

display: none;
position: absolute;
top: 248px;
left: 211px;
width: 10px;
height: 143px;
transform: rotate(90deg);

}
#sbox {
position: relative;
left: 115px;
width: 400px;
height: 400px;
z-index: -2;
display: none;
}

#trace {
position: relative;
bottom: 20px;
right: 90px;
width: 600px;
height: 550px;
z-index: -10;
}

.arrrow1 {

position: absolute;
top: 80px;
left: 30px;
width: 40px;
height: 240px;
transform: rotate(180deg);
z-index: 0;
}
.arrrow2 {

top: 50px;
left: 170px;
position: absolute;
transform: rotate(55deg);
z-index: 0;
width: 30px;
height: 110px;
z-index: -2;
}
.arrrow3 {

position: absolute;
transform: rotate(135deg);
z-index: 0;
top: 140px;
left: 250px;
width: 20px;
height: 160px;
}

.arrrow4 {

position: absolute;
top: 280px;
left: 205px;
width: 30px;
height: 110px;
transform: rotate(90deg);
z-index: 0;
}
</style>
</head>

<body>

<div id="canvas-container">
<canvas id="canvas" width="400" height="400"></canvas>
<div class="dot" id="dot3" style="top: 10px; left: 97px;"></div>
<div class="dot" id="dot4" style="top: 95px; left: 263px;"></div>
<div class="dot" id="dot1" style="top: 311px; left: 97px;"></div>
<div class="dot" id="dot2" style="top: 217px; left: 97px;"></div>
<div class="dot" id="dot5" style="top: 185px; left: 145px;"></div>
<div class="dot" id="dot6" style="top: 310px; left: 265px;"></div>
<img id="sbox" src="sboxx.png" >
<img id="trace" src="k-new.png" >
<img class="arrrow1" id="arrow1" src="without-bg.gif" alt="Overlay Image">
<img class="arrrow2" id="arrow2" src="without-bg.gif" alt="Overlay Image">
<img class="arrrow3" id="arrow3" src="without-bg.gif" alt="Overlay Image">

<img id="stroke1" src="stroke1.png" >
<img id="stroke2" src="stroke1.png" >
<img id="stroke3" src="stroke1.png" >

</div>

<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const dot3 = document.getElementById('dot3');
const dot1 = document.getElementById('dot1');
const dot2 = document.getElementById('dot2');
const dot4 = document.getElementById('dot4');
const dot5 = document.getElementById('dot5');
const dot6 = document.getElementById('dot6'); // Added dot6
const arrow1 = document.getElementById('arrow1');
const arrow2 = document.getElementById('arrow2');
const arrow3 = document.getElementById('arrow3');


let isDrawing = false;
let startX = 0;
let startY = 0;
let tolerance = 30; // Tolerance radius for dot connection
let nextConnection = 'dot3-dot1'; // Start with connecting dot3 to dot1

arrow1.style.display = 'block'; // Initially, arrow1 is visible
arrow2.style.display = 'none';
arrow3.style.display = 'none';


function checkDotTolerance(dot, x, y) {
return Math.hypot(x - (dot.offsetLeft + 5), y - (dot.offsetTop + 5)) <= tolerance;
}

function drawToleranceCircle(dot, ctx) {
ctx.beginPath();
ctx.arc(dot.offsetLeft + 5, dot.offsetTop + 5, tolerance, 0, 2 * Math.PI);
ctx.strokeStyle = 'rgba(255, 200, 0, 0.5)'; // Visual guide for connection
ctx.stroke();
}

function startDrawing(e) {
const rect = canvas.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
let targetDot;

switch (nextConnection) {
case 'dot3-dot1':
targetDot = dot3;
break;
case 'dot2-dot4':
targetDot = dot2;
break;
case 'dot5-dot6':
targetDot = dot5;
break;
}

if (!checkDotTolerance(targetDot, x, y)) {
alert('Please follow rules and draw accordingly. Try again!');
return; // Do not start drawing if not within tolerance of target dot
}

ctx.clearRect(0, 0, canvas.width, canvas.height);
drawToleranceCircle(targetDot, ctx);

isDrawing = true;
startX = targetDot.offsetLeft + 5;
startY = targetDot.offsetTop + 5;
}


function draw(e) {
if (!isDrawing) return;
const rect = canvas.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
ctx.beginPath();
ctx.moveTo(startX, startY);
ctx.lineTo(x, y);
ctx.stroke();
startX = x;
startY = y;
ctx.strokeStyle = 'black'; // Change line color to black
ctx.lineWidth = 6;
}

function stopDrawing(e) {
if (!isDrawing) return;
const rect = canvas.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
let targetDot;

switch (nextConnection) {
case 'dot3-dot1':
targetDot = dot1;
break;
case 'dot2-dot4':
targetDot = dot4;
break;
case 'dot5-dot6':
targetDot = dot6;
break;
}

if (checkDotTolerance(targetDot, x, y)) {
console.log('Stopped drawing near', targetDot.id);
let strokeId;
switch (nextConnection) {
case 'dot3-dot1':
strokeId = '1';
nextConnection = 'dot2-dot4';
arrow1.style.display = 'none';
arrow2.style.display = 'block';
dot2.style.zIndex = 4; // Bring dot4 to front
break;
case 'dot2-dot4':
strokeId = '2';
nextConnection = 'dot5-dot6';
dot2.style.zIndex = 0; // Reset dot2 z-index
arrow2.style.display = 'none';
arrow3.style.display = 'block';
dot5.style.zIndex = 4; // Bring dot5 to front

break;
case 'dot5-dot6':
strokeId = '3';
dot5.style.zIndex = 0; // Reset dot5 z-index
arrow3.style.display = 'none';
dot6.style.display = 'none'; // Bring dot6 to front
// Optionally loop back or end the sequence
// In this case, you may want to reset the connections, e.g., nextConnection = 'dot3-dot1';
break;
}

if (strokeId) {
document.getElementById('stroke' + strokeId).style.display = 'block';
}
ctx.clearRect(0, 0, canvas.width, canvas.height);
} else {
alert('Complete the line near the correct dot. Try Again!');
ctx.clearRect(0, 0, canvas.width, canvas.height); // Clear the canvas
}
isDrawing = false;
}

canvas.addEventListener('mousedown', startDrawing);
canvas.addEventListener('mousemove', draw);
canvas.addEventListener('mouseup', stopDrawing);


</script>
</body>

</html>
Binary file added experiment/simulation/LettersPage/SmaK/k-new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a7e1ecd

Please sign in to comment.