Browse Source

added hw10, end control RGB and audio control

makstravm 3 years ago
parent
commit
0c3e05fb10

HW10/1@3x.png → HW10/audio/1@3x.png


BIN
HW10/audio/BURN_V60.mp3


+ 37 - 0
HW10/audio/index.html

@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html lang="en-ru">
+
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <link rel="stylesheet" href="style.css">
+  <title>HW10 - audio</title>
+
+</head>
+
+
+<body id='body'>
+  <div class="container">
+    <div id='container1'></div>
+    <div id="containerRgb">
+      <div id="box"><span></span></div>
+    </div>
+
+    <div class="audio">
+      <div id='volMus' class="volume">Volume<span>100%</span></div>
+      <div id='speedMus' class="volume">Speed<span>100%</span></div>
+      <audio src="BURN_V60.mp3" id="track" preload></audio>
+      <button id='btn' class="btn">
+        <img class="play" src="play.svg" alt="play">
+        <img class="stop" src="stop.svg" alt="play">
+      </button>
+      <div id='progressMus' class="volume">Progress<span>100%</span></div>
+    </div>
+
+
+    <script src="main.js"></script>
+
+</body>
+
+</html>

+ 153 - 0
HW10/audio/main.js

@@ -0,0 +1,153 @@
+function Control(el, { value = 0,
+  min = 0,
+  max = 100,
+  minAngle = 0,
+  maxAngle = 270,
+  width = 200,
+  wheelSpeed = 0.1,
+  step = 1 } = {}) {
+
+  const img = document.createElement('img')
+  img.src = '1@3x.png'
+  img.width = width
+  el.append(img)
+
+  const ratio = (maxAngle - minAngle) / (max - min)// сколько градусов 1 ед. велью
+  const getAngle = () => (value - min) * ratio + minAngle // текущий угол ползунка
+
+  this.setValue = newValue => { //проверить, вдруг в этом объекте есть onchange
+    if (newValue > max) newValue = max
+    if (newValue < min) newValue = min
+    if (typeof this.onchange === 'function') {
+      this.onchange(newValue)
+    }
+    value = newValue //и запустить его с новым value
+    img.style.transform = `rotate(${getAngle()}deg)`
+  }
+  this.getValue = () => value
+
+  img.onmousewheel = e => {
+    const { deltaY } = e
+    const newValue = value + deltaY * wheelSpeed
+    this.setValue(newValue)
+    e.preventDefault()
+  }
+
+  img.onclick = e => {
+    const { layerX } = e
+    const { width } = img
+    layerX > width / 2 ? this.setValue(value + step) : this.setValue(value - step)
+  }
+
+  const toDeg = rad => ((rad * 180) / Math.PI + 360 + 90) % 360
+  let prevMouseAngle = null
+
+  img.onmousedown = e => {
+    const y = e.layerY - img.height / 2
+    const x = e.layerX - img.width / 2
+    prevMouseAngle = toDeg(Math.atan2(y, x))
+    e.preventDefault()
+  }
+
+  img.onmousemove = e => {
+    if (prevMouseAngle === null) return
+    const y = e.layerY - img.height / 2
+    const x = e.layerX - img.width / 2
+    let currentAngle = toDeg(Math.atan2(y, x))
+    let moveAngleDiff = (currentAngle - prevMouseAngle)
+    this.setValue(value + moveAngleDiff / ratio)
+    prevMouseAngle = currentAngle
+  }
+
+  img.onmouseout = img.onmouseup = () => {
+    prevMouseAngle = null
+  }
+
+  this.setValue(value)
+}
+
+// const volumeControl = new Control(container1, { value: 13, min: 0, max: 100, minAngle: 0, maxAngle: 270, width: 150 })
+// volumeControl.onchange = value => console.log(value) //на каждый setValue
+// console.log(volumeControl.getValue())
+// setTimeout(() => volumeControl.setValue(80), 2000)
+//пришейте к нему тэг audio для громкости
+
+function setRGB() {
+  box.style.backgroundColor = `rgb(${red.getValue().toFixed(0)},${green.getValue().toFixed(0)},${blue.getValue().toFixed(0)})`
+  box.children[0].innerText = `color rgb:${red.getValue().toFixed(0)},${green.getValue().toFixed(0)},${blue.getValue().toFixed(0)}`
+}
+
+const red = new Control(containerRgb, { min: 0, max: 255, width: 100 })
+red.onchange = setRGB
+const green = new Control(containerRgb, { min: 0, max: 255, width: 100 })
+green.onchange = setRGB
+const blue = new Control(containerRgb, { min: 0, max: 255, width: 100 })
+blue.onchange = setRGB
+
+// громкость звука
+const volume = new Control(volMus, {
+  value: 1, min: 0, max: 1, width: 100, wheelSpeed: 0.001, step: 0.1
+})
+volume.onchange = controlAudio
+// скорость проигрывания
+const speedTrack = new Control(speedMus, {
+  value: 1, min: 0.5, max: 1.5, width: 100, wheelSpeed: 0.001, step: 0.1
+})
+speedTrack.onchange = controlAudio
+// прогресс трека
+const progressTrack = new Control(progressMus, {
+  value: 0, min: 0, max: 100, width: 100, wheelSpeed: 0.01, step: 1
+})
+
+// отрисовка изначальных данных в хтмл
+volMus.children[0].innerText = `${(volume.getValue() * 100).toFixed(0)}%`
+speedMus.children[0].innerText = `${(speedTrack.getValue() * 100).toFixed(0)}%`
+progressMus.children[0].innerText = `${progressTrack.getValue().toFixed(0)}%`
+
+// ф-я контейнер для контроллеров
+function controlAudio() {
+  track.volume = volume.getValue()
+  volMus.children[0].innerText = `${(volume.getValue() * 100).toFixed(0)}%`
+  track.playbackRate = speedTrack.getValue()
+  speedMus.children[0].innerText = `${(speedTrack.getValue() * 100).toFixed(0)}%`
+  track.currentTime = (track.duration / 100) * progressTrack.getValue()
+  progressMus.children[0].innerText = `${progressTrack.getValue().toFixed(0)}%`
+}
+
+btn.onclick = regulatorPlayTrack()
+
+function regulatorPlayTrack() {
+  let chek = false//чек для плей и стоп
+  let stopAnim;
+  let stopGlyuk;
+  return function () {
+    // функция для визуального ефекта прогресса проигрывания
+    let reDraw = function () {
+      progressTrack.setValue((track.currentTime * 100) / track.duration)
+      progressMus.children[0].innerText = `${progressTrack.getValue().toFixed(0)}%`
+      console.log(3);
+    }
+    // рандом боди при проигрывание
+    let glyuk = function () {
+      body.style.backgroundColor = `rgb(${Math.round(Math.random() * 255).toFixed(0)},${Math.round(Math.random() * 255).toFixed(0)},${Math.round(Math.random() * 255).toFixed(0)})`
+    }
+    // добавляем клас для замены отрисовки кнопки
+    btn.classList.toggle("active");
+    if (!chek) {
+      track.play()
+      progressTrack.onchange = ''
+      chek = true
+      stopAnim = setInterval(reDraw, 100);
+      stopGlyuk = setInterval(glyuk, 300);
+    } else {
+      track.pause()
+      progressTrack.onchange = controlAudio
+      chek = false
+      clearInterval(stopAnim)
+      clearInterval(stopGlyuk)
+    }
+  }
+}
+
+
+

