如何在处理过程中提高Android模式下的帧速率?
我使用的是processing.js.com网站上的开源代码,它有frame rate()方法 当我改变帧速率时,它会在Java和Javascript模式下显示移动形状的变化,但在Android模式下不会, 为什么会发生这种情况? 我应该如何提高帧速率以加快我的可视化如何在处理过程中提高Android模式下的帧速率?,android,processing,Android,Processing,我使用的是processing.js.com网站上的开源代码,它有frame rate()方法 当我改变帧速率时,它会在Java和Javascript模式下显示移动形状的变化,但在Android模式下不会, 为什么会发生这种情况? 我应该如何提高帧速率以加快我的可视化 // Set number of circles int count = 25; // Set maximum and minimum circle size int maxSize = 100; in
// Set number of circles
int count = 25;
// Set maximum and minimum circle size
int maxSize = 100;
int minSize = 20;
// Build float array to store circle properties
float[][] e = new float[count][5];
// Set size of dot in circle center
float ds=2;
// Selected mode switch
int sel = 0;
// Set drag switch to false
boolean dragging=false;
// If use drags mouse...
void mouseDragged(){
// Set drag switch to true
dragging=true;
}
// If user releases mouse...
void mouseReleased(){
// ..user is no-longer dragging
dragging=false;
}
// Set up canvas
void setup(){
// Frame rate
frameRate(130);
// Size of canvas (width,height)
size(600,475);
// Stroke/line/border thickness
strokeWeight(1);
// Initiate array with random values for circles
for(int j=0;j< count;j++){
e[j][0]=random(width); // X
e[j][1]=random(height); // Y
e[j][2]=random(minSize,maxSize); // Radius
e[j][3]=random(-.5,.5); // X Speed
e[j][4]=random(-.5,.5); // Y Speed
}
}
// Begin main draw loop (called 25 times per second)
void draw(){
// Fill background black
background(0);
// Begin looping through circle array
for (int j=0;j< count;j++){
// Disable shape stroke/border
noStroke();
// Cache diameter and radius of current circle
float radi=e[j][2];
float diam=radi/2;
// If the cursor is within 2x the radius of current circle...
if( dist(e[j][0],e[j][1],mouseX,mouseY) < radi ){
// Change fill color to green.
fill(64,187,128,100);
// Remember user has circle "selected"
sel=1;
// If user has mouse down and is moving...
if (dragging){
// Move circle to circle position
e[j][0]=mouseX;
e[j][1]=mouseY;
}
} else {
// Keep fill color blue
fill(64,128,187,100);
// User has nothing "selected"
sel=0;
}
// Draw circle
ellipse(e[j][0],e[j][1],radi,radi);
// Move circle
e[j][0]+=e[j][3];
e[j][1]+=e[j][4];
/* Wrap edges of canvas so circles leave the top
and re-enter the bottom, etc... */
if( e[j][0] < -diam ){ e[j][0] = width+diam; }
if( e[j][0] > width+diam ){ e[j][0] = -diam; }
if( e[j][1] < 0-diam ){ e[j][1] = height+diam; }
if( e[j][1] > height+diam){ e[j][1] = -diam; }
// If current circle is selected...
if (sel==1) {
// Set fill color of center dot to white..
fill(255,255,255,255);
// ..and set stroke color of line to green.
stroke(128,255,0,100);
} else {
// otherwise set center dot color to black..
fill(0,0,0,255);
// and set line color to turquoise.
stroke(64,128,128,255);
}
// Loop through all circles
for(int k=0;k< count;k++){
// If the circles are close...
if( dist(e[j][0],e[j][1],e[k][0],e[k][1]) < radi){
// Stroke a line from current circle to adjacent circle
line(e[j][0],e[j][1],e[k][0],e[k][1]);
}
}
// Turn off stroke/border
noStroke();
// Draw dot in center of circle
rect(e[j][0]-ds,e[j][1]-ds,ds*2,ds*2);
}
}
//设置圈数
整数计数=25;
//设置最大和最小圆大小
int maxSize=100;
int minSize=20;
//构建浮点数组以存储圆属性
浮动[]e=新浮动[计数][5];
//设置圆心点的大小
浮点数ds=2;
//选择模式开关
int sel=0;
//将拖动开关设置为false
布尔拖动=假;
//如果使用拖动鼠标。。。
void mouseDragged(){
//将拖动开关设置为true
拖动=真;
}
//如果用户释放鼠标。。。
void mouseereleased(){
//…用户不再拖动
拖动=假;
}
//设置画布
无效设置(){
//帧速率
帧率(130);
//画布尺寸(宽度、高度)
尺寸(600475);
//笔划/线条/边框厚度
冲程重量(1);
//使用圆的随机值初始化数组
对于(int j=0;jwidth+diam){e[j][0]=-diam;}
如果(e[j][1]<0-diam){e[j][1]=高度+直径;}
如果(e[j][1]>height+diam){e[j][1]=-diam;}
//如果选择了当前圆。。。
如果(sel==1){
//将中心点的填充颜色设置为白色。。
填充(255255);
//..并将线条的笔划颜色设置为绿色。
冲程(128255,0100);
}否则{
//否则,将“中心点颜色”设置为黑色。。
填充(0,0,0255);
//并将线条颜色设置为绿松石色。
冲程(64128255);
}
//周旋
for(int k=0;k
要更改草图中圆的速度,只需更改速度值即可
在setup()函数中,可以设置以下内容:
e[j][3] = random(-.5, .5); // X Speed
e[j][4] = random(-.5, .5); // Y Speed
这些值稍后用于在draw()函数中移动圆:
// Move circle
e[j][0] += e[j][3];
e[j][1] += e[j][4];
您可以简单地更改setup()函数中设置的e[j][3]
和e[j][4]
值,也可以将它们替换为在代码开头的全局范围中指定的变量。下面是我要做的快速修改。注意变量<代码>浮动速度=0.5代码>设置在代码开头附近。如果将该值设置得更大,则圆的移动速度将更快
// Set number of circles
int count = 25;
// Set maximum and minimum circle size
int maxSize = 100;
int minSize = 20;
// Set speed
float speed = 0.5;
// Build float array to store circle properties
float[][] e = new float[count][5];
// Set size of dot in circle center
float ds = 2;
// Selected mode switch
int sel = 0;
// Set drag switch to false
boolean dragging = false;
// If use drags mouse...
void mouseDragged() {
// Set drag switch to true
dragging = true;
}
// If user releases mouse...
void mouseReleased() {
// ..user is no-longer dragging
dragging = false;
}
// Set up canvas
void setup() {
// Size of canvas (width,height)
size(600, 475);
// Stroke/line/border thickness
strokeWeight(1);
// Initiate array with random values for circles
for (int j = 0; j < count; j++) {
e[j][0] = random(width); // X
e[j][1] = random(height); // Y
e[j][2] = random(minSize, maxSize); // Radius
e[j][3] = random(-speed, speed); // X Speed
e[j][4] = random(-speed, speed); // Y Speed
}
}
// Begin main draw loop (called 25 times per second)
void draw() {
// Fill background black
background(0);
// Begin looping through circle array
for (int j = 0; j < count; j++) {
// Disable shape stroke/border
noStroke();
// Cache diameter and radius of current circle
float radi = e[j][2];
float diam = radi / 2;
// If the cursor is within 2x the radius of current circle...
if (dist(e[j][0], e[j][1], mouseX, mouseY) < radi) {
// Change fill color to green.
fill(64, 187, 128, 100);
// Remember user has circle "selected"
sel = 1;
// If user has mouse down and is moving...
if (dragging) {
// Move circle to circle position
e[j][0] = mouseX;
e[j][1] = mouseY;
}
} else {
// Keep fill color blue
fill(64, 128, 187, 100);
// User has nothing "selected"
sel = 0;
}
// Draw circle
ellipse(e[j][0], e[j][1], radi, radi);
// Move circle
e[j][0] += e[j][3];
e[j][1] += e[j][4];
/* Wrap edges of canvas so circles leave the top
and re-enter the bottom, etc... */
if (e[j][0] < -diam) {
e[j][0] = width + diam;
}
if (e[j][0] > width + diam) {
e[j][0] = -diam;
}
if (e[j][1] < 0 - diam) {
e[j][1] = height + diam;
}
if (e[j][1] > height + diam) {
e[j][1] = -diam;
}
// If current circle is selected...
if (sel == 1) {
// Set fill color of center dot to white..
fill(255, 255, 255, 255);
// ..and set stroke color of line to green.
stroke(128, 255, 0, 100);
} else {
// otherwise set center dot color to black..
fill(0, 0, 0, 255);
// and set line color to turquoise.
stroke(64, 128, 128, 255);
}
// Loop through all circles
for (int k = 0; k < count; k++) {
// If the circles are close...
if (dist(e[j][0], e[j][1], e[k][0], e[k][1]) < radi) {
// Stroke a line from current circle to adjacent circle
line(e[j][0], e[j][1], e[k][0], e[k][1]);
}
}
// Turn off stroke/border
noStroke();
// Draw dot in center of circle
rect(e[j][0] - ds, e[j][1] - ds, ds * 2, ds * 2);
}
}
//设置圈数
整数计数=25;
//设置最大和最小圆大小
int maxSize=100;
int minSize=20;
//设定速度
浮动速度=0.5;
//构建浮点数组以存储圆属性
浮动[]e=新浮动[计数][5];
//设置圆心点的大小
浮点数ds=2;
//选择模式开关
int sel=0;
//将拖动开关设置为false
布尔拖动=假;
//如果使用拖动鼠标。。。
void mouseDragged(){
//将拖动开关设置为true
拖动=真;
}
//如果用户释放鼠标。。。
void mouseereleased(){
//…用户不再拖动
拖动=假;
}
//设置画布
无效设置(){
//画布尺寸(宽度、高度)
尺寸(600475);
//笔划/线条/边框厚度
冲程重量(1);
//使用圆的随机值初始化数组
对于(int j=0;j