|
1 | 1 | <script lang="ts">
|
2 | 2 | import { twMerge } from 'tailwind-merge';
|
3 | 3 | import { store, tickFrame } from '../game';
|
| 4 | + import PropertyEditor from './PropertyEditor.svelte'; |
4 | 5 | import ChevronDoubleDown from './icons/ChevronDoubleDown.svelte';
|
5 | 6 |
|
6 | 7 | let controlsDiv: HTMLDivElement | undefined;
|
7 | 8 | let showControls = false;
|
8 | 9 |
|
9 |
| - function insertNoise() { |
10 |
| - const canvas = document.getElementById('canvas')! as HTMLCanvasElement; |
11 |
| - const ctx = canvas.getContext('2d')!; |
12 |
| - const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height); |
13 |
| -
|
14 |
| - const colours = [ |
15 |
| - [255, 0, 0, 0], |
16 |
| - [0, 255, 0], |
17 |
| - [0, 0, 255], |
18 |
| - ]; |
19 |
| -
|
20 |
| - for (let i = 0; i < imageData.data.length; i += 4) { |
21 |
| - if (imageData.data[i + 3]) { |
22 |
| - continue; |
23 |
| - } |
24 |
| -
|
25 |
| - const y = Math.floor(i / (canvas.width * 4)); |
26 |
| -
|
27 |
| - // const [r, g, b] = colours[Math.floor(Math.random() * colours.length)]; |
28 |
| - const [r, g, b] = colours[y % colours.length]; |
29 |
| -
|
30 |
| - imageData.data[i] = r; |
31 |
| - imageData.data[i + 1] = g; |
32 |
| - imageData.data[i + 2] = b; |
33 |
| - imageData.data[i + 3] = 255; |
34 |
| - } |
35 |
| -
|
36 |
| - ctx.putImageData(imageData, 0, 0); |
37 |
| - } |
38 |
| -
|
39 | 10 | function clearCanvas() {
|
40 | 11 | const canvas = document.getElementById('canvas')! as HTMLCanvasElement;
|
41 | 12 | const ctx = canvas.getContext('2d')!;
|
|
62 | 33 | bind:value={$store.brushSize}
|
63 | 34 | />
|
64 | 35 | </label>
|
65 |
| - <label class="flex flex-row items-center justify-between"> |
66 |
| - Brush colour: |
67 |
| - <input |
68 |
| - class="rounded-md bg-zinc-800 p-2 outline-none ring-teal-600 transition-all focus:ring-2" |
69 |
| - type="text" |
70 |
| - size="8" |
71 |
| - bind:value={$store.brushColour} |
72 |
| - /> |
73 |
| - </label> |
74 |
| - <button class="rounded-md bg-teal-600 p-2 transition-colors hover:bg-teal-700" on:click={insertNoise}> |
75 |
| - Insert noise |
76 |
| - </button> |
77 | 36 | <button class="rounded-md bg-teal-600 p-2 transition-colors hover:bg-teal-700" on:click={clearCanvas}>
|
78 | 37 | Clear canvas
|
79 | 38 | </button>
|
|
88 | 47 | <button class="rounded-md bg-teal-600 p-2 transition-colors hover:bg-teal-700" on:click={tickFrame}>
|
89 | 48 | Tick frame
|
90 | 49 | </button>
|
| 50 | + <PropertyEditor /> |
91 | 51 | </div>
|
92 | 52 |
|
93 | 53 | {#if controlsDiv}
|
|
0 commit comments