Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ルールの可視化 #114

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/drawer.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/drawer_change_parameter.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/drawer_gallery.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/drawer_mortal.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/drawer_symmetry.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/simulations/drawer/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class Model {
const padding = 100
const position = (): Vector => {
if (fixedStartPoint && rules.length === 1) {
return this.fieldSize.div(2)
return new Vector(this.fieldSize.x / 2, (this.fieldSize.y / 2) + 40)
}
return new Vector(random(this.fieldSize.x - padding, padding), random(this.fieldSize.y - padding, padding))
}
Expand Down
39 changes: 34 additions & 5 deletions src/simulations/drawer_change_parameter/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ const saveInterval = 300 // ms
let t = 0
let n = 0
const canvasId = "canvas"
const fieldSize = constants.system.fieldSize
const fieldSize = new Vector(constants.system.fieldSize, constants.system.fieldSize * 9 / 16)
const flexibleRule = createRule()
let currentModel = createModel()

export const canvasWidth = fieldSize
export const canvasWidth = fieldSize.x

export const main = (p: p5): void => {
p.setup = () => {
const canvas = p.createCanvas(fieldSize, fieldSize)
const canvas = p.createCanvas(fieldSize.x, fieldSize.y)
canvas.id(canvasId)
canvas.parent(defaultCanvasParentId)

Expand All @@ -50,6 +50,35 @@ export const main = (p: p5): void => {
}
currentModel.draw(p, constants.draw.showsQuadtree)

const rule = currentModel.lSystemRules[0]
if (rule != null) {
const textSize = 16
const margin = 32

const floored = rule.encoded.split(";").map(transition => {
const transitionComponents = transition.split(":")
const components = transitionComponents[1].split(",").map(c => {
const i = parseFloat(c)
if (isNaN(i)) {
return c
}
return i > 0 ? `${Math.floor(i)}` : `${Math.ceil(i)}`
})
return `${transitionComponents[0]}:${components.join(",")}`
}).join(";")

const text = floored
.replace(/,/g, "")
.replace(/:/g, "→")
.replace(/;/g, ", ")

p.fill(0xFF, 0xC0)
p.textStyle(p.NORMAL)
p.textAlign(p.RIGHT)
p.textSize(textSize)
p.text(text, fieldSize.x - margin, margin)
}

if (currentModel.result != null) {
console.log(`${n}: ${currentModel.lSystemRules[0].encoded}`)
if (constants.system.autoDownload) {
Expand Down Expand Up @@ -110,7 +139,7 @@ function createModel(): Model | null {
const modelOf = (colorTheme: string): Model => {
if (colorTheme === "transition") {
return new TransitionColoredModel(
new Vector(fieldSize, fieldSize),
fieldSize,
constants.simulation.maxLineCount,
rules,
constants.simulation.mutationRate,
Expand All @@ -121,7 +150,7 @@ function createModel(): Model | null {
)
} else {
return new ImmortalModel(
new Vector(fieldSize, fieldSize),
fieldSize,
constants.simulation.maxLineCount,
rules,
constants.simulation.mutationRate,
Expand Down