如何在Processing中获取屏幕坐标
我正在使用处理来做一个项目。
我使用 draw
函数在素描板上画了一个草图(实际上是文本)。
我想获取文本每个单词的屏幕坐标来做一些其他有趣的事情。
我不知道我可以使用什么函数来检索、取回屏幕坐标。
任何人都可以帮忙解决这个问题吗?我会很感激你的帮助。
谢谢
I am using Processing to do a project.
I have a sketch (actually text) in the sketch board by using the draw
function.
I want to get the screen coordinates of each word of the text to do some other interesting things.
I do not know what function I can use to retrieve, get back the screen coordinates.
Can anybody help on this. I'll appreciate your help.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
希望我正确地理解了您的问题,下面的草图解释了如何实现解决方案。它的速度相当快,并且基本上依赖于手动单词定位。首先,我将整个文本分成单个单词;存储在
myWords
数组中。在绘制循环中,我使用两个变量 - xPos 和 yPos - 来表示在屏幕上移动的假想光标。 if 子句检查当前单词是否会跳出草图区域(包括填充):
如果是,则光标将跳到下一行的开头。
现在间距依赖于鼠标,行高是固定的;但也很容易是动态的。您可以使用
xPos
和yPos
变量来调整单词的位置。此外,xPosEnd
指示单词结束位置。正如我所说,这种方法速度相当快,也可以应用于角色级别。手动文本定位脚本
Hopefully I got your problem correctly and the following sketch explains how you can achieve a solution. Its pretty fast forward and basically relies on manual word positioning. First of all I split the whole text into single words; stored in the
myWords
array.Within the
draw
-loop I use two variables –xPos
andyPos
– to represent an imaginary cursor that moves over the screen. An if clause checks if the current word would jump out of the sketch area (including the padding):If so, the cursor will jump to the beginning of the next line.
Right now the spacing relies on the mouse and the line height is fixed; but could also easily be dynamic. You can use the
xPos
andyPos
variables to play around with the positions of the words. Furthermore doesxPosEnd
indicate the word end-position. As I said, this approach is pretty fast forward and can be also applied on a character level.Manual text positioning script
可能您正在寻找
screen
系统变量示例程序
如需更多参考,请参阅语言 API
编辑
你用什么方法来绘制文本?您将使用什么方法来制作文本动画?这取决于您用来查找坐标的方法。
如果您使用
text
方法,那么您提供的坐标为参数例如:
text(data, x, y)
如果您对文本进行动画处理以向右移动 5 个坐标,那么如果初始 x 坐标为 10,那么现在的 x 坐标将为 15。
May be you are looking for the
screen
System variableSample program
For more reference always refer the Language API
Edit
What method are you using to draw the text? What method will you be using for animating the text? It depends on the methods you use to find the coordinates.
If you used the
text
method then you provided the coordinates as parameterseg:
text(data, x, y)
If you animated the text to move 5 coordinates to the right then if the initial x coordinate was 10 then the x coordinate now will be 15.