实验六 大数据可视化工具—Processing(一)
指路->>>Processing简介和环境搭建
实验目的
了解Processing数据可视化的特点
掌握Processing的简单操作
能够使用Processing绘制简单形状
实验内容和主要步骤
1练习掌握Processing的安装和基本操作方法
下载Procession
https://processing.org/download/
(2)解压压缩包
(3)图形环境
在 Processing 内进行开发涉及到的是 PDE 和显示窗口。size 关键字以像素为单位定义了显示窗口的大小并且通常都是 Processing 应用程序内的首要步骤。
(4)定义背景和颜色
2熟悉Processing的绘制功能
(1)绘制像素点
使用 set 函数绘制单个像素点。此函数接受显示窗口内的 x,y 坐标以及作为颜色的第三个参数。Processing 也有一个类型,称为 color,通过它,可以定义用于某个操作的颜色。
(2)绘制一个四边形
3练习使用Processing绘制点、线、圆、椭圆、曲线等
(1)利用procession绘制形状
(2)随机绘制多个四边形
实验七 大数据可视化工具—Processing(二)
实验目的
- 掌握元胞自动机的概念及构建方法
- 利用Processing绘制森林火灾模型
实验内容和主要步骤 - 复习如何使用Processing绘制点、线、圆、椭圆、曲线等
- 练习使用Processing绘制点、线、圆、椭圆、曲线等
(1) 利用procession绘制形状
(2)随机绘制多个四边形
- 练习使用Processing构建二维元胞自动机并在其基础上构建一个森林火灾蔓延的可视化模型
(1) 编写代码
int[][][] pix = new int[2][400][400];
int toDraw = 0;
int tree = 0;
int burningTree = 1;
int emptySite = 2;
int x_limit = 400;
int y_limit = 400;
color brown = color(80, 50, 10); // brown
color red = color(255, 0, 0); // red;
color green = color(0, 255, 0); // green
float pGrowth = 0.01;
float pBurn = 0.00006;
boolean prob( float p )
{
if (random(0, 1) < p) return true;
else return false;
}
void setup()
{
size(400, 400);
frameRate(60);
/* Initialize to all empty sites */
for (int x = 0; x < x_limit; x++) {
for (int y = 0; y < y_limit; y++) {
pix[toDraw][x][y] = emptySite;
}
}
}
void draw()
{
update();
for (int x = 0; x < x_limit; x++) {
for (int y = 0; y < y_limit; y++) {
if (pix[toDraw][x][y] == tree) {
stroke( green );
} else if (pix[toDraw][x][y] == burningTree) {
stroke( red );
} else stroke( brown );
point( x, y );
}
}
toDraw = (toDraw == 0) ? 1 : 0;
}
void update()
{
int x, y, dx, dy, cell, chg, burningTreeCount;
int toCompute = (toDraw == 0) ? 1 : 0;
for (x = 1; x < x_limit-1; x++) {
for (y = 1; y < y_limit-1; y++) {
cell = pix[toDraw][x][y];
// Survey area for burning trees
burningTreeCount = 0;
for (dx = -1; dx < 2; dx++) {
for (dy = -1; dy < 2; dy++) {
if ((dx == 0) && (dy == 0)) continue;
else if (pix[toDraw][x+dx][y+dy] == burningTree) burningTreeCount++;
}
}
// Determine next state
if (cell == burningTree) chg = emptySite;
else if ((cell == emptySite) && (prob(pGrowth))) chg = tree;
else if ((cell == tree) && (prob(pBurn))) chg = burningTree;
else if ((cell == tree) && (burningTreeCount > 0)) chg = burningTree;
else chg = cell;
pix[toCompute][x][y] = chg;
}
}
}
(2) 运行
(3) 模型演示
关注公众号:Time木
一起学习交流