asmerC.html 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width" />
  6. <title>Rgb</title>
  7. <style>
  8. </style>
  9. </head>
  10. <body>
  11. <script>
  12. function Control(el, {value=0, step=1,
  13. max=100, min=0,
  14. maxAngle=360, minAngle=0}={}){
  15. const img = document.createElement('img')
  16. img.src = '1@3x.png'
  17. el.append(img)
  18. const ratio = (maxAngle - minAngle) / (max - min)
  19. const value2Deg = () => ratio * (value - min) + minAngle
  20. const changeValue = (delta, fireEvent=false) => {
  21. let newValue = value +delta
  22. if (newValue >= max) newValue = max
  23. if (newValue <= min) newValue = min
  24. value = newValue
  25. //console.log(value)
  26. if (fireEvent && this.onChange && typeof this.onChange === 'function'){
  27. this.onChange(value)
  28. }
  29. img.style.transform = `rotate(${value2Deg()}deg)`;
  30. }
  31. const {top, left} = img.getBoundingClientRect()
  32. changeValue(0)
  33. console.log(img.width, top, left)
  34. img.onclick = e => {
  35. changeValue(e.clientX - left > img.width/2 ? step : -step, true)
  36. }
  37. img.onmousewheel = e => {
  38. changeValue(e.deltaY * step, true)
  39. e.preventDefault()
  40. }
  41. let startDragAngle;
  42. const calcAngle = ({layerX, layerY}) => {
  43. const deltaX = layerX - img.width/2
  44. const deltaY = layerY - img.height/2
  45. return (Math.atan2(deltaY, deltaX)/ Math.PI) * 180
  46. }
  47. img.onmousedown = e => {
  48. startDragAngle = calcAngle(e)
  49. e.preventDefault()
  50. }
  51. img.onmousemove = e => {
  52. if (startDragAngle !== undefined){
  53. const currentAngle = calcAngle(e)
  54. const deltaAngle = currentAngle - startDragAngle
  55. changeValue(deltaAngle/ratio, true)
  56. startDragAngle = currentAngle
  57. e.preventDefault()
  58. }
  59. }
  60. img.onmouseup = img.onmouseout = e => {
  61. if (startDragAngle){
  62. startDragAngle = undefined
  63. e.preventDefault()
  64. }
  65. }
  66. this.setValue = v => changeValue(v - value)
  67. this.changeValue = changeValue
  68. this.getValue = () => value
  69. }
  70. function rgbConst(parent){
  71. this.container = document.createElement("div");
  72. this.container.style = "display: flex;";
  73. parent.appendChild(container);
  74. this.fullColor = document.createElement("div");
  75. this.fullColor.setAttribute("style","background-color: rgb(64, 64, 64); width: 150px; height: 150px; margin: 5px");
  76. container.appendChild(this.fullColor);
  77. this.r = new Control(container, {max:255, value: 64});
  78. this.r.onChange = () => this.changeColor()
  79. this.g = new Control(container, {max:255, value: 64});
  80. this.g.onChange = () => this.changeColor()
  81. this.b = new Control(container, {max:255, value: 64});
  82. this.b.onChange = () => this.changeColor()
  83. this.rgbImg = document.getElementsByTagName("img");
  84. for(let i = 0; i < this.rgbImg.length; i++) {
  85. let colors = ["red", "green", "blue"];
  86. this.rgbImg[i].style = `width: 130px; padding: 10px; background-color: ${colors[i]}; border-radius: 50%; margin: 5px; transform: rotate(90deg)`;
  87. }
  88. this.changeColor = function() {
  89. let value1 = this.r.getValue();
  90. let value2 = this.g.getValue();
  91. let value3 = this.b.getValue();
  92. this.fullColor.setAttribute("style",`background-color: rgb(${value1}, ${value2}, ${value3}); width: 150px; height: 150px`);
  93. }
  94. this.changeColor()
  95. }
  96. function Audio(parent) {
  97. this.audioContainer = document.createElement("div");
  98. this.audioContainer.id = "volumeControl"
  99. parent.appendChild(audioContainer)
  100. this.audio = document.createElement("audio");
  101. this.audio.setAttribute("src", "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-16.mp3")
  102. this.audio.setAttribute("controls", "controls")
  103. this.audio.style = "margin: 20px"
  104. this.audioContainer.appendChild(audio);
  105. this.audioVolume = new Control(audioContainer, {value: 1, max: 1, min: 0, step: 0.00000001});
  106. this.audioVolume.onChange = () => this.changeVolume(this.audioVolume.getValue())
  107. this.volumeControl = document.getElementById("volumeControl");
  108. this.img = volumeControl.getElementsByTagName("img");
  109. this.img[0].style = "width: 100px"
  110. this.valueDirection = document.createElement("span");
  111. this.valueDirection.innerText = `100`
  112. this.audioContainer.appendChild(this.valueDirection)
  113. this.changeVolume = function(value) {
  114. this.audio.volume = `${value}`;
  115. this.valueDirection.innerText = `${[Math.round(this.audioVolume.getValue() * 100)]}`
  116. }
  117. }
  118. rgbConst(document.body)
  119. Audio(document.body)
  120. // const volumeControl = new Control(container1, {value: 50})
  121. // volumeControl.onChange = (value) => console.log('VOLUME', value)
  122. // const balanceControl = new Control(container2, {maxAngle: 90, minAngle: 0, min: -50, max: 50, value: 25})
  123. /*
  124. function registerForm(el){
  125. return new Promise((resolve, reject) => {
  126. const loginInput = document.createElement('input')
  127. const passwordInput = document.createElement('input')
  128. const cancelButton = document.createElement('button')
  129. const okButton = document.createElement('button')
  130. el.append(loginInput)
  131. el.append(passwordInput)
  132. el.append(cancelButton)
  133. okButton.innerText = 'ok'
  134. el.append(okButton)
  135. cancelButton.innerText = 'ne ok'
  136. function clear(){
  137. loginInput.remove()
  138. passwordInput.remove()
  139. okButton.remove()
  140. cancelButton.remove()
  141. }
  142. okButton.onclick = () => {
  143. clear()
  144. resolve({login: loginInput.value, password: passwordInput.value});
  145. }
  146. cancelButton.onclick = () => {
  147. clear();
  148. reject(new Error('cancel'))
  149. }
  150. })
  151. }
  152. async function RegAndLog(){
  153. try{
  154. title.innerText = 'Register Please'
  155. let regLogin, regPassword, a, b;
  156. while(!regLogin || !regPassword)
  157. {
  158. [{login:regLogin, password: regPassword}]= [await registerForm(container)]
  159. }
  160. // await ServerRegister({regLogin, regPassword})
  161. title.innerText = 'Login Please'
  162. const {login, password} = await registerForm(container)
  163. console.log(login, password, regLogin, regPassword)
  164. // await ServerLogin({login, password})
  165. if (regLogin === login && regPassword === password){
  166. title.innerText = 'Регистрация и Логин прошли ЗБС'
  167. }
  168. else {
  169. title.innerText = 'Регистрация и Логин не прошли'
  170. }
  171. }
  172. catch(e){
  173. title.innerText = 'якийс негаразд: ' + e.message
  174. }
  175. }
  176. RegAndLog()
  177. let a=5,b=10;
  178. [{a,b}] = [{b,a}]
  179. console.log(a, b) */
  180. </script>
  181. </body>
  182. </html>