+ 43 - 0
HW10/audio/play.svg

@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
+<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+	 viewBox="0 0 459 459" style="enable-background:new 0 0 459 459;" xml:space="preserve">
+<g>
+	<g>
+		<path d="M229.5,0C102.751,0,0,102.751,0,229.5S102.751,459,229.5,459S459,356.249,459,229.5S356.249,0,229.5,0z M310.292,239.651
+			l-111.764,76.084c-3.761,2.56-8.63,2.831-12.652,0.704c-4.022-2.128-6.538-6.305-6.538-10.855V153.416
+			c0-4.55,2.516-8.727,6.538-10.855c4.022-2.127,8.891-1.857,12.652,0.704l111.764,76.084c3.359,2.287,5.37,6.087,5.37,10.151
+			C315.662,233.564,313.652,237.364,310.292,239.651z"/>
+	</g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+</svg>

+ 39 - 0
HW10/audio/stop.svg

@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!-- Generator: Adobe Illustrator 18.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+	 viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve">
+<path d="M256,0C114.617,0,0,114.615,0,256s114.617,256,256,256s256-114.615,256-256S397.383,0,256,0z M224,320
+	c0,8.836-7.164,16-16,16h-32c-8.836,0-16-7.164-16-16V192c0-8.836,7.164-16,16-16h32c8.836,0,16,7.164,16,16V320z M352,320
+	c0,8.836-7.164,16-16,16h-32c-8.836,0-16-7.164-16-16V192c0-8.836,7.164-16,16-16h32c8.836,0,16,7.164,16,16V320z"/>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+</svg>

