2 Star 0 Fork 0

AlexWang0296/HyPost

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
scale-label.py 1.70 KB
一键复制 编辑 原始数据 按行查看 历史
AlexWang0296 提交于 2019-02-07 16:08 . Add CSL
# This user-defined function is called by OVITO to let it draw arbitrary graphics on top of the viewport.
def render(args):
# This demo code prints the current animation frame into the upper left corner of the viewport.
text1 = "Frame {}".format(args.frame)
args.painter.drawText(10, 10 + args.painter.fontMetrics().ascent(), text1)
# Also print the current number of particles into the lower left corner of the viewport.
pipeline = args.scene.selected_pipeline
if pipeline:
data = pipeline.compute()
num_particles = data.particles.count
text2 = "{} particles".format(num_particles)
args.painter.drawText(10, args.painter.window().height() - 10, text2)
from PyQt5.QtCore import *
from PyQt5.QtGui import *
# Parameters:
bar_length = 10 # Simulation units (e.g. Angstroms)
bar_color = QColor(0,0,0)
label_text = "{} nm".format(bar_length/10)
label_color = QColor(255,255,255)
# This function is called by OVITO on every viewport update.
def render(args):
if args.is_perspective:
raise Exception("This overlay only works with non-perspective viewports.")
# Compute length of bar in screen space
screen_length = args.project_size((0,0,0), bar_length)
# Define geometry of bar in screen space
height = 0.07 * args.painter.window().height()
margin = 0.02 * args.painter.window().height()
rect = QRectF(margin, margin, screen_length, height)
# Render bar rectangle
args.painter.fillRect(rect, bar_color)
# Render text label
font = args.painter.font()
font.setPixelSize(height)
args.painter.setFont(font)
args.painter.setPen(QPen(label_color))
args.painter.drawText(rect, Qt.AlignCenter, label_text)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/alexwang0296/HyPost.git
[email protected]:alexwang0296/HyPost.git
alexwang0296
HyPost
HyPost
master

搜索帮助