293

ubuntu 22.04 安装 Processing

乐果   发表于   2023 年 11 月 21 日 标签:ubuntuprocessing

首先简单介绍一下, Processing 是一种计算机语言,以 JAVA 语法为基础, 可转化成 JAVA 程序,不过在语法上简易许多。

所有的原始代码及开发环境开放,主要用于艺术、影像、影音的设计与处理。

它能做啥

自然之美,浮游天地

频率之美,傅里叶变换

编码分析声音频谱,抓取节奏信号,转换为光电影像

三角之美,周而复始

编写代码把时间转换成三角函数的弧度,运算结果化作图形的属性,制作出周而复始的Gif影像:

迭代之美,一蹴而就

使用编程基本语句之一,Iteration迭代,优雅的矢量绘图大体量图形

噪声之美,时空转换

Perlin Noise算法把时间的变化转换在空间维度之上,计算出连续随机的坐标,用在静态动态图形之上,呈现数学信号上的噪声之美

下载

https://processing.org 上下载最新的 linux 64bit 版本 gzip 文件, 例如我当前下载的是 Processing4.3 版本

安装

解压后移动到 /opt/ 目录

添加快捷方式

/usr/share/applications 下新建新文件 processing-pde.desktop , 内容如下:

[Desktop Entry]
Version=4.3
Type=Application
Name=Processing IDE
Icon=/opt/processing-4.3/lib/icons/app-128.png
Exec=/opt/processing-4.3/processing
Comment=Processing IDE
Categories=Development;IDE;
Terminal=false


附: 用于从图片中提取 LCD 单色数组的代码

// THIS IS NOT ARDUINO CODE!  Runs in Processing IDE (www.processing.org).
// Convert image to C header file suitable for the Adafruit_Thermal library.

void setup() {
  // Select and load image
  selectInput("Select image file to convert:", "processImage");
}

void processImage(File image) {
  String      filename, basename;
  PImage      img;
  PrintWriter output;
  int         pixelNum, byteNum, bytesOnLine = 99,
              x, y, b, rowBytes, totalBytes, lastBit, sum;
  println("Loading image...");
  filename = image.getPath();
  img      = loadImage(image.getPath());

  // Morph filename into output filename and base name for data
  x = filename.lastIndexOf('.');
  if(x > 0) filename = filename.substring(0, x);  // Strip current extension
  x = filename.lastIndexOf('/');
  if(x > 0) basename = filename.substring(x + 1); // Strip path
  else      basename = filename;
  filename += ".h"; // Append '.h' to output filename
  println("Writing output to " + filename);

  // Calculate output size
  rowBytes   = (img.width + 7) / 8;
  totalBytes = rowBytes * img.height;
  // Convert image to B&W, make pixels readable
  img.filter(THRESHOLD);
  img.loadPixels();

  // Open header file for output (NOTE: WILL CLOBBER EXISTING .H FILE, if any)
  output = createWriter(filename); 

  // Write image dimensions and beginning of array
  output.println("#ifndef _" + basename + "_h_");
  output.println("#define _" + basename + "_h_");
  output.println();
  output.println("#define " + basename + "_width  " + img.width);
  output.println("#define " + basename + "_height " + img.height);
  output.println();
  output.print("static const uint8_t PROGMEM " + basename + "_data[] = {");

  // Generate body of array
  for(pixelNum=byteNum=y=0; y<img.height; y++) { // Each row...
    for(x=0; x<rowBytes; x++) { // Each 8-pixel block within row...
      lastBit = (x < rowBytes - 1) ? 1 : (1 << (rowBytes * 8 - img.width));
      sum     = 0; // Clear accumulated 8 bits
      for(b=128; b>=lastBit; b >>= 1) { // Each pixel within block...
        if((img.pixels[pixelNum++] & 1) == 0) sum |= b; // If black pixel, set bit
      }
      if(++bytesOnLine >= 10) { // Wrap nicely
          output.print("\n ");
          bytesOnLine = 0;
      }
      output.format(" 0x%02X", sum); // Write accumulated bits
      if(++byteNum < totalBytes) output.print(',');
    }
  }

  // End array, close file, exit program
  output.println();
  output.println("};");
  output.println();
  output.println("#endif // _" + basename + "_h_");
  output.flush();
  output.close();
  println("Done!");
  exit();
}

乐果   发表于   2023 年 11 月 21 日 标签:ubuntuprocessing

0

文章评论