[Processing]在画布上写文本
- 准备工作
- 这一步只是我强迫症犯了哈,这个随意,画几根线而已。每一小格10个像素,中格50,大格100像素
1 void setup() 2 { 3 size(1280,720); 4 } 5 6 void draw() 7 { 8 background(0,0,0); 9 //translate(width/2,height/2); 10 Aix(1,50,width,height,40); 11 Aix(2,100,width,height,60); 12 Aix(1,10,5,5,100); 13 Aix(2,50,7,7,100); 14 stroke(150); 15 strokeWeight(3); 16 line(-width,0, width,0); 17 line(0,-height, 0,height); 18 19 DrawText(); 20 } 21 22 float weight = 3; 23 float del = 100; 24 float lonW = 10; 25 float lonH = 10; 26 void Aix(float w,float d,float lw,float lh,float st) 27 { 28 weight = w; 29 del = d; 30 lonW = lw; 31 lonH = lh; 32 stroke(st); 33 strokeWeight(weight); 34 for(int i = 0;i <= width;i+=del) 35 { 36 line(i,-lonH, i,lonH); 37 } 38 for(int i = 0;i >= -width;i-=del) 39 { 40 line(i,-lonH, i,lonH); 41 } 42 for(int i = 0;i <= height;i+=del) 43 { 44 line(-lonW,i, lonW,i); 45 } 46 for(int i = 0;i >= -height;i-=del) 47 { 48 line(-lonW,i, lonW,i); 49 } 50 } 51 52 void DrawText() 53 { 54 55 }
- 打印文字
1 text(String str,float x,float y[,float z]);//在某位置显示文本,默认为白色的文本,可用 fill() 方法填充颜色 2 text(char[] chars,int start,int end,float x,float y[,float z]); 3 text(String str,float x1,float y1,float x2,float y2);//在两个点决定的矩形内显示字符串 4 text(float num,float x,float y[,float z]);
1 void DrawText() 2 { 3 String str = "Hello World"; 4 text(str,50,50); 5 }
- 默认文字是白色的,所以如果一开始背景是浅色的话回看不清楚,这一点要注意。可用用 fill(); 方法改变颜色
- 字体大小
1 void DrawText() 2 { 3 String str = "Hello World"; 4 5 textSize(50);//修改字体大小 6 text(str,50,50); 7 }
- 对其方式
- textAlign(h[,o]); 其中,h表示水平对齐方式,o表示垂直对齐方式,可填入宏
- h
- RIGHT 右对齐
- CENTER
- LEFT
- o
- TOP
- CENTER
- BOTTOM
- BASELINE 基线对齐
- h
1 void DrawText() 2 { 3 String str = "Hello World"; 4 5 noFill(); 6 stroke(#E0A000); 7 rect(0,0, 500,300);//画矩形 8 9 textSize(50); 10 textAlign(RIGHT,BOTTOM);//右下对齐 11 text(str,0,0, 500,300);//在一个矩形内显示 12 }
- textAlign(h[,o]); 其中,h表示水平对齐方式,o表示垂直对齐方式,可填入宏
- 设置行高
1 void DrawText() 2 { 3 String str = "Hello World\nWorld Hello"; 4 5 noFill(); 6 stroke(#E0A000); 7 rect(0,0, 500,300); 8 9 textSize(20); 10 textLeading(20); 11 text(str,0,0, 500,300); 12 textLeading(40); 13 text(str,150,0, 500,300); 14 textLeading(80); 15 text(str,300,0, 500,300); 16 }
文本宽度
1 void DrawText() 2 { 3 String str = "Hello World\nWorld Hello"; 4 5 noFill(); 6 stroke(#E0A000); 7 rect(0,0, 500,300); 8 9 textSize(20); 10 textLeading(20); 11 text(str,0,0, 500,300); 12 13 //画一个框把一行文字框起来 14 stroke(#FFFFCC); 15 line(0,0, textWidth(str),0);//用到了获取字符串宽度的方法 textWidth() 16 line(0,20, textWidth(str),20); 17 18 stroke(#EECCEE); 19 line(0,0, 0,20); 20 line(textWidth(str),0, textWidth(str),20); 21 }
转载于:https://www.cnblogs.com/Yukisora/p/9270326.html
[Processing]在画布上写文本相关推荐
- html5画布添加输入框,JS,HTML5 - 在画布上添加文本输入值作为fillText
我试图用HTML5 canvas来玩弄一点,而我只是在制作一个有趣的小型web应用程序,但我已经陷入困境.JS,HTML5 - 在画布上添加文本输入值作为fillText 我希望用户输入文本到文本框, ...
- 在cmd上写文本,并保存查看
一般来说我们在windows上写文本文档都是新建记事本,然后写完了,保存,如果要看的话,再打开. 前一阵子突然看到了这些操作,不觉明历,现在分享一下! win+r 然后输入cmd color 0a ...
- python在画布上写文字大小_Tkinter:在画布上缩放项目
我试着去理解画布的缩放是如何工作的. 例如,下面的代码.为什么绑定到鼠标滚轮的canvas.scale("all", ...)正在缩放所有矩形,而不是文本. 如何实现文本和矩形的缩 ...
- Qt工作笔记-第三种方法在QGraphics上写文本
前面的两种方法: QGraphicsSimpleTextIte和QGraphicsTextItem 如下: https://blog.csdn.net/qq78442761/article/detai ...
- Qt工作笔记-在Graphics上写文本(QGraphicsSimpleTextItem与QGraphicsTextItem的基本使用)
查了下文档发现就这2个, 一个是QGraphicsTextItem,另外一个是QGraphicsSimpleTextItem 从官方对QGraphicsTextItem中的描述中可以看到: 这个QGr ...
- Jeff Dean的激荡人生:我和Sanjay在同一台电脑上写代码
选自NewYorker,作者:James Somers,机器之心编译. 有很多人认为,Jeff Dean 的存在是谷歌如此强大的原因,谷歌员工都把谷歌搜索惊人的速度归功于他,他也是神经网络框架 Ten ...
- python matplotlib在一张画布上画多个图的两种方法,plt.subplot(),plt.subplots()。
Matplotlib在一张画布上画多个图的两种方法,plt.subplot,plt.subplots. 目录 回顾 plt.subplots()画法 plt.subplot()画法 保存 回顾 之前也 ...
- html画布图片不显示_如何在HTML5画布上显示图像
html画布图片不显示 by Nash Vail 由Nash Vail Ok, so here's a question: "Why do we need an article for th ...
- MPAndroidchart自定义样式二在柱状图上显示文本和间断式显示柱状图
内容描述 a .在柱状图上显示文本 b.间断式显示柱状图 产品原型如下: 难点描述: MPAndroidChart 并不支持将文字描述信息展示到柱状图(条形图)上:而且也不支持不从0开始的柱状节点展示 ...
最新文章
- 面试官问:说说悲观锁、乐观锁、分布式锁?都在什么场景下使用?有什么技巧?...
- 系统上线后关键用户的工作建议
- 图像局部显著性—点特征(GLOH)
- SAP Spartacus 在 Github 托管虚拟机上执行的 pipeline 明细
- chi660e电化学工作站软件_RuddlesdenPopper 型锰酸盐LaSr2Mn2O7的氧还原性能和作为电化学电容器电极材料的性能研究...
- 上凸包和下凸包_使用凸包聚类
- 分治法在排序算法中的应用(JAVA)--快速排序(Lomuto划分、Hoare划分、随机化快排)
- 程序员的算法课(7)-01背包问题
- LNAMP 中的PHP探针
- VS2010-MFC(MFC常用类:MFC异常处理)
- axure内联框架和动态面板_Axure中内联框架的使用与设置图文教程(第12)
- 离散数学 习题篇 —— 谓词公式练习
- AppFabric 版本区分
- 小程序发布上线全流程(包含小程序怎么通过审核)
- linux realtek声卡驱动下载,一步一步安装Realtek ALC888、ALC1200 声卡(附Realtek ALC888 ALC1200驱动)...
- 旅行商问题和背包问题
- 两台 计算机如何建立共享,怎么建立两个电脑的共享
- iOS RunTime机制----让catagory能够增加属性
- ipad浏览器安装java_在桌面浏览器中调试iphone、ipad等设备上的网页
- 长短期记忆网络(LSTM)简述