`
javalurker
  • 浏览: 23489 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

Text Transitions

阅读更多
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.effect.DropShadow;
import javafx.scene.text.Text;
import javafx.scene.text.TextOrigin;
import javafx.scene.text.Font;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;

import javafx.animation.KeyFrame;
import javafx.animation.Timeline;

def BASE_WIDTH = 800;
def BASE_HEIGHT = 600;
def MARGIN = 20;

var backgroundRect = Rectangle
{
x:        0
y:        0
width:    BASE_WIDTH
height:   BASE_HEIGHT

onMouseClicked: function(event) { t.playFromStart() }
}

var boundingRect = Rectangle
{
x:            MARGIN * 2
y:            BASE_HEIGHT * 2 / 3 - MARGIN
width:        BASE_WIDTH - MARGIN * 4
height:       BASE_HEIGHT - (BASE_HEIGHT * 2 / 3)
fill:         Color.rgb(255, 255, 255, 0.2)
stroke:       Color.WHITE
strokeWidth:  2
}

var displayedText = Text
{
x: boundingRect.x + MARGIN
y: boundingRect.y + MARGIN
wrappingWidth: boundingRect.width - MARGIN * 2
content: ""
font: Font { size: 36 }
textOrigin: TextOrigin.TOP
//stroke: Color.BLACK
fill: Color.WHITE
effect: DropShadow {}
}

def FINAL_TEXT = "I was trying to get the text to wrap, but the text layout engine would keep putting a character on the previous line until the full word was visible.";
var charCount = 0 on replace
{
var textToDisplay = FINAL_TEXT.substring(0, charCount);
displayedText.content = textToDisplay;
}

Stage
{
title:   "Text demo"
visible: true
scene:   Scene
{
width:   BASE_WIDTH
height:  BASE_HEIGHT
fill:    Color.BLACK
content:
[
backgroundRect,
boundingRect,
displayedText
]
}
}

var t = Timeline
{
keyFrames:
[
// In reality the speed would be per letter so the times would
// be computed dynamically.  I have an idea of how to do that.
// Initial experiments also suggest that the speed of displaying
// each letter should be relative to the width of the letter.
KeyFrame { time:  0s, values: charCount => 0 }
KeyFrame { time:  3s, values: charCount => FINAL_TEXT.length() }
]
};
t.play();
分享到:
评论

相关推荐

    文本过渡动画效果

    NRTextTransitions is a category in UIView that makes easier handling animated text transitions for UILabel, UITextView and UITextField. As the standard +[UIView animateWithDuration:animations:] is not...

    Android代码-Transitions-Everywhere

    Transitions Everywhere Backport of Android Transitions API. Animations backported to Android 4.0 . API compatible with ...text.setVisibility(visible ? View.VISIBLE : View.GONE); Article and sample ap

    Python 3 Using ChatGPT/GPT-4

    This book is intended primarily for ... Next, the text transitions to Generative AI, discussing its distinction from Conversational AI. Popular platforms and models, including ChatGPT, GPT-4, and thei

    html5 texteffect设置每行文字特效

    CSS3提供了诸如动画(Animations)、过渡(Transitions)和变换(Transforms)等特性,使得文字效果的实现变得更加简单。例如,我们可以使用`@keyframes`规则来定义一个动画,使其应用于文本元素,从而创建出动态的...

    到处无处不在的转换:在Jetpack Transitions Library之上的一组额外转换

    在平台中标记为@hide的内部过渡: Recolor , Rotate , ChangeText和Crossfade 。 另外两个过渡:缩放和翻译。 快速开始 如果您将29(Q)指定为targetSdkVersion则应使用此版本: dependencies { ...

    ffmpeg-gl-transition

    FFmpeg 是一个强大的开源工具套件,用于处理多媒体文件,包括视频、音频转换、流处理等。`ffmpeg-gl-transition` 是 FFmpeg 的一个扩展,它引入了OpenGL(Graphics Library)支持,使得在视频剪辑中实现平滑的过渡...

    css3-text-bubble-tips.zip

    5. **过渡(Transitions)和动画(Animations)**:CSS3的过渡效果可以让元素在状态变化时平滑过渡,而动画则可以创建复杂的动态效果,使得文本气泡在出现、消失或改变方向时更加吸引人。 6. **盒模型**:理解CSS3...

    The Book of CSS3

    With real-world examples and a focus on results, The Book of CSS3 shows you how to transform ordinary text into stunning, richly detailed web pages fit for any browser. You'll master the latest ...

    CSS3多行文本下划线动画特效.zip

    2. CSS3 Transitions 和 Animations: - CSS3 的 `transition` 属性用于创建平滑的过渡效果,当元素的某个属性发生变化时,它会在两个值之间平滑地过渡。例如,`transition: text-decoration-color 2s ease-in-out;...

    text-recognizer:PyTorch中的文本识别器,基于“全栈深度学习课程”中教授的项目和最佳实践,结合了Claudio Jolowicz的Hypermodern Python

    设置待定去做 创建字词 make_wordpieces.py build_transitions.py 将IAM目标编码为单词的转换 换能器损耗函数[]带单词的训练[]实现wandb回调进行日志记录[]实施每次点击费用[]窗口图像[]火车骨干[]伯特培训,如何?...

    CSS3伪三维径向圆形按钮,无JS及图片,纯HTML.rar

    text-shadow transitions gradients :nth-child() pseudo-class Opera浏览器和Firefox浏览器对于阴影使用的是box-shadow inset, 而Webkit浏览器(如谷歌浏览器)使用的是background:-webkit-gradient. 谷歌下个...

    纯CSS3实现漂亮的input输入框动画样式库(Text input love)

    1. **过渡(Transitions)**:这是一种简单的动画效果,它允许元素的样式属性在一定时间内平滑变化。过渡通常用于属性如颜色、大小、位置等的变化。 2. **关键帧动画(Keyframe Animations)**:这是更复杂的动画...

    纯CSS3实现的3D镂空文字特效源码.zip

    5. **过渡(Transitions)**:当鼠标悬停或焦点变化时,可以使用`transition`属性平滑地改变元素的样式,例如改变颜色、大小等,为3D镂空文字增加动态效果。 6. **动画(Animations)**:CSS3的`@keyframes`规则...

    QML例子:模拟交通灯

    text: "Start" onClicked: { // 在这里启动或停止定时器 } } ``` 交通灯的状态转换可以通过定时器来实现。在QML中,我们可以使用`Timer`对象来创建定时器。当按钮被点击时,启动定时器,每隔一定时间改变交通灯...

    Transitions:android中的共享元素过渡和动画

    android:text="Click me!" android:transitionName="shared_button" /> <!-- 在目标活动布局 --> android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" ...

    Animated-Text-Background:动画文字背景项目

    CSS3引入了许多强大的功能,如动画(Animations)和过渡(Transitions),使得开发者能够实现复杂的视觉动态效果。在这个项目中,开发者可能使用了`@keyframes`规则来定义动画的关键帧,以及`animation`属性来应用...

    FairyGUI-Unity-Plugin-3.4.0.zip

    - NEW: Transitions now support playing partially and pausing. - IMPROVED: Change the way of registering bitmap font. - FIXED: A GButton pivot issue. - FIXED: Correct text align behavior. 2.3.0 - NEW...

    Mastering CSS

    Rich begins your CSS training with a review of CSS best practices, such as using a good text editor to automate your authoring and setting up a CSS baseline. You then move on to create a responsive ...

    CSS3背景颜色与文字滚动同时切换代码

    首先,我们要了解CSS3中的动画(Animations)和过渡(Transitions)特性。这两个特性允许我们在不同的时间间隔内改变元素的样式属性,从而创造出流畅的视觉变化。例如,背景颜色的变化可以通过`transition`属性来...

Global site tag (gtag.js) - Google Analytics