Better code quality
This commit is contained in:
@ -72,7 +72,71 @@ const TEMPLATES: Template[] = [
|
||||
{ pattern: "((t*t)/(t^t>>S))&N", weight: 5 },
|
||||
{ pattern: "(t*(t>>S1))^(t*(t>>S2))", weight: 6 },
|
||||
{ pattern: "((t>>S1)*(t>>S2))&((t>>S3)|(t>>S4))", weight: 6 },
|
||||
{ pattern: "(t&(t>>S1))^((t>>S2)&(t>>S3))", weight: 5 }
|
||||
{ pattern: "(t&(t>>S1))^((t>>S2)&(t>>S3))", weight: 5 },
|
||||
|
||||
{ pattern: "t*(a&t>>b)", weight: 6 },
|
||||
{ pattern: "(t>>a)|(t>>b)", weight: 6 },
|
||||
{ pattern: "t&(t>>a)&(t>>c)", weight: 5 },
|
||||
{ pattern: "(t*a)&(t>>b)", weight: 5 },
|
||||
{ pattern: "t%(d)+(t>>a)", weight: 5 },
|
||||
{ pattern: "(t>>a)^(t>>c)", weight: 5 },
|
||||
{ pattern: "t*((t>>a)|(t>>b))&c", weight: 5 },
|
||||
{ pattern: "((t>>a)&b)*(t>>c)", weight: 5 },
|
||||
{ pattern: "(t&(t>>a))^(t>>d)", weight: 4 },
|
||||
{ pattern: "t/(b+(t>>a|t>>c))", weight: 4 },
|
||||
|
||||
{ pattern: "t&t>>a", weight: 7 },
|
||||
{ pattern: "t&t>>b", weight: 7 },
|
||||
{ pattern: "(t*a&t>>b)|(t*c&t>>d)", weight: 9 },
|
||||
{ pattern: "(t>>a)&(t>>b)", weight: 6 },
|
||||
{ pattern: "t*(a&t>>b)|(t>>c)", weight: 7 },
|
||||
{ pattern: "(t*a&t>>S1)|(t*b&t>>S2)", weight: 8 },
|
||||
{ pattern: "t&(t>>a)|(t>>b)", weight: 6 },
|
||||
{ pattern: "(t*c&t>>a)&(t>>b)", weight: 6 },
|
||||
{ pattern: "t*(t>>a&t>>b)", weight: 6 },
|
||||
{ pattern: "((t>>a)&N)|(t*b&t>>c)", weight: 7 },
|
||||
|
||||
{ pattern: "t&N?(t*a&t>>b):(t>>c)", weight: 7 },
|
||||
{ pattern: "(t>>a)&N?(t*b):(t*c)", weight: 7 },
|
||||
{ pattern: "t&M?(t>>a|t>>b):(t>>c&t>>d)", weight: 6 },
|
||||
{ pattern: "(t>>S)&N?(t*a):(t>>b)", weight: 6 },
|
||||
{ pattern: "t%(M)?(t>>a):(t*b&t>>c)", weight: 6 },
|
||||
{ pattern: "t&d?(t*a&t>>S):(t>>b)", weight: 6 },
|
||||
{ pattern: "(t>>a)&(t>>b)?(t*c):(t>>S)", weight: 5 },
|
||||
{ pattern: "t&M?(t>>a)^(t>>b):(t*c)", weight: 5 },
|
||||
|
||||
{ pattern: "t*a%(M)", weight: 6 },
|
||||
{ pattern: "(t*a)%(M1)+(t*b)%(M2)", weight: 7 },
|
||||
{ pattern: "t*a&(t>>b)%(M)", weight: 6 },
|
||||
{ pattern: "(t*c%(M))&(t>>a)", weight: 6 },
|
||||
{ pattern: "t*a+(t*b&t>>c)", weight: 6 },
|
||||
{ pattern: "(t*a&t>>S)+(t*b%(M))", weight: 7 },
|
||||
{ pattern: "t*b%(M)*(t>>a)", weight: 6 },
|
||||
{ pattern: "(t*a|t*b)&(t>>c)", weight: 6 },
|
||||
{ pattern: "t*c&((t>>a)|(t>>b))", weight: 6 },
|
||||
{ pattern: "(t*a%(M1))^(t*b%(M2))", weight: 6 },
|
||||
|
||||
{ pattern: "(t>>a)^(t>>b)^(t>>c)", weight: 6 },
|
||||
{ pattern: "t^(t>>a)^(t*b)", weight: 6 },
|
||||
{ pattern: "((t>>a)^(t>>b))&(t*c)", weight: 6 },
|
||||
{ pattern: "(t^t>>a)*(t^t>>b)", weight: 6 },
|
||||
{ pattern: "t^(t>>a)&(t>>b)&(t>>c)", weight: 5 },
|
||||
{ pattern: "((t>>a)^N)*((t>>b)^M)", weight: 6 },
|
||||
{ pattern: "(t*a)^(t>>b)^(t>>c)", weight: 6 },
|
||||
{ pattern: "t^(t*a>>b)^(t>>c)", weight: 5 },
|
||||
{ pattern: "((t^t>>a)&N)|(t>>b)", weight: 5 },
|
||||
{ pattern: "(t>>a)^(t*b&t>>c)", weight: 6 },
|
||||
|
||||
{ pattern: "((t>>a)&(t>>b))*((t>>c)|(t*d))", weight: 7 },
|
||||
{ pattern: "t*((t>>a|t>>b)&(t>>c|t*d))", weight: 7 },
|
||||
{ pattern: "(t&(t>>a))*(t%(M))", weight: 6 },
|
||||
{ pattern: "t/(D+(t>>a)&(t>>b))", weight: 5 },
|
||||
{ pattern: "((t*a)&(t>>b))^((t*c)%(M))", weight: 6 },
|
||||
{ pattern: "(t>>a|t*b)&((t>>c)^(t*d))", weight: 6 },
|
||||
{ pattern: "t*(t>>a)%(M1)+(t>>b)%(M2)", weight: 7 },
|
||||
{ pattern: "((t>>a)%(M))*((t*b)&(t>>c))", weight: 6 },
|
||||
{ pattern: "t&((t>>a)|(t*b))^(t>>c)", weight: 6 },
|
||||
{ pattern: "(t*a&N)|(t>>b&M)|(t*c)", weight: 7 }
|
||||
]
|
||||
|
||||
function randomElement<T>(arr: T[]): T {
|
||||
|
||||
20
src/utils/tileHelpers.ts
Normal file
20
src/utils/tileHelpers.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import type { TileState } from '../types/tiles'
|
||||
|
||||
export type FocusedTile = { row: number; col: number } | 'custom'
|
||||
|
||||
export function getTileId(row: number, col: number): string {
|
||||
return `${row}-${col}`
|
||||
}
|
||||
|
||||
export function isCustomTileFocused(focusedTile: FocusedTile): boolean {
|
||||
return focusedTile === 'custom'
|
||||
}
|
||||
|
||||
export function isTileFocused(focusedTile: FocusedTile, row: number, col: number): boolean {
|
||||
if (focusedTile === 'custom') return false
|
||||
return focusedTile.row === row && focusedTile.col === col
|
||||
}
|
||||
|
||||
export function getTileFromGrid(tiles: TileState[][], row: number, col: number): TileState | undefined {
|
||||
return tiles[row]?.[col]
|
||||
}
|
||||
@ -32,9 +32,12 @@ export function loadTileParams(tile: TileState): void {
|
||||
})
|
||||
}
|
||||
|
||||
export function saveTileParams(tile: TileState): void {
|
||||
tile.engineParams = { ...engineSettings.get() }
|
||||
tile.effectParams = { ...effectSettings.get() }
|
||||
export function saveTileParams(tile: TileState): TileState {
|
||||
return {
|
||||
...tile,
|
||||
engineParams: { ...engineSettings.get() },
|
||||
effectParams: { ...effectSettings.get() }
|
||||
}
|
||||
}
|
||||
|
||||
export function cloneTileState(tile: TileState): TileState {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
export function generateWaveformData(formula: string, width: number, sampleRate: number = 8000, duration: number = 0.5): number[] {
|
||||
export function generateWaveformData(formula: string, width: number, sampleRate: number = 8000, duration: number = 0.5, a: number = 8, b: number = 16, c: number = 32, d: number = 64): number[] {
|
||||
try {
|
||||
const compiledFormula = new Function('t', `return ${formula}`) as (t: number) => number
|
||||
const compiledFormula = new Function('t', 'a', 'b', 'c', 'd', `return ${formula}`) as (t: number, a: number, b: number, c: number, d: number) => number
|
||||
const samplesPerPixel = Math.floor((sampleRate * duration) / width)
|
||||
const waveform: number[] = []
|
||||
|
||||
@ -11,7 +11,7 @@ export function generateWaveformData(formula: string, width: number, sampleRate:
|
||||
for (let s = 0; s < samplesPerPixel; s++) {
|
||||
const t = x * samplesPerPixel + s
|
||||
try {
|
||||
const value = compiledFormula(t)
|
||||
const value = compiledFormula(t, a, b, c, d)
|
||||
const byteValue = value & 0xFF
|
||||
const normalized = (byteValue - 128) / 128
|
||||
min = Math.min(min, normalized)
|
||||
|
||||
Reference in New Issue
Block a user