Processing练习之鼠标控制线段粗细

案例代码如下:

import processing.pdf.*;

import java.util.Calendar;

boolean savePDF = false;

int tileCount = 20;

int actRandomSeed =0;

int actStrokeCap = ROUND;

void setup(){

size(600,600);

}

void draw(){

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

background(255);

smooth();

noFill();

strokeCap(actStrokeCap);

randomSeed(actRandomSeed);

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

{

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

{

int posX = width/tileCount*gridX;

int posY = height/tileCount*gridY;

int toggle =(int)random(0,2);

if(toggle == 0){

strokeWeight(mouseX/20);

line (posX, posY,posX+width/tileCount,posY+height/tileCount);

}

if(toggle == 1){

strokeWeight(mouseY/20);

line(posX, posY+height/tileCount, posX+width/tileCount, posY);

}

}

}

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;

if (key == '1'){

actStrokeCap = ROUND;

}

if (key =='2'){

actStrokeCap= SQUARE;

}

if (key == '3'){

actStrokeCap = PROJECT;

}

}

String timestamp(){

Calendar now= Calendar.getInstance();

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

}

保存并运行如图1

图1

相关推荐
降临-max6 分钟前
JavaWeb企业级开发---Mybatis
java·开发语言·笔记·学习·mybatis
知乎的哥廷根数学学派7 分钟前
基于多物理约束融合与故障特征频率建模的滚动轴承智能退化趋势分析(Pytorch)
人工智能·pytorch·python·深度学习·算法·机器学习
我是一只小青蛙88812 分钟前
位图与布隆过滤器:高效数据结构解析
开发语言·c++·算法
eso198327 分钟前
白话讲述监督学习、非监督学习、强化学习
算法·ai·聚类
chen_jared29 分钟前
反对称矩阵的性质和几何意义
人工智能·算法·机器学习
好好研究30 分钟前
SpringBoot注解的作用
java·spring boot·spring
海天一色y41 分钟前
python---力扣数学部分
算法·leetcode·职场和发展
一起努力啊~1 小时前
算法刷题--哈希表
算法·面试·散列表
Libby博仙1 小时前
Spring Boot 条件化注解深度解析
java·spring boot·后端
willingli1 小时前
c语言经典100题 61-70题
c语言·开发语言·算法