p5 java_求助!!急急急有没有朋友可以把这p5转化成java 呀 谢谢

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

let _aryObject = [];

let _tileNumT;

let _tileNumR;

let _ellipseRatio;

let _count;

let _stepR;

let _stepT;

function setup() {

let canvasSize;

if (windowWidth <= windowHeight) {

canvasSize = windowWidth;

} else {

canvasSize = windowHeight;

}

createCanvas(canvasSize, canvasSize);

frameRate(30);

noFill();

colorMode(HSB, 360, 100, 100, 255);

strokeJoin(ROUND);

_freqCount = 20;

_count = 0;

_ellipseRatio = 2;

_tileNumT = 12;

_tileNumR = 4;

let shapeMode = 1;

let initT = int(random(_tileNumT));

let layerNum = 20;

for (k = 1; k <= layerNum; k++) {

let baseColor = 360 + random(720);

_aryObject.push(new f(

1, initT,

color((baseColor + 180) % 360, 100, 100, 255),

shapeMode,

width/2/_tileNumR/layerNum*k

));

}

}

function draw() {

clear();

blendMode(DIFFERENCE);

background(255);

for (let i = 0; i < _aryObject.length; i++) {

_aryObject[i].update();

_aryObject[i].drawMe();

}

_count ++;

}

class f {

constructor(iR, iT, myColor, shapeMode, sw) {

this.target_iR = iR;

this.target_iT = iT;

this.myColor = myColor;

this.shapeMode = shapeMode; //0 rect, 1 ellipse

this.sw = sw *_ellipseRatio;

this.aryPoint = [];

}

setTarget() {

_stepR = 1;

_stepT = 2;

this.iR = this.target_iR;

this.iT = this.target_iT % _tileNumT;

this.aryPoint.unshift([this.iR, this.iT]);

let dir;

if (this.iR <= _stepR) {

dir = random(["down", "left", "right"]);

} else if (this.iR >= _tileNumR-_stepR) {

dir = random(["up", "left", "right"]);

} else {

dir = random(["up", "down", "left", "right"]);

}

if (dir == "up") { this.target_iR = this.iR - _stepR; }

else if (dir == "down") { this.target_iR = this.iR + _stepR; }

else if (dir == "left") { this.target_iT = this.iT - _stepT; }

else if (dir == "right") { this.target_iT = this.iT + _stepT; }

this.dR = (this.target_iR - this.iR) / (_freqCount+1);

this.dT = (this.target_iT - this.iT) / (_freqCount+1);

}

update() {

if (_count % _freqCount == 0) {

this.setTarget();

}

if (this.target_iR == this.iR) { //dir = right or left

this.aryPoint.unshift([this.iR, this.aryPoint[0][1] + this.dT]);

} else if (this.target_iT == this.iT) {

this.aryPoint.unshift([this.aryPoint[0][0] + this.dR, this.iT]);

}

while (this.aryPoint.length >= 40) {

this.aryPoint.pop();

}

}

drawMe() {

stroke(this.myColor);

if (this.shapeMode == 0) {

strokeCap(PROJECT);

}

else {

strokeCap(ROUND);

}

strokeWeight(this.sw);

push();

translate(width/2, height/2);

beginShape();

for (let i = 0; i < this.aryPoint.length; i++) {

curveVertex(

width / 2 / _tileNumR * this.aryPoint[i][0] * cos(2*PI / _tileNumT * this.aryPoint[i][1]),

width / 2 / _tileNumR * this.aryPoint[i][0] * sin(2*PI / _tileNumT * this.aryPoint[i][1]));

}

endShape();

pop();

}

}

function mouseReleased() {

_count = 0;

_ellipseRatio = 2;

_tileNumT = 12;

_tileNumR = 4;

let shapeMode = 1;

let initT = int(random(_tileNumT));

let layerNum = 20;

_aryObject = [];

for (k = 1; k <= layerNum; k++) {

let baseColor = 360 + random(720);

_aryObject.push(new f(

1, initT,

color((baseColor + 180) % 360, 100, 100, 255),

shapeMode,

width/2/_tileNumR/layerNum*k

));

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值