-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6e298a
commit 61e5f1c
Showing
1 changed file
with
109 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,131 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>珠珠的刮刮乐</title> | ||
<style> | ||
body, html { | ||
margin: 0; | ||
padding: 0; | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
background-color: #f0f0f0; | ||
} | ||
.scratch-container { | ||
position: relative; | ||
width: 300px; | ||
height: 150px; | ||
} | ||
canvas { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
} | ||
#scratchCanvas { | ||
z-index: 2; | ||
} | ||
#backgroundCanvas { | ||
z-index: 1; | ||
} | ||
.header { | ||
font-size: 24px; | ||
margin-bottom: 20px; | ||
font-family: 'Brush Script MT', cursive; | ||
color: purple; | ||
} | ||
.footer { | ||
font-size: 18px; | ||
margin-top: 20px; | ||
width: 300px; | ||
text-align: right; | ||
} | ||
</style> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>珠珠的刮刮乐</title> | ||
<style> | ||
body, html { | ||
margin: 0; | ||
padding: 0; | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
background-color: #f0f0f0; | ||
} | ||
.scratch-container { | ||
position: relative; | ||
width: 400px; | ||
height: 200px; | ||
} | ||
canvas { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
} | ||
#scratchCanvas { | ||
z-index: 2; | ||
} | ||
#backgroundCanvas { | ||
z-index: 1; | ||
} | ||
.header { | ||
font-size: 24px; | ||
margin-bottom: 20px; | ||
font-family: 'Brush Script MT', cursive; | ||
color: purple; | ||
} | ||
.footer { | ||
font-size: 18px; | ||
margin-top: 20px; | ||
width: 400px; | ||
text-align: right; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="header">珠珠的刮刮乐</div> | ||
<div class="scratch-container"> | ||
<canvas id="backgroundCanvas"></canvas> | ||
<canvas id="scratchCanvas"></canvas> | ||
<canvas id="backgroundCanvas"></canvas> | ||
<canvas id="scratchCanvas"></canvas> | ||
</div> | ||
<div class="footer">萝卜公司</div> | ||
<script> | ||
const scratchCanvas = document.getElementById('scratchCanvas'); | ||
const scratchCtx = scratchCanvas.getContext('2d'); | ||
const backgroundCanvas = document.getElementById('backgroundCanvas'); | ||
const backgroundCtx = backgroundCanvas.getContext('2d'); | ||
const scratchCanvas = document.getElementById('scratchCanvas'); | ||
const scratchCtx = scratchCanvas.getContext('2d'); | ||
const backgroundCanvas = document.getElementById('backgroundCanvas'); | ||
const backgroundCtx = backgroundCanvas.getContext('2d'); | ||
|
||
const canvasWidth = 300; | ||
const canvasHeight = 150; | ||
const canvasWidth = 400; | ||
const canvasHeight = 200; | ||
|
||
scratchCanvas.width = canvasWidth; | ||
scratchCanvas.height = canvasHeight; | ||
backgroundCanvas.width = canvasWidth; | ||
backgroundCanvas.height = canvasHeight; | ||
scratchCanvas.width = canvasWidth; | ||
scratchCanvas.height = canvasHeight; | ||
backgroundCanvas.width = canvasWidth; | ||
backgroundCanvas.height = canvasHeight; | ||
|
||
let isScratching = false; | ||
let isScratching = false; | ||
|
||
// Load and draw the background image | ||
let backgroundImage = new Image(); | ||
backgroundImage.onload = function() { | ||
backgroundCtx.drawImage(backgroundImage, 0, 0, canvasWidth, canvasHeight); | ||
}; | ||
backgroundImage.src = 'img/1.jpg'; // Ensure this path is correct | ||
// Load and draw the background image | ||
let backgroundImage = new Image(); | ||
backgroundImage.onload = function() { | ||
backgroundCtx.drawImage(backgroundImage, 0, 0, canvasWidth, canvasHeight); | ||
}; | ||
backgroundImage.src = '1.jpg'; // Ensure this path is correct | ||
|
||
// Fill the scratch canvas with a light purple color | ||
scratchCtx.fillStyle = '#C8A2C8'; | ||
scratchCtx.fillRect(0, 0, canvasWidth, canvasHeight); | ||
// Fill the scratch canvas with a light purple color | ||
scratchCtx.fillStyle = '#C8A2C8'; | ||
scratchCtx.fillRect(0, 0, canvasWidth, canvasHeight); | ||
|
||
// Event listeners for mouse and touch events | ||
scratchCanvas.addEventListener('mousedown', startScratch); | ||
scratchCanvas.addEventListener('mousemove', scratch); | ||
scratchCanvas.addEventListener('mouseup', stopScratch); | ||
scratchCanvas.addEventListener('mouseleave', stopScratch); | ||
scratchCanvas.addEventListener('touchstart', startScratch); | ||
scratchCanvas.addEventListener('touchmove', scratch); | ||
scratchCanvas.addEventListener('touchend', stopScratch); | ||
// Draw grid lines and border to divide the canvas into 3x3 sections | ||
scratchCtx.strokeStyle = '#800080'; // Deep purple color | ||
scratchCtx.lineWidth = 2; | ||
for (let i = 1; i <= 2; i++) { | ||
scratchCtx.beginPath(); | ||
scratchCtx.moveTo(i * canvasWidth / 3, 0); | ||
scratchCtx.lineTo(i * canvasWidth / 3, canvasHeight); | ||
scratchCtx.stroke(); | ||
|
||
function startScratch(e) { | ||
isScratching = true; | ||
scratch(e); | ||
} | ||
scratchCtx.beginPath(); | ||
scratchCtx.moveTo(0, i * canvasHeight / 3); | ||
scratchCtx.lineTo(canvasWidth, i * canvasHeight / 3); | ||
scratchCtx.stroke(); | ||
} | ||
// Draw border | ||
scratchCtx.strokeRect(0, 0, canvasWidth, canvasHeight); | ||
|
||
function scratch(e) { | ||
if (!isScratching) return; | ||
var x = e.clientX || e.touches[0].clientX; | ||
var y = e.clientY || e.touches[0].clientY; | ||
x -= scratchCanvas.getBoundingClientRect().left; | ||
y -= scratchCanvas.getBoundingClientRect().top; | ||
scratchCtx.globalCompositeOperation = 'destination-out'; | ||
scratchCtx.beginPath(); | ||
scratchCtx.arc(x, y, 30, 0, Math.PI * 2); | ||
scratchCtx.fill(); | ||
} | ||
// Event listeners for mouse and touch events | ||
scratchCanvas.addEventListener('mousedown', startScratch); | ||
scratchCanvas.addEventListener('mousemove', scratch); | ||
scratchCanvas.addEventListener('mouseup', stopScratch); | ||
scratchCanvas.addEventListener('mouseleave', stopScratch); | ||
scratchCanvas.addEventListener('touchstart', startScratch); | ||
scratchCanvas.addEventListener('touchmove', scratch); | ||
scratchCanvas.addEventListener('touchend', stopScratch); | ||
|
||
function stopScratch() { | ||
isScratching = false; | ||
} | ||
function startScratch(e) { | ||
isScratching = true; | ||
scratch(e); | ||
} | ||
|
||
function scratch(e) { | ||
if (!isScratching) return; | ||
var x = e.clientX || e.touches[0].clientX; | ||
var y = e.clientY || e.touches[0].clientY; | ||
x -= scratchCanvas.getBoundingClientRect().left; | ||
y -= scratchCanvas.getBoundingClientRect().top; | ||
scratchCtx.globalCompositeOperation = 'destination-out'; | ||
scratchCtx.beginPath(); | ||
scratchCtx.arc(x, y, 30, 0, Math.PI * 2); | ||
scratchCtx.fill(); | ||
} | ||
|
||
function stopScratch() { | ||
isScratching = false; | ||
} | ||
</script> | ||
</body> | ||
</html> |