+ 69 - 0
HW10/audio/style.css

@@ -0,0 +1,69 @@
+body {
+  font-size: 10px;
+  line-height: 10px;
+  box-sizing: border-box;
+  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
+  transition: all 0.5s;
+}
+.container {
+  max-width: 1200px;
+  padding: 15px;
+  text-align: center;
+}
+#box {
+  width: 100%;
+  height: 35vh;
+  border: 1px solid #000000;
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  font-size: 2em;
+  margin: 10px 0;
+}
+img {
+  border-radius: 50%;
+  overflow: hidden;
+  margin: 0 15px;
+  cursor: pointer;
+}
+span {
+  background-color: #fff;
+  padding: 0 10px;
+  line-height: 2em;
+  margin-bottom: 10px;
+}
+.audio {
+  padding-top: 50px;
+  display: flex;
+  align-items: flex-end;
+  justify-content: center;
+}
+.volume {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  font-size: 1.5em;
+  line-height: 1.6em;
+}
+.btn {
+  border: none;
+  background-color: transparent;
+  cursor: pointer;
+  border-radius: 50%;
+  overflow: hidden;
+}
+.btn img {
+  width: 100px;
+}
+.btn .play {
+  display: block;
+}
+.btn .stop {
+  display: none;
+}
+.btn.active .play {
+  display: none;
+}
+.btn.active .stop {
+  display: block;
+}

+ 0 - 89
HW10/main.js

@@ -1,89 +0,0 @@
-function Control(el, { value = 0,
-  min = 0,
-  max = 100,
-  minAngle = 0,
-  maxAngle = 270,
-  width = 200,
-  wheelSpeed = 0.1,
-  step = 1 } = {}) {
-
-  const img = document.createElement('img')
-  img.src = '1@3x.png'
-  img.width = width
-  el.append(img)
-
-  const ratio = (maxAngle - minAngle) / (max - min)// сколько градусов 1 ед. велью
-  const getAngle = () => (value - min) * ratio + minAngle // текущий угол ползунка
-
-  this.setValue = newValue => { //проверить, вдруг в этом объекте есть onchange
-    if (newValue > max) newValue = max
-    if (newValue < min) newValue = min
-    if (typeof this.onchange === 'function') {
-      this.onchange(value)
-    }
-    value = newValue //и запустить его с новым value
-    img.style.transform = `rotate(${getAngle()}deg)`
-  }
-  this.getValue = () => value
-  this.onchange = value => value
-
-  img.onmousewheel = e => {
-    const { deltaY } = e
-    const newValue = value + deltaY * wheelSpeed
-    this.setValue(newValue)
-    e.preventDefault()
-  }
-
-  img.onclick = e => {
-    const { layerX } = e
-    const { width } = img
-    layerX > width / 2 ? this.setValue(value + step) : this.setValue(value - step)
-  }
-
-  const toDeg = rad => ((rad * 180) / Math.PI + 360 + 90) % 360
-  let prevMouseAngle = null
-
-  img.onmousedown = e => {
-    const y = e.layerY - img.height / 2
-    const x = e.layerX - img.width / 2
-    prevMouseAngle = toDeg(Math.atan2(y, x))
-    e.preventDefault()
-  }
-
-  img.onmousemove = e => {
-    if (prevMouseAngle === null) return
-    const y = e.layerY - img.height / 2
-    const x = e.layerX - img.width / 2
-    let currentAngle = toDeg(Math.atan2(y, x))
-    let moveAngleDiff = (currentAngle - prevMouseAngle)
-    this.setValue(value + moveAngleDiff / ratio)
-    prevMouseAngle = currentAngle
-  }
-
-  img.onmouseout = img.onmouseup = () => {
-    prevMouseAngle = null
-  }
-
-  this.setValue(value)
-}
-
-// const volumeControl = new Control(container1, { value: 13, min: 0, max: 100, minAngle: 0, maxAngle: 270, width: 150 })
-// volumeControl.onchange = value => console.log(value) //на каждый setValue
-// console.log(volumeControl.getValue())
-// setTimeout(() => volumeControl.setValue(80), 2000)
-//пришейте к нему тэг audio для громкости
-
-function setRGB() {
-  box.style.backgroundColor = `rgb(${red.getValue().toFixed(0)},${green.getValue().toFixed(0)},${blue.getValue().toFixed(0)})`
-  box.children[0].innerText = `color rgb:${red.getValue().toFixed(0)},${green.getValue().toFixed(0)},${blue.getValue().toFixed(0)}`
-}
-
-const red = new Control(container1, { min: 0, max: 255, width: 150 })
-red.onchange = setRGB
-const green = new Control(container1, { min: 0, max: 255, width: 150 })
-green.onchange = setRGB
-const blue = new Control(container1, { min: 0, max: 255, width: 150 })
-blue.onchange = setRGB
-
-
-

