Pyprocessing is slower than Processing in Python mode apprently, and how to improve its performance?
(1) Run pyprocessing: python D:/myPyprocessing.py
---------myPyprocessing.py Code--------------
from pyprocessing import *
import Image
i = 0
purx = 0
pury = 0
size(1269,1425)
def setup():
fill(126)
background(102)
background(255)
myFont = createFont("Georgia", 32, True)
textFont(myFont,10)
textAlign(LEFT)
smooth()
def arrow(x1, y1, x2, y2):
line(x1, y1, x2, y2)
pushMatrix()
translate(x2, y2)
a = atan2(x1-x2, y2-y1)
rotate(a)
line(0, 0, -5, -5)
line(0, 0, 5, -5)
popMatrix()
def mousePressed():
global i, purx, pury
if (i > 0):
arrow(purx, pury, mouse.x, mouse.y)
if (mouse.pressed and (mouse.button == LEFT)):
# scribble a line with the mouse
line (pmouse.x, pmouse.y, mouse.x, mouse.y)
i += 1
purx = mouse.x
pury = mouse.y
text(str(i), mouse.x, mouse.y)
fill(red(color(255, 200, 0)), 0, 0)
ellipse(mouse.x, mouse.y, 5, 5)
else:
stroke(0)
def draw():
fill(color(255, 204, 0))
if (key.pressed and key.char == 'q'):
save("F:\\processing\\output1.png")
exit()
run()
(2) You can run the processing in Python mode, and it is quickly: java -jar processing-py.jar D:\prTest.py
--------D:\prTest.py----------
i = 0
purx = 0
pury = 0
def setup():
img = loadImage("F:\\picT\\capturesf92da6102a5c81d3168b10c8d02deda1.png")
size(img.width, img.height)
fill(126)
background(102)
background(255)
myFont = createFont("Georgia", 32, True)
textFont(myFont,15)
textAlign(LEFT)
smooth()
def arrow(x1, y1, x2, y2):
line(x1, y1, x2, y2)
pushMatrix()
translate(x2, y2)
a = atan2(x1-x2, y2-y1)
rotate(a)
line(0, 0, -5, -5)
line(0, 0, 5, -5)
popMatrix()
def mousePressed():
global i, purx, pury
if (i > 0):
arrow(purx, pury, mouseX, mouseY)
if (mousePressed and (mouseButton == LEFT)):
i += 1
purx = mouseX
pury = mouseY
text(i, mouseX, mouseY)
fill(red(color(255, 200, 0)), 0, 0)
ellipse(mouseX, mouseY, 5, 5)
else:
stroke(0)
def draw():
fill(color(255, 204, 0))
saveFrame("F:\\processing\\output2.png")