add compress and reset for segments

main
Benjamin Kraft 1 year ago
parent 9c4d93af7a
commit 9bbcbe9e83
  1. 1
      public/data/images/compress.svg
  2. 26
      public/data/scripts/ts/manager.ts
  3. 18
      public/index.html
  4. 35
      public/styles.css

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M180.001-424.617v-59.999h599.998v59.999H180.001Zm0-115.384V-600h599.998v59.999H180.001Zm270 440v-146.463l-74.001 74-42.153-42.152L480-360.769l146.153 146.153L584-172.464l-74.001-72.77v145.233h-59.998ZM480-663.848 333.847-810.001 376-852.154l74.001 74.001v-146.463h59.998v146.463L584-852.154l42.153 42.153L480-663.848Z"/></svg>

After

Width:  |  Height:  |  Size: 423 B

@ -7,6 +7,8 @@ class Manager {
playing = false; playing = false;
static Size = 20;
constructor() { constructor() {
p.colorMode(p.HSB, 100); p.colorMode(p.HSB, 100);
let count = 100; let count = 100;
@ -54,6 +56,7 @@ class Manager {
data(){ data(){
return { return {
segmentCount: 1, segmentCount: 1,
maxSegmentCount: 30,
masses: [], masses: [],
lengths: [], lengths: [],
startAngle: 90, startAngle: 90,
@ -70,12 +73,27 @@ class Manager {
add() { add() {
}, },
resetMasses(){
for (let i = 0; i < this.maxSegmentCount; i++)
this.masses[i] = 1;
},
resetLengths() {
for (let i = 0; i < this.maxSegmentCount; i++)
this.lengths[i] = 1;
},
normalize(){
let L: [number] = this.lengths;
let sum = L.slice(0, this.segmentCount).reduce((p, n) => p + n);
let maxLength = Manager.Size / 2;
let factor = maxLength / sum;
for (let i = 0; i < this.segmentCount; i++)
this.lengths[i] *= factor;
}
}, },
mounted() { mounted() {
for (let i = 0; i < 20; i++){ this.resetMasses();
this.masses.push(1); this.resetLengths();
this.lengths.push(1);
}
}, },
name: "Preparation" name: "Preparation"
}).mount("#preparation"); }).mount("#preparation");

@ -19,7 +19,7 @@
<legend>Preparation</legend> <legend>Preparation</legend>
<label> <label>
Segments: {{ segmentCount }} Segments: {{ segmentCount }}
<input type="range" v-model.number="segmentCount" min="1" max="20" step="1"> <input type="range" v-model.number="segmentCount" min="1" max="30" step="1">
</label> </label>
<div id="segment_view"> <div id="segment_view">
<span id="segment_header_mass">Mass</span><span id="segment_header_length">Length</span> <span id="segment_header_mass">Mass</span><span id="segment_header_length">Length</span>
@ -28,9 +28,14 @@
<span class="segment_label">{{ masses[i - 1] }}kg</span> <span class="segment_label">{{ masses[i - 1] }}kg</span>
<input type="range" v-model.number="masses[i - 1]" min="0.1" max="10" step=".1"> <input type="range" v-model.number="masses[i - 1]" min="0.1" max="10" step=".1">
<span class="segment_label">{{ lengths[i - 1] }}m</span> <span class="segment_label">{{ lengths[i - 1] }}m</span>
<input type="range" v-model.number="lengths[i - 1]" min="0.1" max="5" step=".1"> <input type="range" v-model.number="lengths[i - 1]" min="0.1" max="10" step=".1">
</template> </template>
</div> </div>
<div class="horizontal_group">
<button class="reset_segments_btn" @click="resetMasses" title="Reset masses to 1"></button>
<button id="normalize_btn" @click="normalize" title="Normalize lengths to fit screen"></button>
<button class="reset_segments_btn" @click="resetLengths" title="Reset lengths to 1"></button>
</div>
<label> <label>
Starting Angle: {{startAngle}}° Starting Angle: {{startAngle}}°
<input type="range" v-model.number="startAngle" min="0" max="360" step="1"> <input type="range" v-model.number="startAngle" min="0" max="360" step="1">
@ -39,39 +44,32 @@
Color: Color:
<input type="color" v-model="color"> <input type="color" v-model="color">
</label> </label>
<br>
<label> <label>
<input type="checkbox" v-model="multiple"> <input type="checkbox" v-model="multiple">
Add multiple Add multiple
</label> </label>
<br>
<template v-if="multiple"> <template v-if="multiple">
<label> <label>
<input type="checkbox" v-model="rainbow"> <input type="checkbox" v-model="rainbow">
Use rainbow coloring Use rainbow coloring
</label> </label>
<br><br>
<label> <label>
Add Count: {{pendulumCount}} Count: {{pendulumCount}}
<input type="range" v-model.number="pendulumCount" min="10" max="250" step="10"> <input type="range" v-model.number="pendulumCount" min="10" max="250" step="10">
</label> </label>
<span>Property to change slightly:</span> <span>Property to change slightly:</span>
<br>
<label> <label>
<input type="radio" value="angle" v-model="changeProperty"> <input type="radio" value="angle" v-model="changeProperty">
Starting Angle Starting Angle
</label> </label>
<br>
<label> <label>
<input type="radio" value="mass" v-model="changeProperty"> <input type="radio" value="mass" v-model="changeProperty">
Specific Mass Specific Mass
</label> </label>
<br>
<label> <label>
<input type="radio" value="length" v-model="changeProperty"> <input type="radio" value="length" v-model="changeProperty">
Specific Length Specific Length
</label> </label>
<br><br>
<label v-show="changeProperty === 'mass' || changeProperty === 'length'"> <label v-show="changeProperty === 'mass' || changeProperty === 'length'">
Index: {{ changeIndex }} Index: {{ changeIndex }}
<input type="range" v-model.number="changeIndex" min="0" :max="segmentCount - 1" step="1"> <input type="range" v-model.number="changeIndex" min="0" :max="segmentCount - 1" step="1">

@ -75,14 +75,16 @@ body {
fieldset { fieldset {
border-radius: 5px; border-radius: 5px;
margin: 10px; margin: 10px;
display: flex;
flex-direction: column;
} }
fieldset > legend { fieldset > * {
font-size: 25px; margin: 5px 0;
} }
input { fieldset > legend {
margin: 5px; font-size: 25px;
} }
#preparation { #preparation {
@ -109,14 +111,14 @@ input {
} }
button { button {
margin-top: 10px;
width: 100%; width: 100%;
height: 50px; height: 40px;
border: 3px solid black; border: 3px solid black;
border-radius: 5px; border-radius: 5px;
background-size: contain; background-size: contain;
background-position: center; background-position: center;
background-repeat: no-repeat; background-repeat: no-repeat;
flex-shrink: 0;
} }
button:hover{ button:hover{
filter: brightness(80%); filter: brightness(80%);
@ -125,6 +127,27 @@ button:active {
filter: brightness(60%); filter: brightness(60%);
} }
.horizontal_group {
display: flex;
justify-content: space-between;
}
.horizontal_group > * {
width: 32%;
}
#normalize_btn {
background-image: url("data/images/compress.svg");
background-size: 50% 80%;
background-color: #cbcbcb;
border-color: #9a9a9a;
}
.reset_segments_btn {
background-image: url("data/images/refresh.svg");
background-color: #cbcbcb;
border-color: #9a9a9a;
}
#add_btn{ #add_btn{
border-color: #007a00; border-color: #007a00;
background-color: #d3ffd3; background-color: #d3ffd3;

Loading…
Cancel
Save