Skip to content

Instantly share code, notes, and snippets.

@Badbird5907
Last active May 23, 2024 04:55
Show Gist options
  • Save Badbird5907/3385ad2fcf0e0745eddc002530ea6df8 to your computer and use it in GitHub Desktop.
Save Badbird5907/3385ad2fcf0e0745eddc002530ea6df8 to your computer and use it in GitHub Desktop.
Run Processing
from Processing3 import *
add_library('minim')
import random
def setup():
global frames, dFrame, fps
size(800,600)
frames = 0
fps = 0
dFrame = millis()
def draw():
global state
clear()
background(255, 255, 255)
# fps
global frames, dFrame, fps
frames += 1
if millis() - dFrame > 1000:
#print(frames)
fps = frames
frames = 0
dFrame = millis()
fpsColor = (0, 0, 0)
if fps > 55:
fpsColor = (0, 255, 0)
elif fps > 40:
fpsColor = (255, 255, 0)
else:
fpsColor = (255, 0, 0)
textSize(16)
fill(fpsColor[0], fpsColor[1], fpsColor[2])
text("FPS: " + str(fps), 10, 30)
def mouseReleased():
return
# usage: ./run.ps1 file.pyde
$script = $args[0]
$jre = "C:\Program Files\Processing\py\jre\bin\java.exe"
$processing = "C:\Program Files\Processing\py\processing-py.jar"
# check if script exists
if (-not (Test-Path $script)) {
# if the -RunFirst parameter is set, run the first script found
if ($args -contains "-RunFirst") {
$script = Get-ChildItem -Path "." -Filter "*.pyde" | Select-Object -First 1
if ($script -eq $null) {
Write-Host "No script found in the current directory."
exit
}
} else {
Write-Host "File not found."
exit
}
}
Write-Host "Running $script..."
# pre-process the script
$scriptTemp = "_temp_script.pyde"
Remove-Item $scriptTemp -ErrorAction SilentlyContinue
Copy-Item $script $scriptTemp
# remove the import
$firstLine = Get-Content $script -TotalCount 1
if ($firstLine -eq "from Processing3 import *") {
$content = Get-Content $scriptTemp
$content = $content | Select-Object -Skip 1
$content | Set-Content $scriptTemp
}
# execute
& $jre -jar $processing $scriptTemp
# delete the temp file
Remove-Item $scriptTemp -ErrorAction SilentlyContinue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment