Skip to content

Commit

Permalink
change the origin to the bottom left (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
hishiwat authored Sep 11, 2024
1 parent 9cdfebe commit 188769e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
34 changes: 19 additions & 15 deletions src/components/organisms/TurtleGraphics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { TurtleGraphicsController } from '../molecules/TurtleGraphicsController'

const CHARACTER_DIRS = ['N', 'E', 'S', 'W'];
const DX = [0, 1, 0, -1];
const DY = [-1, 0, 1, 0];
const DY = [1, 0, -1, 0];

const charToRotateStyle = {
N: 'rotate(180deg)',
Expand Down Expand Up @@ -254,28 +254,32 @@ export const TurtleGraphics = forwardRef<TurtleGraphicsHandle, TurtleGraphicsPro
templateColumns={`repeat(${GRID_COLUMNS}, ${GRID_SIZE}px)`}
templateRows={`repeat(${GRID_ROWS}, ${GRID_SIZE}px)`}
>
{board.map((columns, rowIndex) =>
columns.map((color, columnIndex) => (
<GridItem
key={columnIndex}
backgroundColor={charToColor[color]}
borderColor="black"
borderWidth={selectedCell?.x === columnIndex && selectedCell?.y === rowIndex ? '2px' : '0.5px'}
className="grid-cell"
onClick={() => handleClickCell(columnIndex, rowIndex)}
onContextMenu={(e) => handleContextMenu(e, columnIndex, rowIndex)}
/>
))
)}
{[...board]
.reverse()
.map((columns, rowIndex) =>
columns.map((color, columnIndex) => (
<GridItem
key={columnIndex}
backgroundColor={charToColor[color]}
borderColor="black"
borderWidth={
selectedCell?.x === columnIndex && selectedCell?.y === GRID_ROWS - rowIndex - 1 ? '2px' : '0.5px'
}
className="grid-cell"
onClick={() => handleClickCell(columnIndex, GRID_ROWS - rowIndex - 1)}
onContextMenu={(e) => handleContextMenu(e, columnIndex, GRID_ROWS - rowIndex - 1)}
/>
))
)}
{characters.map((character) => (
<Box
key={'character' + character.x + character.y}
borderColor={selectedCharacter?.color === character.color ? 'black' : 'transparent'}
borderWidth="2px"
bottom={character.y * GRID_SIZE + 'px'}
h={GRID_SIZE + 'px'}
left={character.x * GRID_SIZE + 'px'}
position="absolute"
top={character.y * GRID_SIZE + 'px'}
w={GRID_SIZE + 'px'}
onClick={() => handleClickCharacter(character)}
onContextMenu={(e) => handleContextMenu(e, character.x, character.y)}
Expand Down
2 changes: 1 addition & 1 deletion src/problems/traceProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Scope {
}
const dirs = ['N', 'E', 'S', 'W'];
const dx = [0, 1, 0, -1];
const dy = [-1, 0, 1, 0];
const dy = [1, 0, -1, 0];
const board = Array.from({ length: ${GRID_ROWS} }, () => Array.from({ length: ${GRID_COLUMNS} }, () => '${EMPTY_COLOR}'));
class Character {
constructor(x = ${Math.floor(GRID_COLUMNS / 2)}, y = ${Math.floor(GRID_ROWS / 2)}, color = '${DEFAULT_COLOR}') {
Expand Down

0 comments on commit 188769e

Please sign in to comment.