当前位置: 首页 > news >正文

实验五之用Processing绘画

1.案例代码如下:

import generativedesign.*;
import processing.pdf.*;
import java.util.Calendar;
Tablet tablet;
boolean recordPDF = false;
float x = 0, y = 0;
float stepSize = 5.0;
PFont font;
String letters = "Sie hören nicht die folgenden Gesänge, Die Seelen, denen ich die ersten sang,Zerstoben ist das freundliche Gedränge, Verklungen ach! der erste Wiederklang.";
int fontSizeMin = 15;
float angleDistortion = 0.0;
int counter = 0;
void setup() {
size(displayWidth, displayHeight);
background(255);
smooth();
tablet = new Tablet(this);
x = mouseX;
y = mouseY;
font = createFont("ArnhemFineTT-Normal",10);
textFont(font,fontSizeMin);
cursor(CROSS);
}
void draw() {
if (mousePressed) {
float pressure = gamma(tablet.getPressure()*1.1, 2.5);
float d = dist(x,y, mouseX,mouseY);
textFont(font,fontSizeMin+ 200 * pressure);
char newLetter = letters.charAt(counter);
stepSize = textWidth(newLetter);
if (d > stepSize) {
float angle = atan2(mouseY-y, mouseX-x);
pushMatrix();
translate(x, y);
rotate(angle + random(angleDistortion));
fill(0);
textAlign(LEFT);
text(newLetter, 0, 0);
popMatrix();
counter++;
if (counter > letters.length()-1) counter = 0;
x = x + cos(angle) * stepSize;
y = y + sin(angle) * stepSize;
}
}
}
void mousePressed() {
x = mouseX;
y = mouseY;
}
void keyReleased() {
if (key == 's' || key == 'S') saveFrame(timestamp()+"_##.png");
if (key == DELETE || key == BACKSPACE) background(255);
if (key =='r' || key =='R') {
if (recordPDF == false) {
beginRecord(PDF, timestamp()+".pdf");
println("recording started");
recordPDF = true;
}
}
else if (key == 'e' || key =='E') {
if (recordPDF) {
println("recording stopped");
endRecord();
recordPDF = false;
background(255);
}
}
}
void keyPressed() {
if (keyCode == UP) angleDistortion += 0.1;
if (keyCode == DOWN) angleDistortion -= 0.1;
}
float gamma(float theValue, float theGamma) {
return pow(theValue, theGamma);
}

String timestamp() {
Calendar now = Calendar.getInstance();
return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now);
}

       保存并运行发现是空白的,此时只需要用鼠标绘画出自己想要的内容即可。我写的是乒乓球世界第一孙颖莎的大写字母。如图1

                                         图1

        绘画完成后想保持PNG可以按S或者小写s,想保存PDF按大写E或者小写e。如果觉得画的不好看,按下Backspace可以清屏。如果发现报错没关系,可以运行成功并进行绘画。

http://www.lryc.cn/news/428378.html

相关文章:

  • Apache CloudStack Official Document 翻译节选(七)
  • 动态创建 Delphi 按钮的完整指南:基于配置文件的 `TGridPanel` 实现
  • 【设计模式】工厂模式和抽象工厂模式
  • 【xilinx】Versal Adaptive SoC DDRMC - NoC QoS 选项卡未出现
  • 融合创新:EasyCVR视频汇聚平台云计算技术与AI技术共筑雪亮工程智能防线
  • keepalived的技术原理及其在负载均衡场景中的应用
  • 树的重心 by江河湖海
  • MySQL存储过程深入指南
  • 牛客算法小题
  • 小米SU7销量超特斯拉,新车明年上半年发布
  • 基于Java语言的光伏监控系统+光伏发电预测+光伏项目+光伏运维+光伏储能项目
  • unity json 处理
  • 如何使用DataGear零编码快速制作MQTT物联网实时数据看板
  • Mysql查询日志
  • Airtest 的使用
  • Android更改包名和签名
  • tortoisegit下载及其使用流程
  • Anrdoir 13 关于设置静态IP后,突然断电,在上电开机卡动画
  • multimodel ocr dataset
  • 兼容并蓄,高效集成:EasyCVR视频综合接入能力助力多元化项目需求
  • linux 部署YUM仓库及NFS共享服务
  • LCD 显示字符
  • NOI2003 逃学的小孩 题解
  • 硬件服务器操作系统的选择:Linux 还是 Windows?
  • dataV组件使用——数据更新更新组件
  • solana合约编写
  • C++调用C#方法(附踩坑点)
  • 开源前端埋点监控插件Web-Tracing
  • 智慧排水远程监测系统物联网解决方案
  • 【SVN(Subversion)是一个版本控制系统】