Closed jerpint closed 9 months ago
cubing.js
is meant to address those kinds of use cases.
Do you have a particular application in mind?
What you're describing can be done like this: https://codepen.io/lgarron/pen/oNezavJ?editors=0010
import { randomScrambleForEvent } from "cubing/scramble";
import { experimentalSolve3x3x3IgnoringCenters } from "cubing/search";
import { TwistyPlayer } from "cubing/twisty";
(async () => {
const player = document.body.appendChild(
new TwistyPlayer({
alg: await randomScrambleForEvent("333"),
}),
);
const state = await player.experimentalModel.currentTransformationProp.get();
const solution = await experimentalSolve3x3x3IgnoringCenters(state);
solution.log();
const currentAlg = (await player.experimentalModel.algProp.get()).alg;
player.timestamp = (
await player.experimentalModel.detailedTimelineInfoProp.get()
).timestamp;
player.alg = currentAlg.concat(solution);
})();
As you can see, a lot of the functionality is still experimental. But that's because we're trying to figure out exactly what apps need! Are you looking for particular functionality beyond what you asked for?
Hey, thanks, but what I would like is for the user to interact and move the cube dynamically, which I don't think can be done in the example you sent?
I would also like to somehow translate the state as the actual state of the cube as an array, e.g. for a NxN cube I would get a NxNx6 array with the color index at each point of the array
Hey, thanks, but what I would like is for the user to interact and move the cube dynamically, which I don't think can be done in the example you sent?
Ah, I see. That's definitely possible; we do it in Twizzle Explorer: https://alpha.twizzle.net/explore/?puzzle=3x3x3
But it'll be at least a few months until that becomes more convenient. (Unless you'd like to contribute canvas input code sooner. That would definitely be welcome!)
I would also like to somehow translate the state as the actual state of the cube as an array, e.g. for a NxN cube I would get a NxNx6 array with the color index at each point of the array
cubing.js
could definitely help with that!
You can see such a translation in action at https://experiments.cubing.net/cubing.js/3x3x3-formats/
If AnimCubeJS works for you then it might be worth sticking with it for now. But we do aim for cubing.js
to subsume all AnimCubeJS functionality, so I'd encourage considering it in the long term.
Hi jerpint,
although I can not solve your problem, at least I can point you to the right sources.
You can interact with the cube programatically for sure, check out the Interactive section (you could also find the Solving Demos section useful) at https://mfeather1.github.io/3ColorCube/idx.html by Michael Feather.
More examples have been recently added to the Enhancement section at https://cubing.github.io/AnimCubeJS/animcubejs.html#enhancement, read the "More advanced use of JavaScript [...]" paragraph.
Closing, because:
Hello!
I would like to use a cube on my page and interact with it programatically. The goal is to implement algorithms to solve the cube such that any user could scramble the cube and then my solver would solve it.
My question is:
1) how can I access the state of the cube at any given moment? 2) How can I move the cube using code?
My page currently looks like this:
I'd like to somehow access the state of the cube using something like
cube.state()
and then act on the state, for example some pseudo code:Any help is appreciated :)