Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bortoz committed Feb 16, 2025
1 parent bd68374 commit d69587c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 55 deletions.
13 changes: 13 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
"style": {
"noNegationElse": "error",
"noNonNullAssertion": "off",
"useNamingConvention": {
"level": "error",
"options": {
"conventions": [
{
"selector": {
"kind": "objectLiteralMember"
},
"formats": ["camelCase", "PascalCase"]
}
]
}
},
"useFilenamingConvention": {
"level": "error",
"options": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { range } from "lodash-es";

import { Canvas, Rectangle, Sprite, Variables } from "~/utils/visualizer";

import bunny_left from "./asy/bunny_left.asy?w=66";
import bunny_right from "./asy/bunny_right.asy?w=66";
import bunnyLeft from "./asy/bunny_left.asy?w=66";
import bunnyRight from "./asy/bunny_right.asy?w=66";
import stairs1 from "./asy/stairs1.asy?w=80";
import stairs2 from "./asy/stairs2.asy?w=80";
import stairs3 from "./asy/stairs3.asy?w=80";

export default function Visualizer({ variables, state }) {
const stairs = [stairs1, stairs2, stairs3][state.M <= 6 ? 0 : state.M <= 14 ? 1 : 2];
const bunnies = [bunny_left, bunny_right];
const bunnies = [bunnyLeft, bunnyRight];
const hf = 2;
const wf = 3;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ export default function Visualizer({ variables, state }) {
return <Sprite key={nc++} src={carrot} alt="Carota" x={x} y={y} />;
})}
</Canvas>
<Variables variables={{ ...variables, "N (num. stanze)": state.N, "K (dim. pacco)": state.K, "euro spesi": state.cost }} />
<Variables
variables={{
...variables,
"N (num. stanze)": state.N,
"K (dim. pacco)": state.K,
"euro spesi": state.cost,
}}
/>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { Fragment } from "react";

import clsx from "clsx";
import { range } from "lodash-es";

import { Canvas, Rectangle, Sprite, Variables } from "~/utils/visualizer";
Expand All @@ -28,25 +29,24 @@ export default function Visualizer({ variables, state }) {
<Canvas gravity="bottom" scale={10}>
{range(state.N).map((i) => (
<Rectangle
key={"rect" + i}
key={`rect${i}`}
color={state.light[i] ? "#eee" : "#333"}
height={height}
width={width}
x={width * (i + 1)}
y={6}>
<div
style={{
color: state.light[i] ? "black" : "white",
textDecorationColor: state.light[i] ? "black" : "white",
}}
className="absolute mt-1 size-full origin-bottom text-center text-2xl text-slate-900 underline decoration-slate-900">
className={clsx(
"absolute mt-1 size-full origin-bottom text-center text-2xl underline",
state.light[i] ? "text-black" : "text-white",
)}>
{i + 1}
</div>
</Rectangle>
))}
{range(state.N).map((i) => (
<Sprite
key={"bulb" + i}
key={`bulb${i}`}
src={state.light[i] ? bulbOn : bulbOff}
alt=""
x={width * (i + 1.5) - 1.5}
Expand All @@ -55,7 +55,7 @@ export default function Visualizer({ variables, state }) {
))}
{range(state.N * 2).map((i) => (
<Sprite
key={"switch" + i}
key={`switch${i}`}
src={
i > 0 && state.light[Math.floor((i - 1) / 2)]
? state.switch[i]
Expand All @@ -71,7 +71,7 @@ export default function Visualizer({ variables, state }) {
/>
))}
{range(state.N).map((i) => (
<Fragment key={"door" + i}>
<Fragment key={`door${i}`}>
{state.door[i] ? (
<Sprite src={openedDoor} alt="Porta aperta" x={width * (i + 1) - 1.5} y={3} />
) : (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import clsx from "clsx";
import { range } from "lodash-es";
import { Canvas, Rectangle, Sprite, Variables } from "~/utils/visualizer";
import bunny from "./asy/bunny.asy?w=66";
Expand All @@ -16,70 +17,51 @@ class Random {
}

export default function Visualizer({ variables, state }) {
const cell_side = 20;
const cell_padding = 1;
const cellSide = 20;
const cellPadding = 1;
const scale = 10;
const font_height = 4;
const fontHeight = 4;

const random = new Random(state.N);
const colors = ["orange", "lightgreen", "blue", "aquamarine", "yellow", "red"];
const cell_color = range(state.N).map(() => colors[random.next() % colors.length]);
const cellColor = range(state.N).map(() => colors[random.next() % colors.length]);
return (
<>
<Canvas gravity="bottom" scale={scale}>
{range(state.N).map((i) => (
<Rectangle
color="transparent"
width={cell_side}
height={cell_side}
key={"rect" + i}
x={cell_side * i}
width={cellSide}
height={cellSide}
key={`rect${i}`}
x={cellSide * i}
y={2}>
<Rectangle
color={{ W: "white", B: cell_color[i] }[state.cols[i]]}
width={cell_side - 2 * cell_padding}
height={cell_side - 2 * cell_padding}
x={cell_padding}
y={cell_padding}
style={{
display: "flex",
alignItems: "center",
justifyContent: "center",
fontSize: 10 * scale,
}}>
color={{ W: "white", B: cellColor[i] }[state.cols[i]]}
width={cellSide - 2 * cellPadding}
height={cellSide - 2 * cellPadding}
x={cellPadding}
y={cellPadding}
className="flex items-center justify-center text-8xl">
{i + 1}
</Rectangle>
</Rectangle>
))}
<Sprite src={bunny} alt="Bunny" x={cell_side * (state.pos + 0.25) - 3.5} y={0} follow />
<Sprite src={bunny} alt="Bunny" x={cellSide * (state.pos + 0.25) - 3.5} y={0} follow />
<Rectangle
style={{
padding: "5px",
textAlign: "center",
borderRadius: "10px",
}}
x={Math.max(cell_side * state.pos, 40)}
y={-font_height * state.M - 2}
height={font_height * state.M + 2}
width={30}>
x={Math.max(cellSide * state.pos, 40)}
y={-fontHeight * state.M - 2}
height={fontHeight * state.M + 2}
width={30}
className="p-2 rounded-lg">
{range(state.M).map((i) => (
<Rectangle
<div
key={`instr-${i}`}
style={{
border: "None",
textAlign: "center",
fontSize: `${scale * font_height}px`,
lineHeight: `${scale * font_height}px`,
fontWeight: i === state.i ? "bold" : "normal",
fontFamily: "monospace",
}}
y={(-i + state.M - 1) * font_height + 1}
x={1}
width="100%">
className={clsx("border-0 text-4xl font-mono", i === state.i && "font-bold")}>
<pre>
{`${(state.M > 9) && (i + 1 < 10) ? " " : ""}${i + 1}. ${{ S: "SALTA", A: "AVANZA" }[state.instr[i]]}`}
</pre>
</Rectangle>
</div>
))}
</Rectangle>
</Canvas>
Expand Down

0 comments on commit d69587c

Please sign in to comment.