Dosen原创
这是我学习quartz composer,Origami,看官方文档翻译下来的,每天一篇,有不准确的地方希望能指出,一起交流进步。转载请与我联系,擅自转载视作侵权。
States & Pulses 状态&脉冲
States help remember information in your prototype. Pulses are used to tell patches to perform an action. Understanding how these work together will help you be more effective at building Origami prototypes.
状态帮你记录原型的信息。脉冲用来告诉原型执行一个动作。理解他们如何配合使用会帮你在建立Origami原型时提高效率。
States 状态
A state is a value that persists over time. The simplest version of state is in the Switch patch. Switches are either on or off, and they remain that way until you tell them otherwise.
一个状态就是一个值持续一段时间。最简单的状态版本就是Switch模块。Switches也是开或关,并且如果你不告诉它们,它们会保持这种状态。
If we look at a state as it changes over time, it might look something like this:
如果我们看到一个状态改变并持续,它看起来或许像这样:
A switch is off until you turn it on. You can see the state goes from off to on immediately in a single frame. A frame is usually 1/60th of a second.
一个switch是关的,直到你将它打开。你可以看到状态是是立即在一帧从关进入开。一帧通常是一秒的1/60。
Pulses 脉冲
While state persists over time, pulses are On ✓ only for a single frame. The value of the cable sending the pulse is otherwise off.
在状态持续的过程中,脉冲只开了一帧。连线传递给脉冲的其他值是关。
A pulse over time looks like this:
脉冲持续的这段时间看起来像是:
You can see that pulses are only On ✓ for a single frame.
你可以看到脉冲只有一帧是开的。
They're used to tell patches to perform an action, like telling a Switch to turn on or turn off. They're also useful for passing along user interactions like tapping on the screen or pressing a key on the keyboard.
它们经常用来告诉模块去执行一个动作,就像告诉一个开关是打开或关闭。它们经常对于沿着用户的交互,像点击屏幕或按一个键盘上的键是很有用的。
Examples of State & Pulses 状态&脉冲的案例
The Switch patch outputs the state of the switch (on / off) and accepts pulses to flip the switch, turn it on, or turn it off.
Switch模块输出开/关的状态,并且允许脉冲转换开关,把它打开,或把它关闭。
The Interaction 2 patch has Down and Up outputs. Down represents the state of whether the finger is currently down on the screen. The Up port outputs a pulse when the finger is released from the screen.
Interaction 2模块有下和上两个输出。Down代表手指当前在屏幕是按下的状态。当手指从屏幕上抬起时Up接口输出一个脉冲。
The Counter 2 patch outputs the state of the counter (the number value) and accepts pulses to increase it or decrease it.
Counter 2 模块输出计数器的状态(一个数值)并且接受脉冲去增加它或者减少它。
The Scroll patch outputs the state of the scroller like its current position and page, and accepts pulses to have it jump to a specific position.
Scroll 模块输出滚动的状态,比如它当前的位置,页数,并且接受脉冲使它跳转到一个特定的位置。
Creating Pulses from State 为状态创建脉冲
There are a couple ways to create a pulse from state. The more explicit way is to use the Pulse patch. The Pulse patch accepts a state called Input Signal. If the Detection Mode is set to Leading, it will output a pulse when the state changes from off to on. If the mode is set to Trailing, it will output a pulse when the state changes from on to off.
有几种方式可以为状态创建一个脉冲。最直接的方法是使用脉冲模块。脉冲模块允许一个状态调用Input Signal(输入信号),如果监测方式设为前置,当状态从关改变为开时会输出一个脉冲。如果方式为后置,当状态从开改变为关时会输出一个脉冲。
Another way is to infer a state change is to connect a state directly to a port accepting a pulse. What'll happen is the port that accepts a pulse will look to when the state changes from off to on, and at that moment infer a pulse. So if you wanted a switch to flip the moment the users finger went down on the screen, you could connect the Down port directly to the Switch's Flip port, without needing to use a Pulse patch.
另一个能推理一个状态改变的方法是直接让连接一个状态的接口允许脉冲。允许脉冲的接口会发生什么,要看当状态从关到开改变时,在这一刻来推断脉冲。所以如果你想在用户手指落在屏幕上的时候转换开关,你可以连接Down接口直接到Switch模块的Flip接口,不需要使用Pulse模块。
Transient State with the Delay patch 过渡状态和延时模块
Sometimes you need a state to go from off to on for a few moments and then back to off. For example, say you were making a confirmation window appear for a couple seconds after the user pressed a button. You could do this using a Switch, but then you'd need to build logic that turns the switch off after some time. A simpler way to do this is to use the Delay D patch.
有时候你需要一个状态在短时间内从关到开,然后再回到关。例如,当用户按下一个按钮后,你使一个确认弹窗只出现几秒。你可以使用Switch做这个,但是你需要建立一些时间后关闭开关的逻辑。一个简单的方法是使用延时模块做这个,
The Delay patch can take state that's changing and delay the change by an amount of time you specify. You can also tell it whether to only delay increasing (off to on) or decreasing (on to off) changes. If you give a Delay patch a pulse as input, you can delay the change from on to off, extending the pulse for any amount of time you'd like.
延时模块可以使状态在你指定的一些时间改变或延时改变。你也可以告诉它是否是只延时增加(关到开)或减少(开到关)的改变如果你给延时模块一个脉冲作为输入,你可以让从开到关的改变延时,并任意延长脉冲的时间。