I will summarize how to execute Processing.py (Python Mode of Processing) with Visual Studio Code (hereinafter VS Code). The author's environment is Windows 10 (64bit). The file path etc. are described assuming that this environment is used. Please read as appropriate.
First, I will clarify the principle of implementation.
Processing.py runs on Jython (a Java implementation of Python). Therefore, you can get the jar file that executes Processing.py and use it to move the sketch without using the Processing IDE.
Roughly summarized, it looks like this.
processing-py.jar
Both will be thrown to other sites as they are likely to be long.
How to install VS Code:
How to install the JDK:
If you run java -version
on the command line and get the following result, the JDK installation is successful.
$ java -version
java version "14.0.2" 2020-07-14
Java(TM) SE Runtime Environment (build 14.0.2+12-46)
Java HotSpot(TM) 64-Bit Server VM (build 14.0.2+12-46, mixed mode, sharing)
It is okay if the specific numbers are slightly off.
Open VSCode, open a button like "field" on the left side, and open the extension management menu. Search for "code runner" in the search box and install the one in the photo above.
processing-py.jar
https://py.processing.org/tutorials/command-line/ There is a file in the middle of the "Requirements" section of this page. I will quote it.
tgz or zip will be downloaded. Unzip it and place it wherever you like.
Suppose you create a folder called pyprocessing
and put sketches etc. in this folder.
First, place processing-py.jar
in the folder downloaded in the previous section.
Next, tweak the VS Code settings. Set Python> Linting: Enabled
to false
in the workspace. This is only if the python extension is already installed.
Notice that we are changing the settings in the workspace, as shown in the photo. Failure to do this will affect other projects.
Next, put sketch.py
(sketch file). Describe the following contents in sketch.py
.
def setup():
size(400,400)
def draw():
background(255)
fill(0)
ellipse(mouseX, mouseY, 50, 50)
When you open sketch.py
, you will be notified at the bottom right of the screen (if it is not already there) that you want to install the python extension. It doesn't matter whether you install it or not. If you have installed it, you need to change the above settings.
Then change the settings. Change the Code Runner: Custom Command
in the workspace to java -jar processing-py.jar sketch.py
. It is as shown in the picture below.
The directory structure is as follows.
pyprocessing
|- .vscode
| |- settings.json
|- processing-py.jar
|- sketch.py
The settings you changed earlier are recorded in settings.json
. I will check it just in case.
settings.json
{
"code-runner.customCommand": "java -jar processing-py.jar sketch.py",
"python.linting.enabled": false
}
You are now ready. Press Ctrl + alt + K and the sketch will work after a while. If you hover your mouse in the sketch window and a black circle appears, you are successful.
https://py.processing.org/tutorials/command-line/ More information can be found in the Processing Libraries section here. A list of libraries can be found at Libraries | Processing.org. The story from here is assumed to be Windows. If you are using another OS, please read as appropriate.
As a general premise, you need JRE 8u202 (the latest JRE is 14). * JRE: Java Runtime Environment
If you want to download JRE8u202 now, you need to sign in to Oracle. When you create an Oracle account, you have to provide quite a lot of personal information. To be honest, the threshold is high, but I will introduce it for the time being.
You also need to install the Processing IDE (https://processing.org/reference/environment/).
First of all, please download and install JRE from the link above. I will pass the PATH later.
Next, create a batch file runner.bat
(shell script runner.sh
on other OS). Describe the following contents.
runner.bat
@echo off
cd /d %~dp0
set PATH=C:\Program Files\Java\jre1.8.0_202\bin;
java -version
java -jar processing-py.jar sketch.py
echo Finished.
exit 0
This file follows the flow shown below.
@echo off
: By default, the command to be executed is output, so turn it off.cd / d% ~ dp0
: Makes the current directory (pyprocessing
) the current directory.set PATH ...
: Change the reference of the java
command to that of 8u202
.java -version
: Outputs the version of java
for confirmation.java -jar processing-py.jar sketch.py
: sketch.py
.: Outputs
Finished.`. This is to confirm the end of the sketch.I'm not sure about other OS, so I will post a site that seems to be helpful.
Then create a libraries
folder inside the pyprocessing
(the directory with the sketches). We will add various libraries here.
As an example, I will introduce the installation of PixelFlow. First, open "Add Mode ..." in the Processing IDE.
It is the upper right of the screen.
The Contribution Manager will open. In the Libraries tab, search for PixelFlow, select it and press Install at the bottom right.
Wait for the installation to complete. After installation, open Documents \ Processing \ libraries
in Explorer. There should be a folder called PixelFlow
. Move this folder into pyprocessing \ libraries
.
Documents / Processing / libraries
regardless of the OS.You are now ready. I will write something as a trial. * The code is based on note written by @ryotako.
sketch.py
add_library("PixelFlow")
def setup():
size(400, 400, P2D) #P2D specification is required because GLSL is used
#Object that simulates fluid(DwFluid2D)When,
#Create PGraphics to use for drawing results
global F,G
F=DwFluid2D(DwPixelFlow(this), width, height, 1) #The last argument is the resolution. Increasing the value will result in a coarse simulation
G=createGraphics(width, height, P2D)
def draw():
#Initialize PGraphics.
#If you do not do this, it will be overlaid on the previous result
with G.beginDraw():
G.background(255)
#Specify the conditions for fluid simulation
#Note that the Y coordinate is upside down in Processing and GLSL.
F.addTemperature(mouseX, height-mouseY, 40, 1)
#Take the fluid simulation one step
F.update()
#Drawing the result of a fluid simulation
#The last argument is 0:Concentration, 1:Temperature, 2:Pressure, 3:Speed, 4:Presence or absence of obstacles
F.renderFluidTextures(G, 1)
image(G,0,0)
You are now ready. Execute the batch file / shell script in the terminal. The batch file is . \ Runner.bat
, and the shell script is sh runner.sh
. It would have been successful if some kind of amazing fluid animation came out, but for some reason it didn't work for me. Ask the Processing community, so I hope you find it helpful.
When I tried using a library called Sound
, it worked. At present, it seems that the libraries that can be used are limited.
Changing the custom command
setting of the Code Runner extension to. \ Runner.bat
or sh runner.sh
will make sketching a little easier.
https://py.processing.org/tutorials/command-line/ https://discourse.processing.org/t/tutorial-running-python-mode-in-vscode/7716 https://github.com/processing/processing/wiki/How-to-Install-a-Contributed-Library#manual-install
Recommended Posts