Last active
May 13, 2022 02:31
-
-
Save mattsan/3fcb5ef63d6ef8382be1fb0c4d3163a3 to your computer and use it in GitHub Desktop.
抵抗器のカラーコードは虹の色
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
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<title>COLOR CODE</title> | |
<script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script> | |
<style> | |
body { | |
display: flex; | |
justify-content: space-evenly; | |
} | |
.resistor-value { | |
text-align: center; | |
} | |
.resistor-image { | |
display: flex; | |
justify-content: space-evenly; | |
background-color: #fdb; | |
width: 300px; | |
height: 80px; | |
border-radius: 50px/100px; | |
} | |
.first-digit, .second-digit, .multiplier, .tolerance { | |
width: 40px; | |
} | |
</style> | |
<script> | |
document.addEventListener('alpine:init', () => { | |
const colors = [ | |
'black', 'brown', 'red', 'orange', 'yellow', | |
'green', 'blue', 'violet', 'gray', 'white', | |
'inherit', 'silver', 'gold' | |
] | |
Alpine.data('Resistor', () => { | |
return { | |
firstDigit: 0, | |
secondDigit: 0, | |
multiplier: 0, | |
tolerance: 1, | |
incFirstDigit () { this.firstDigit = (this.firstDigit + 1) % 10 }, | |
incSecondDigit () { this.secondDigit = (this.secondDigit + 1) % 10 }, | |
incMultiplier () { this.multiplier = (this.multiplier + 1) % 10 }, | |
incTolerance () { this.tolerance = (this.tolerance + 1) % 3 }, | |
getFirstDigitStyle () { return `background-color: ${colors[this.firstDigit]};` }, | |
getSecondDigitStyle () { return `background-color: ${colors[this.secondDigit]};` }, | |
getMultiplierStyle () { return `background-color: ${colors[this.multiplier]};` }, | |
getToleranceStyle () { return `background-color: ${colors[this.tolerance + 10]};` }, | |
getDigit () { return this.firstDigit * 10 + this.secondDigit }, | |
getTolerance () { return [20, 10, 5][this.tolerance] } | |
} | |
}) | |
}) | |
</script> | |
</head> | |
<body> | |
<div x-data="Resistor"> | |
<div class="resistor-value"> | |
<span x-text="getDigit"></span>× 10<sup x-text="multiplier"></sup>Ω ± <span x-text="getTolerance"></span>% | |
</div> | |
<div class="resistor-image"> | |
<div class="first-digit" @click="incFirstDigit" :style="getFirstDigitStyle"></div> | |
<div class="second-digit" @click="incSecondDigit" :style="getSecondDigitStyle"></div> | |
<div class="multiplier" @click="incMultiplier" :style="getMultiplierStyle"></div> | |
<div class="tolerance" @click="incTolerance" :style="getToleranceStyle"></div> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment