mirror of
https://github.com/dyne/FreeJ.git
synced 2026-06-16 12:59:33 +02:00
new experimental support for processing scripts
a -p flag is added on commandline to run .pde scripts directly it makes use of the included processing.js glue a new scripts/processing directory is added with some examples to experiment with so far only a few processing scripts work
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
// simple loader of a processing script
|
||||
|
||||
include("processing.js");
|
||||
|
||||
scr = new Screen("sdl");
|
||||
if (!scr.is_initialized()) {
|
||||
scr.init(800,600);
|
||||
add_screen(scr);
|
||||
}
|
||||
|
||||
script = read_file("/home/jaromil/devel/freej/scripts/javascript/examples/ventaglio.pjs");
|
||||
//script = read_file("/home/jaromil/devel/freej/scripts/javascript/examples/simple.processing");
|
||||
//script = read_file("/home/jaromil/devel/freej/scripts/javascript/examples/recursion.pjs");
|
||||
//script = read_file("/home/jaromil/devel/freej/scripts/javascript/examples/sinewave.pjs");
|
||||
//script = read_file("/home/jaromil/devel/freej/scripts/javascript/examples/colorwheel.pjs");
|
||||
//script = read_file("/home/jaromil/devel/freej/scripts/javascript/examples/setupdraw.pjs");
|
||||
|
||||
|
||||
Processing(script);
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
// All Examples Written by Casey Reas and Ben Fry
|
||||
// unless otherwise stated.
|
||||
// The statements in the setup() function
|
||||
// execute once when the program begins
|
||||
void setup()
|
||||
{
|
||||
size(200, 200); // Size should be the first statement
|
||||
stroke(255); // Set line drawing color to white
|
||||
frameRate(30);
|
||||
}
|
||||
|
||||
float y = 100;
|
||||
|
||||
// The statements in draw() are executed until the
|
||||
// program is stopped. Each statement is executed in
|
||||
// sequence and after the last line is read, the first
|
||||
// line is executed again.
|
||||
void draw()
|
||||
{
|
||||
background(0); // Set the background to black
|
||||
y = y - 1;
|
||||
if (y < 0) { y = height; }
|
||||
line(0, y, width, y);
|
||||
echo("y = " + y);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/* BIG BANG(2.0)
|
||||
por Bernardo Silva C.
|
||||
*/
|
||||
float margen, sp,x,y,d,m,M;//variables
|
||||
|
||||
|
||||
void setup(){
|
||||
margen = 1;
|
||||
sp =150;
|
||||
size(500, 500);//tamaño
|
||||
smooth();//suavizado
|
||||
stroke(255,100);//linea
|
||||
fill(0,100);//relleno negro con transparencia
|
||||
strokeWeight(3.7);//grosor de la linea
|
||||
m=0.000005;// aumenta en ese valor
|
||||
background(0);//fondo negro
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void draw(){
|
||||
if(M<0||M>=0.004){//si M es menor que 0 o mayor que 0.0003
|
||||
m=-m;/* m es -m.entonces matematicamente hablando cuando sea
|
||||
postivo y sea mayor o igual que 0.0003,m se volvera negativo,por
|
||||
lo cual regrasa a comprimirse el big bang
|
||||
*/
|
||||
}
|
||||
fill(0,15);//transparencia para logra el difuminado
|
||||
rect(0,0,height,width);// cuadrado como fondo
|
||||
|
||||
M+=m;//variable en la que incrementa(escala)
|
||||
|
||||
|
||||
translate(height/2,width/2);//posición de la figura
|
||||
for(y=margen ; y < height; y += sp/2){
|
||||
for(x = margen; x < width; x += sp/12){
|
||||
//esta es la distancia
|
||||
d = 100+sqrt((mouseX - x)*(mouseX - x) + (mouseY - y)*(mouseY - y));
|
||||
scale(d * M);//se increneta la distancia en m
|
||||
quad(x,y,x,y,x,d,x,d);//cuadrilateros
|
||||
quad(x/12,y+6,x,d,x,d,x*2,d);
|
||||
rotate(100);//la figura se rota en torno a su posicion en x e y
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void keyPressed(){//si se aprieta el boton(f) se graba la foto
|
||||
saveFrame("BIG BANG.jpg");
|
||||
println("fotograma grabado");
|
||||
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@ float dx; // Value for incrementing X, to be calculated as a fun
|
||||
float[] yvalues; // Using an array to store height values for the wave (not entirely necessary)
|
||||
|
||||
void setup() {
|
||||
size(200,200);
|
||||
size(400,300);
|
||||
frameRate(30);
|
||||
colorMode(RGB,255,255,255,100);
|
||||
smooth();
|
||||
+8
-32
@@ -696,45 +696,21 @@ JS(entry_select) {
|
||||
|
||||
JS(include_javascript_file) {
|
||||
func("%u:%s:%s",__LINE__,__FILE__,__FUNCTION__);
|
||||
char *jscript;
|
||||
const char *debian_path = "share/doc/freej/scripts/javascript/lib";
|
||||
char temp[512];
|
||||
FILE *fd;
|
||||
|
||||
if(argc<1) JS_ERROR("missing argument");
|
||||
|
||||
char *jscript;
|
||||
jscript = js_get_string(argv[0]);
|
||||
|
||||
JsParser *js = (JsParser *)JS_GetContextPrivate(cx);
|
||||
|
||||
snprintf(temp,512,"%s",jscript);
|
||||
fd = fopen(temp,"r");
|
||||
if(!fd) {
|
||||
snprintf(temp,511,"%s/%s/%s",PREFIX,debian_path,jscript);
|
||||
fd = fopen(temp,"r");
|
||||
if(!fd) {
|
||||
error("included file %s not found", jscript);
|
||||
error("locations checked: current and %s/%s",
|
||||
PREFIX,debian_path);
|
||||
error("javascript include('%s') failed", jscript);
|
||||
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fd);
|
||||
|
||||
if (js->open(cx, obj, temp) == 0) {
|
||||
// all errors already reported,
|
||||
// js->open talks too much
|
||||
error("JS include('%s') failed", jscript);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
func("JS: included %s", jscript);
|
||||
|
||||
if( ! js->include(jscript) )
|
||||
error("javascript include not found: \"%s\"",jscript);
|
||||
|
||||
// if its the first script loaded, save it as main one
|
||||
// this is then used in reset to return at beginning stage
|
||||
if(global_environment->main_javascript[0] == 0x0)
|
||||
memcpy(global_environment->main_javascript, temp, 512);
|
||||
// if(global_environment->main_javascript[0] == 0x0)
|
||||
// memcpy(global_environment->main_javascript, temp, 512);
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
+30
-2
@@ -70,10 +70,11 @@ static const char *help =
|
||||
" . -g experimental opengl engine! (better pow(2) res as 256x256)\n"
|
||||
#endif
|
||||
" . -j <javascript.js> execute a javascript file\n"
|
||||
" . -p <processing.pde> execute a processing script (experimental)\n"
|
||||
" .\n";
|
||||
|
||||
// we use only getopt, no _long
|
||||
static const char *short_options = "-hvD:gas:S:nj:cgf:F";
|
||||
static const char *short_options = "-hvD:gas:S:nj:p:cgf:F";
|
||||
|
||||
/* this is the global FreeJ context */
|
||||
Context *freej = NULL;
|
||||
@@ -89,6 +90,7 @@ int width = 400;
|
||||
int height = 300;
|
||||
int magn = 0;
|
||||
char javascript[512]; // script filename
|
||||
char processing[512]; // script filename
|
||||
|
||||
int fps = 25;
|
||||
|
||||
@@ -102,10 +104,12 @@ bool opengl = false;
|
||||
|
||||
void cmdline(int argc, char **argv) {
|
||||
int res, optlen;
|
||||
FILE *fd; // tmp fd for checks
|
||||
|
||||
/* initializing defaults */
|
||||
char *p = layer_files;
|
||||
javascript[0] = 0;
|
||||
processing[0] = 0;
|
||||
|
||||
debug_level = 0;
|
||||
|
||||
@@ -185,7 +189,6 @@ void cmdline(int argc, char **argv) {
|
||||
break;
|
||||
|
||||
case 'j':
|
||||
FILE *fd;
|
||||
fd = fopen(optarg,"r");
|
||||
if(!fd) {
|
||||
error("can't open JS file '%s': %s", optarg, strerror(errno));
|
||||
@@ -198,6 +201,16 @@ void cmdline(int argc, char **argv) {
|
||||
}
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
fd = fopen(optarg,"r");
|
||||
if(!fd) {
|
||||
error("processing script file not found '%s': %s", optarg, strerror(errno));
|
||||
} else {
|
||||
snprintf(processing,512,"%s",optarg);
|
||||
fclose(fd);
|
||||
}
|
||||
break;
|
||||
|
||||
#ifdef WITH_OPENGL
|
||||
case 'g':
|
||||
opengl = true;
|
||||
@@ -345,6 +358,21 @@ int main (int argc, char **argv) {
|
||||
} else freej->interactive = true;
|
||||
}
|
||||
|
||||
/* execute processing */
|
||||
if( processing[0] ) {
|
||||
freej->interactive = false;
|
||||
|
||||
if( freej->js->include("processing.js") ) {
|
||||
// correctly included our extra library
|
||||
|
||||
char tmp[1024];
|
||||
snprintf(tmp,1023,"script = read_file(\"%s\");Processing(script);", processing);
|
||||
freej->js->parse(tmp);
|
||||
}
|
||||
|
||||
if(freej->quit) exit(1);
|
||||
else freej->interactive = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -47,9 +47,11 @@ class JsParser {
|
||||
public:
|
||||
JsParser(Context *_env);
|
||||
~JsParser();
|
||||
int include(const char* jscript); ///< include javascript libraries from known path (current or PREFIX)
|
||||
int open(const char* script_file);
|
||||
int open(JSContext *cx, JSObject *obj, const char* script_file);
|
||||
int use(JSContext *cx, JSObject *obj, const char* script_file);
|
||||
|
||||
int parse(const char *command);
|
||||
void stop();
|
||||
void gc();
|
||||
|
||||
@@ -384,6 +384,43 @@ void JsParser::init_class(JSContext *cx, JSObject *obj) {
|
||||
return;
|
||||
}
|
||||
|
||||
int JsParser::include(const char* jscript) {
|
||||
func("%u:%s:%s",__LINE__,__FILE__,__FUNCTION__);
|
||||
|
||||
const char *debian_path = "share/doc/freej/scripts/javascript/lib";
|
||||
int res = 0;
|
||||
char temp[512];
|
||||
FILE *fd;
|
||||
|
||||
snprintf(temp,512,"%s",jscript);
|
||||
fd = fopen(temp,"r");
|
||||
if(!fd) {
|
||||
snprintf(temp,511,"%s/%s/%s",PREFIX,debian_path,jscript);
|
||||
fd = fopen(temp,"r");
|
||||
if(!fd) {
|
||||
error("included file %s not found", jscript);
|
||||
error("locations checked: current and %s/%s",
|
||||
PREFIX,debian_path);
|
||||
error("javascript include('%s') failed", jscript);
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fd);
|
||||
|
||||
res = this->open(temp);
|
||||
if (!res) {
|
||||
// all errors already reported,
|
||||
// js->open talks a lot
|
||||
error("JS include('%s') failed", jscript);
|
||||
return res;
|
||||
}
|
||||
|
||||
func("JS: included %s", jscript);
|
||||
return res;
|
||||
}
|
||||
|
||||
/* return lines read, or 0 on error */
|
||||
int JsParser::open(const char* script_file) {
|
||||
return open(global_context, global_object, script_file);
|
||||
|
||||
Reference in New Issue
Block a user