diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..511e89b --- /dev/null +++ b/src/utils.ts @@ -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)) diff --git a/src/views/color/ColorPicker.vue b/src/views/color/ColorPicker.vue index c2a1854..86d05fa 100644 --- a/src/views/color/ColorPicker.vue +++ b/src/views/color/ColorPicker.vue @@ -20,6 +20,7 @@ import {Options, Vue} from 'vue-class-component'; import "vue3-colorpicker/style.css"; import {ColorPicker} from "vue3-colorpicker"; import {Color} from "three"; +import {range} from "@/utils"; @Options({components: {ColorPicker}}) export default class MyColorPicker extends Vue @@ -30,10 +31,7 @@ export default class MyColorPicker extends Vue mounted(): void { - this.palette.push(['', '', '', '', '', '', '', '', '', '']) - this.palette.push(['', '', '', '', '', '', '', '', '', '']) - this.palette.push(['', '', '', '', '', '', '', '', '', '']) - return + this.palette = range(3).map(_ => range(10).map(_ => '')) } change(color: string): void