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

相关推荐
BridgeCloud14 分钟前
华硕电脑键盘全部失灵
计算机外设·电脑
Luminbox紫创测控19 分钟前
杂散光测试-HUD抬头显示器太阳光模拟器
计算机外设
开开心心就好1 天前
电子教材下载工具,支持多链接批量下载
windows·随机森林·计算机视觉·pdf·计算机外设·逻辑回归·excel
春日见1 天前
自动驾驶的四个演进阶段
开发语言·人工智能·驱动开发·matlab·docker·计算机外设
mzhan0171 天前
电脑:鼠标
计算机外设·电脑
WHD3061 天前
苏州服务器维修哪家好/公司推荐
linux·ubuntu·centos·计算机外设·电脑·unix·安全架构
ONE_SIX_MIX1 天前
debian13 无显示器的 服务器,开机不自动加载nvidia 驱动的,解决
运维·计算机外设
Vanranrr2 天前
抛弃“鼠标点点点”,用键盘流把节奏拉满
计算机外设
Saniffer_SH2 天前
【高清视频】实验室搭建PCIe 6.0测试环境需要的retimer卡介绍
服务器·驱动开发·测试工具·fpga开发·计算机外设·硬件架构·压力测试
ACP广源盛139246256732 天前
ASW3810@ACP#4 路差分 2:1/1:2 双向多路复用 / 解复用器 产品规格与应用总结
大数据·单片机·嵌入式硬件·计算机外设·电脑