-
Notifications
You must be signed in to change notification settings - Fork 1
/
Problema do Jardim.html
157 lines (136 loc) · 3.63 KB
/
Problema do Jardim.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Jardim de Área Máxima</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
text-align: center;
margin: 0;
padding: 20px;
background-color: #747474;
color: #000000;
}
#container {
border: 2px solid #3498db;
border-radius: 10px;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
max-width: 800px;
margin: 0 auto;
background-color: #ffffff;
}
h2 {
color: #3498db;
}
label {
font-size: 1.2em;
margin-right: 10px;
display: block;
margin-bottom: 10px;
color: #3498db;
}
input {
padding: 8px;
font-size: 1em;
width: 100%;
box-sizing: border-box;
margin-bottom: 20px;
}
button {
padding: 12px;
font-size: 1em;
background-color: #3498db;
color: rgb(255, 255, 255);
border: none;
cursor: pointer;
transition: background-color 0.3s ease;
width: 100%;
}
button:hover {
background-color: #2980b9;
}
p {
font-size: 1.2em;
margin-top: 20px;
color: #3498db;
}
span {
font-weight: bold;
color: #3498db;
}
canvas {
max-width: 100%;
margin-top: 20px;
}
</style>
</head>
<body>
<div id="container">
<h2>Jardim de Área Máxima</h2>
<label for="altura">Altura do Retângulo: </label>
<input type="number" id="altura" placeholder="Insira a altura">
<br><br>
<button onclick="calcular()">Calcular</button>
<br><br>
<p>Área do Retângulo: <span id="area"></span></p>
<p>Base do Retângulo: <span id="base"></span></p>
<canvas id="myChart"></canvas>
</div>
<script>
function calcular() {
var altura = parseFloat(document.getElementById('altura').value);
if (!isNaN(altura) && altura > 0 && altura < 8) {
var area = -(3/4) * Math.pow(altura, 2) + 6 * altura;
var base = area / altura;
document.getElementById('area').textContent = area.toFixed(2);
document.getElementById('base').textContent = base.toFixed(2);
var xValues = [];
var yValues = [];
for (let x = 0; x <= altura; x += 0.1) {
xValues.push(x.toFixed(2));
yValues.push((-(3/4) * Math.pow(x, 2) + 6 * x).toFixed(2));
}
var maxX = altura.toFixed(2);
var maxY = area.toFixed(2);
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: xValues,
datasets: [
{
label: 'Área do Retângulo',
data: yValues,
borderColor: '#3498db',
backgroundColor: 'transparent',
borderWidth: 2,
pointBackgroundColor: '#2980b9'
},
{
label: 'Ponto Máximo',
data: [{ x: maxX, y: maxY }],
pointRadius: 8,
backgroundColor: '#e74c3c',
borderColor: '#c0392b'
}
]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
} else {
alert('Por favor, insira uma altura válida maior que 0 e menor que 8.');
}
}
</script>
</body>
</html>