Ron Jensen - 2014-07-11

I've been doing a lot of volunteer work on's computer programming help page, answering questions and providing help to people new to programming in general. They use processing.js as an add-on library to javascript. It provides several graphics functions like rect(), ellipse(), triangle(), etc. Many times people will draw pretty intense pictures containing tens of these command and then ask for help animating them. To set up the animations its often necessary to shift the x and y coordinates they used and add variables to them. That's where Notepad++ and Python come in...

I would like to be able to parse the source code, and when it finds a call like 'rect(10,20,30,40)' it would subtract an entered value from the first argument (the x position) and the second argument (the y position) and leave the third and fourth (width and height) untouched. Other calls, like triangles contain 3 x/y pairs so the program would need to process all three pairs.

Also, optionally it would be nice to add a variable into the call like 'rect(10+xPos,20+yPos,30,40)'

I'm looking for hints on how to accomplish these tasks since Python isn't a native language for me.


P.s., here's a quick sample of what I usually need to process. fill() is untouched, rect() has x,y as the first two arguments, quad() is 4 x,y pairs.

//box 1
fill(125, 47, 11);
rect(85, 220, 50, 50);
rect(135, 240, 12, 60);
rect(135, 290, 25, 10);
quad(160, 190, 110, 190, 85, 220, 135, 220);
quad(160, 190, 135, 220, 135, 270, 160, 240);
rect(105, 270, 13, 40);
rect(105, 300, 25, 10);