Processing圆圈随鼠标运动

一.案例代码如下:

import processing.pdf.*;

import java.util.Calendar;

boolean savePDF = false;

float tileCount =20;

color circleColor = color(0);

int circleAlpha = 180;

int actRandomSeed =0;

void setup(){

size(600,600);

}

void draw(){

if(savePDF)beginRecord(PDF,timestamp()+".pdf");

translate(width/tileCount/2,height/tileCount/2);

background(255);

smooth();

noFill();

randomSeed(actRandomSeed);

stroke(circleColor,circleAlpha);

strokeWeight(mouseY/60);

for(int gridY=0;gridY<tileCount;gridY++){

for(int gridX=0;gridX<tileCount;gridX++){

float posX=width/tileCount*gridX;

float posY =height/tileCount*gridY;

float shiftX=random(-mouseX,mouseX)/20;

float shiftY=random(-mouseX,mouseX)/20;

ellipse(posX+shiftX,posY+shiftY,mouseY/15,mouseY/15);

}

}

if(savePDF)

{savePDF=false;

endRecord();

}

}

void mousePressed(){

actRandomSeed=(int) random(100000);

}

void keyReleased(){

if(key=='s'||key=='S') saveFrame(timestamp()+"_##.png");

if(key=='p'||key=='P') savePDF=true;

}

String timestamp(){

Calendar now=Calendar.getInstance();

return String.format("%1ty%1tm%1td_%1tH%1tM%1tS",now);

}

保存并运行如图1

图1

注意:案例中按下大写P或者小写p保存PDF,如果按下大写S或者小写s可以保存PNG。运行时大家可以多动动鼠标,会发现有趣的变化。

相关推荐
神奇程序员7 天前
不止高刷:明基 RD280UG 在编码场景下的表现如何
计算机外设
开开心心就好7 天前
安卓开源应用,超时提醒紧急人护独居安全
windows·决策树·计算机视觉·pdf·计算机外设·excel·动态规划
上海合宙LuatOS7 天前
LuatOS核心库API——【iotauth 】 IOT 鉴权库
java·单片机·嵌入式硬件·物联网·struts·计算机外设·硬件工程
谁刺我心7 天前
qml自定义鼠标
计算机外设
SamtecChina20238 天前
Samtec连接器设计研究 | 载流量:温升为什么重要?
大数据·网络·人工智能·算法·计算机外设
ACP广源盛139246256738 天前
GSV6502与GSV2001应用场景相同点和差异点对比@ACP
单片机·计算机外设
凌云拓界8 天前
TypeWell全攻略(二):热力图渲染引擎,让键盘发光
前端·后端·python·计算机外设·交互·pyqt·数据可视化
南山十一少10 天前
cherry键盘组合MacBook使用
计算机外设
开开心心就好11 天前
免费音频转文字工具,绿色版离线多模型可用
人工智能·windows·计算机视觉·计算机外设·ocr·excel·语音识别
开开心心就好12 天前
实用系统备份还原,小巧免PE备份快镜像小
windows·计算机视觉·pdf·计算机外设·迭代器模式·excel·桥接模式