在处理中创建随机像素线
我正在尝试制作一款游戏,但我陷入了随机关卡设计。基本上,我试图创建一条从一个边缘/角到另一个边缘/角的线,同时具有一定的随机性。
有关示例,请参见下图 1 [链接已损坏] 和 2。我正在 processing 中执行此操作,并且我尝试的每一次尝试都没有产生正确的结果。我可以让它们随机填充,但不能排成一行或从一边到另一边。顺便说一句,我正在尝试在 16 x 16 网格上执行此操作。任何想法或帮助将不胜感激,谢谢!
图片2:
I'm trying to make a game and I'm stuck on random level design. Basically, I'm trying to create a line from one edge/corner to another edge/corner while having some randomness to it.
See below image 1 [link broken] and 2 for examples. I'm doing this in processing and every attempt I've tried hasn't yielded proper results. I can get them to populate randomly but not in a line or from edge to edge. I'm trying to do this on a 16 x 16 grid by the way. Any ideas or help would be greatly appreciated thanks!
Image 2:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的描述,挑战在于从上到下有一条连接线,并且具有一点随机性驱动左/右方向。
有多种选择。
我想到的一个基本想法是:
这是一个使用
PImage 说明这一点的基本草图
来可视化数据:上面的逻辑非常简单,但可以随意用其他选项替换
random(3)
(也许 扔骰子来确定方向或探索其他伪随机数生成器 (PRNG),例如randomGaussian()
、noise()
(以及相关函数)等)这是上述内容的 p5.js 版本:
在这两个示例中,数据都是结构化的一维数组,但是,如果它更容易,它也可以很容易地成为二维数组。在这个开发阶段,最简单、最具可读性的选项就是最佳选择。
Based on your description, the challenge is in having a connected line from top to bottom with a bit of randomness driving left/right direction.
There are multiple options.
Here's a basic idea that comes to mind:
Here's a basic sketch that illustrates this using
PImage
to visualise the data:The logic is be pretty plain above, but free to replace
random(3)
with other options (perhaps throwing dice to determine direction or exploring other psuedo-random number generators (PRNGs) such asrandomGaussian()
,noise()
(and related functions), etc.)Here's a p5.js version of the above:
The data is a structured a 1D array in both examples, however, if it makes it easier it could easily be a 2D array. At this stage of development, whatever is the simplest, most readable option is the way to go.