Vue
by HLuB0AFLy0
HTML
<div id="app">
<h2>TCO19 MM R1 : LineUp</h2>
<button v-on:click="init()">init</button>
<button v-on:click="SA()">SA</button>
<p>
type(0:random,1:near,2:multi line):<input v-model="type" style="width:30px">
</p>
<p>
delay:<input v-model="delay" style="width:30px">ms
</p>
<p>
iterations(0 -> <input v-model="maxIterations" style="width:50px">):{{ iterations }}
</p>
<p>
temperature(<input v-model="startTemperature" style="width:30px"> -> 0):{{ temperature }}
</p>
<p>
score:{{ score }}
</p>
<p>
lineup:
</p>
<p v-for="(line, h) in lineup" v-bind:key="h">
<transition-group name="flip-list" tag="div" class="container">
<span v-for="(item, w) in line" v-bind:key="item" class="list-complete-item cell" :style="'color:rgb(' + (Math.abs(heights[lineup[h][w]] - arrangements[h][w])/maxHeight*255) + ',0,' + ((1.0-Math.abs(heights[lineup[h][w]] - arrangements[h][w])/maxHeight)*255) + ')'">
{{ item }}
</span>
</transition-group>
</p>
<!--
<p>
diff height:
</p>
<p v-for="(line, h) in lineup" v-bind:key="h">
<transition-group name="flip-list" tag="div" class="container">
<span v-for="(item, w) in line" v-bind:key="item" :class="'list-complete-item ' + 'transition: all ' + (0.01*delay) + 's;' ">
{{ Math.abs(heights[lineup[h][w]] - arrangements[h][w]) }}
</span>
</transition-group>
</p>
<p>
diff dist:
</p>
<p v-for="(line, h) in lineup" v-bind:key="h">
<transition-group name="flip-list" tag="div" class="container">
<span v-for="(item, w) in line" v-bind:key="item" class="list-complete-item">
{{ Math.abs(prevW(h,lineup[h][w]) - w) }}
</span>
</transition-group>
</p>
<p>
H:{{ H }}
</p>
<p>
W:{{ W }}
</p>
<p>
arrangements:
</p>
<p>
{{ arrangements }}
</p>
<p>
heights:
</p>
<p>
{{ heights }}
</p>
-->
</div>
CSS
.list-complete-item {
transition: all 1s;
display: inline-block;
margin-right: 10px;
}
.container {
display: flex;
flex-wrap: wrap;
width: 100%;
margin-top: 10px;
}
.cell {
display: flex;
justify-content: space-around;
align-items: center;
width: 25px;
height: 25px;
border: 1px solid #aaa;
margin-right: -1px;
margin-bottom: -1px;
}
Vue
new Vue({
el: "#app",
data(){return {
type:'0',
delay:1000,
score:0,
iterations:0,
maxIterations:100,
temperature:0,
startTemperature:10,
H:0,
W:0,
maxHeight:0,
heights:[],
lineup:[],
arrangements:[]
}
},
methods: {
init: function(){
this.W = Math.floor(Math.random()*91) + 10;
this.H = Math.floor(Math.random()*19) + 2;
this.W = 30;
this.H = 10;
this.maxHeight = Math.floor(Math.random()*991) + 10;
this.heights = [];
for (let w = 0; w < this.W; w++) {
this.heights.push(Math.floor(Math.random()*this.maxHeight) + 1);
}
this.arrangements = [];
for (let h = 0; h < this.H; h++) {
const arr = [];
for (let w = 0; w < this.W; w++) {
arr.push(Math.floor(Math.random()*this.maxHeight) + 1);
}
this.arrangements.push(arr);
}
this.lineup = [];
for (let h = 0; h < this.H; h++) {
const arr = [];
for (let w = 0; w < this.W; w++) {
arr.push(w);
}
this.lineup.push(arr);
}
this.score = this.calculateScore();
this.iterations = 0;
this.temperature = Number.parseFloat(this.startTemperature);
},
SA: async function(){
this.iterations = 0;
this.temperature = Number.parseFloat(this.startTemperature);
for(;this.iterations<this.maxIterations;this.iterations++){
this.temperature = Number.parseFloat(this.startTemperature) + (0 - Number.parseFloat(this.startTemperature))*(this.iterations - 0)/(this.maxIterations - 0 + 1e-9);
if (this.type==='0'?this.change():this.type==='1'?this.changeNear():this.changeMulti()){
await this.sleep(this.delay);
}
}
},
change: function(){
const h = Math.floor(this.H * Math.random());
const w =...