Dodanie ruchu po koniczynie
This commit is contained in:
1 parent
ba10d195ce
commit
28a5cd7c0d
2 files changed
+77
No files matched your search
@@ -6,13 +6,90 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Lekcja 3</title>
|
<title>Lekcja 3</title>
|
||||||
<style>
|
<style>
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
textarea {
|
textarea {
|
||||||
resize: none;
|
resize: none;
|
||||||
}
|
}
|
||||||
|
.widok {
|
||||||
|
width: 440px;
|
||||||
|
height: 440px;
|
||||||
|
position: relative;
|
||||||
|
border: 1px solid black;
|
||||||
|
}
|
||||||
|
.wskaznik {
|
||||||
|
position: absolute;
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
background-color: orange;
|
||||||
|
border: 3px solid black;
|
||||||
|
border-radius: 100%;
|
||||||
|
|
||||||
|
top: 100px;
|
||||||
|
left: 100px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<h2>4</h2>
|
||||||
|
<div class="widok">
|
||||||
|
<div class="wskaznik"></div>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
const wskaznik = document.getElementsByClassName("wskaznik")[0];
|
||||||
|
let y = parseInt(wskaznik.style.top)
|
||||||
|
let x = parseInt(wskaznik.style.left)
|
||||||
|
|
||||||
|
let tryb = 0
|
||||||
|
let licznik_goradol = 100
|
||||||
|
let licznik_lewoprawo = 150
|
||||||
|
|
||||||
|
setInterval(function() {
|
||||||
|
let rad = 0
|
||||||
|
let offset_x = 0
|
||||||
|
let offset_y = 0
|
||||||
|
switch(tryb) {
|
||||||
|
case 0:
|
||||||
|
offset_x = 100
|
||||||
|
offset_y = 0
|
||||||
|
licznik_goradol++
|
||||||
|
rad = licznik_goradol * (Math.PI/100)
|
||||||
|
if (licznik_goradol % 100 == 0) { tryb++ }
|
||||||
|
break
|
||||||
|
case 1:
|
||||||
|
offset_x = 200
|
||||||
|
offset_y = 100
|
||||||
|
licznik_lewoprawo++
|
||||||
|
rad = licznik_lewoprawo * (Math.PI/100)
|
||||||
|
if (licznik_lewoprawo % 100 == 50) { tryb++ }
|
||||||
|
break
|
||||||
|
case 2:
|
||||||
|
offset_x = 100
|
||||||
|
offset_y = 200
|
||||||
|
licznik_goradol++
|
||||||
|
rad = licznik_goradol * (Math.PI/100)
|
||||||
|
if (licznik_goradol % 100 == 0) { tryb++ }
|
||||||
|
break
|
||||||
|
case 3:
|
||||||
|
offset_x = 0
|
||||||
|
offset_y = 100
|
||||||
|
licznik_lewoprawo++
|
||||||
|
rad = licznik_lewoprawo * (Math.PI/100)
|
||||||
|
if (licznik_lewoprawo % 100 == 50) { tryb = 0 }
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
y = (Math.sin(rad) + 1) * 100 + offset_y
|
||||||
|
x = (Math.cos(rad) + 1) * 100 + offset_x
|
||||||
|
|
||||||
|
wskaznik.style.top = `${y}px`
|
||||||
|
wskaznik.style.left = `${x}px`
|
||||||
|
}, 25)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<hr>
|
||||||
<h2>2</h2>
|
<h2>2</h2>
|
||||||
<input style="font-family: monospace;" type="text" name="whata" id="frika" size="42">
|
<input style="font-family: monospace;" type="text" name="whata" id="frika" size="42">
|
||||||
<script>
|
<script>
|
||||||
|
|||||||
Reference in new issue
Block a user