[+] Python range()
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* Same as python's range
|
||||||
|
*
|
||||||
|
* Ways of calling this function:
|
||||||
|
* range(to)
|
||||||
|
* range(from, to)
|
||||||
|
* range(from, to, step)
|
||||||
|
*
|
||||||
|
* @param fromOrTo Either from or to. From is inclusive
|
||||||
|
* @param to to, Not inclusive
|
||||||
|
* @param step Step
|
||||||
|
*/
|
||||||
|
export function range(fromOrTo: number, to?: number, step = 1): number[]
|
||||||
|
{
|
||||||
|
const from = to ? fromOrTo : 0
|
||||||
|
to = to ? to : fromOrTo
|
||||||
|
|
||||||
|
return [...Array(Math.floor((to - from) / step))].map((_, i) => from + i * step);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(range(3))
|
||||||
|
console.log(range(2, 5))
|
||||||
@@ -20,6 +20,7 @@ import {Options, Vue} from 'vue-class-component';
|
|||||||
import "vue3-colorpicker/style.css";
|
import "vue3-colorpicker/style.css";
|
||||||
import {ColorPicker} from "vue3-colorpicker";
|
import {ColorPicker} from "vue3-colorpicker";
|
||||||
import {Color} from "three";
|
import {Color} from "three";
|
||||||
|
import {range} from "@/utils";
|
||||||
|
|
||||||
@Options({components: {ColorPicker}})
|
@Options({components: {ColorPicker}})
|
||||||
export default class MyColorPicker extends Vue
|
export default class MyColorPicker extends Vue
|
||||||
@@ -30,10 +31,7 @@ export default class MyColorPicker extends Vue
|
|||||||
|
|
||||||
mounted(): void
|
mounted(): void
|
||||||
{
|
{
|
||||||
this.palette.push(['', '', '', '', '', '', '', '', '', ''])
|
this.palette = range(3).map(_ => range(10).map(_ => ''))
|
||||||
this.palette.push(['', '', '', '', '', '', '', '', '', ''])
|
|
||||||
this.palette.push(['', '', '', '', '', '', '', '', '', ''])
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
change(color: string): void
|
change(color: string): void
|
||||||
|
|||||||
Reference in New Issue
Block a user