如何为 Android 设置处理?
处理是一个免费的图形库,我ntegrated d才有发展Ënvironment(IDE)的电子艺术和视觉设计社区建成。它是当今最强大的库之一,可用于创建 2D 和 3D 视觉算法艺术作品。它是开源的,基于Java,并带有大量的功能,旨在使用代码进行绘图和绘画既有趣又容易。我们可以使用我们的编码技能示例、游戏、动画和物理引擎等来创建不同类型的艺术。
在您的 Android 应用程序中使用 Processing 的核心库,您可以创建高性能图形和动画,而无需处理 Android 的 OpenGL 或 Canvas API。通常,您甚至不必为管理线程、创建渲染循环或保持帧速率等低级任务而烦恼。在本文中,我们将讨论如何为 Android 设置处理。
分步实施
步骤 1:从此链接下载适用于您的操作系统(OSX、Windows 或 Linux)的 Processing 3.0。
步骤 2:在任何文件夹中解压缩 Zip 文件并打开processing.exe文件。
第 3 步:应用程序打开后,单击下图“添加更多”中的图标。
第 4 步:现在安装Android 模式。
第 5 步:如果您的计算机上没有Android SDK ,请安装它。
Android SDK 安装完成后,Processing for android 的安装部分就完成了,现在我们在上面创建我们的项目。
在设备上运行
现在为了在我们的设备上运行,我们必须像在 android 中和通过 USB 一样将我们的设备保持在开发人员模式。
示例代码:
Java
// Program to show moving Ball and changing colour.
// Set up variable position,colour and velocity.
PVector pos;
PVector vel;
int col;
// Function to set up size of canvas
// and position,velocity and colour.
void setup(){
size(600, 600);
pos = new PVector(width/2, height/2);
vel = new PVector(random(-4, 4), random(-4, 4));
col = floor(random(0, 255));
}
// Function to draw eclipse.
void draw(){
background(col);
fill(231);
checkValid();
fill(204, 102, 0);
ellipse(pos.x, pos.y, 50, 50);
pos.add(vel);
}
// Function to check the position
// of ball must be wthin screen.
void checkValid(){
if(pos.x <= 25 || pos.x >= width - 25){
vel.x *= -1;
// Change in colour when it hit the wall.
col = floor(random(0 ,255));
}
if(pos.y <=25 || pos.y >= height - 25){
vel.y *= -1;
// Change in colour when it hit the wall.
col = floor(random(0 ,255));
}
}
输出:
在模拟器上运行
要在模拟器上运行,我们必须安装它。
要查看它是否已安装,请转到C:\Users\Documents\Processing\android\sdk必须有一个文件夹名称 Emulator。要运行,请单击“在模拟器上运行”。
在控制台中:
输出:
Note: If you can’t able to run on the emulator then open processing.exe in administrator mode.