就是这个样的粗爆,手搓一个计算器:单位圆计算器

 线上运行,可以直接打开:单位圆计算器(在线计算器)

       作为程序员,没有合适的工具,就得手搓一个,PC端,移动端均可适用。废话不多说,直接上代码。

HTML:

<div class="calculator"><label for="angle">输入角度 (度):</label> <input id="angle" step="0.01" type="number" placeholder="角度"><button onclick="calculateUnitCircle()">计算坐标</button><div id="result" class="result">结果将显示在这里</div></div>

JS:

function calculateUnitCircle() {
        const angle = parseFloat(document.getElementById('angle').value);

        if (isNaN(angle)) {
            document.getElementById('result').textContent = "请输入有效的角度。";
            return;
        }

        // 将角度转换为弧度
        const angleInRadians = angle * (Math.PI / 180);

        // 计算单位圆上的坐标点
        const x = Math.cos(angleInRadians);
        const y = Math.sin(angleInRadians);

        // 计算正弦和余弦值
        const sine = Math.sin(angleInRadians);
        const cosine = Math.cos(angleInRadians);

        document.getElementById('result').innerHTML = 
            `单位圆坐标 (x, y):(${x.toFixed(2)}, ${y.toFixed(2)})<br>` +
            `正弦值:${sine.toFixed(2)}<br>` +
            `余弦值:${cosine.toFixed(2)}`;
    }

 CSS:

.calculator {
width: 100%;
    background-color: #333;
    color: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}


label {
    display: block;
    margin-bottom: 10px;
    font-size: 16px;
}

input, select {
    width: 100%!important;
    padding: 10px!important;
    margin-bottom: 20px;
       color: #000000; 
    border-radius: 5px;
    border: 1px solid #555;
    font-size: 16px!important;
    background-color: #ffffff!important;
}

button {
    width: 100%;
    padding: 10px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
        display: block;
        margin: 0px;
     margin-bottom: 20px;
    margin-left: 0px!important;
}

button:hover {
    background-color: orange;
}

.result {
    margin-top: 20px;
    text-align: center;
}

option {
        background-color: #ffffff;
}


p {
    font-size: 18px;
        margin-top: 5px!important;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值