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。运行时大家可以多动动鼠标,会发现有趣的变化。

相关推荐
开开心心_Every5 小时前
实现鼠标键盘动作录制与重复播放的工具
微信·jupyter·pycharm·pdf·计算机外设·word·excel
科技每日热闻16 小时前
一屏总览!飞利浦超宽商用显示器49B2U5900CH,定义后期剪辑创作体验
计算机外设
智塑未来1 天前
2026年电竞鼠标十强解析:镁合金如何重塑竞技体验
计算机外设
励志不掉头发的内向程序员2 天前
LibreCAD 2D架构】从鼠标点击到屏幕像素:LibreCAD绘图架构全链路解析之鼠标事件与RS_ActionDrawLine
c++·qt·学习·架构·计算机外设
不想看见4042 天前
一次关于“鼠标是不是串口”的追问:从USB协议到CAN总线
c++·qt·计算机外设
驱动小百科3 天前
雷柏鼠标驱动下载教程:雷柏鼠标驱动怎么安装
计算机外设·雷柏鼠标驱动下载·雷柏鼠标驱动·雷柏鼠标驱动安装·雷柏鼠标驱动官网
playboy1344 天前
NAS不能访问共享文件夹数据恢复
大数据·计算机外设
卢锡荣4 天前
一线通桌面显示器优选芯|乐得瑞 LDR6021Q
计算机外设
每周报刊6 天前
竞速座舱级视界:爱攻 AGP497UCZD 超宽 QDOLED 显示器解析
数据结构·游戏·计算机外设
小幂同学8 天前
笔记本触控板能用鼠标连点器吗?快捷键与位置问题解析
计算机外设·鼠标连点器·连点器