+ 0 - 29
HW10/style.css

@@ -1,29 +0,0 @@
-body {
-  font-size: 10px;
-  line-height: 10px;
-  box-sizing: border-box;
-  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
-}
-.container {
-  max-width: 1200px;
-  padding: 15px;
-  text-align: center;
-}
-#box {
-  width: 100%;
-  height: 35vh;
-  border: 1px solid #000000;
-  display: flex;
-  align-items: center;
-  justify-content: center;
-  font-size: 2em;
-}
-img {
-  border-radius: 50%;
-  overflow: hidden;
-}
-span {
-  background-color: #fff;
-  padding: 0 10px;
-  line-height: 2em;
-}

+ 3 - 7
HW10/index.html

@@ -6,16 +6,12 @@
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <link rel="stylesheet" href="style.css">
-  <title>HW9</title>
+  <title>HW10 - task</title>
 
 </head>
 
-
-<body>
-  <div class="container">
-    <div id='container1'></div>
-    <div id="box"><span></span></div>
-  </div>
+<body >
+  
 
   <script src="main.js"></script>
 

+ 42 - 0
HW10/taskHW/main.js

@@ -0,0 +1,42 @@
+function Password(parent, open = false) {
+
+  let input = document.createElement('input')
+  let checkBox = document.createElement('input')
+  input.type = open ? 'text' : 'password'
+  checkBox.type = 'checkbox'
+  checkBox.checked = open
+  parent.append(input)
+  parent.append(checkBox)
+
+  this.getValue = () => input.value
+  this.getOpen = () => checkBox.checked
+
+  this.setValue = newValue => input.value = newValue
+  this.setOpen = () => checkBox.checked ? input.type = 'text' : input.type = 'password'
+
+
+  input.oninput = () => this.onChange()
+  checkBox.oninput = () => {
+    this.setOpen()
+    if (typeof this.onOpenChange === 'function') {
+      this.onOpenChange(checkBox.checked)
+    }
+
+  }
+}
+
+let p = new Password(document.body, true)
+p.onChange = () => console.log(p.getValue())
+p.onOpenChange = (open) => console.log(open)
+p.setValue('qwerty')
+console.log(p.getValue())
+
+let login = new Password(document.body, false)
+let button = document.createElement('button')
+button.setAttribute('disabled', 'disabled')
+button.innerText = 'LogIn'
+document.body.append(button)
+
+let checkDisabled = () => p.getValue() !== '' && p.getValue() !== '' ? button.removeAttribute('disabled', 'disabled') : button.setAttribute('disabled', 'disabled')
+p.onChange = () => checkDisabled()
+login.onChange = () => checkDisabled()

+ 12 - 0
HW10/taskHW/style.css

@@ -0,0 +1,12 @@
+body {
+  font-size: 10px;
+  line-height: 10px;
+  box-sizing: border-box;
+  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
+  transition: all 0.5s;
+}
+.container {
+  max-width: 1200px;
+  padding: 15px;
+  text-align: center;
+}