Author Topic: Processing  (Read 5324 times)

Tomaaz

  • Guest
Processing
« on: August 25, 2016, 05:59:51 PM »
Processing 3 comes with a new Python Mode. It means that, instead of Java based syntax, you can write Processing code in Python. It is simple like that:

Code: [Select]
size(400, 400)
background(192, 64, 0)
for x in range(0, 255):
    stroke(x, 255, 255 - x)
    line(150, x, 270, 350)

There is also a JavaScript library for Processing programmers and a version for Android.

Tomaaz

  • Guest
Re: Processing
« Reply #1 on: September 01, 2016, 09:30:16 PM »
Javascript library is even more cool. Here is a very simple example (it comes with the editor):

Code: [Select]
function setup(){
  createCanvas(710, 400, WEBGL);
}

function draw(){
  background(250);
  rotateY(frameCount * 0.01);

  for(var j = 0; j < 5; j++){
    push();
    for(var i = 0; i < 80; i++){
      translate(sin(frameCount * 0.001 + j) * 100, sin(frameCount * 0.001 + j) * 100, i * 0.1);
      rotateZ(frameCount * 0.002);
      push();
      sphere(8, 6, 4);
      pop();
    }
    pop();
  }
}

HTML/Js files are attached. Just extract the archive and open index.html file in your web browser.

ScriptBasic

  • Guest
Re: Processing
« Reply #2 on: September 01, 2016, 09:45:25 PM »
Very cool Tomaaz!

The V7 JavaScript engine doesn't have browser resource support and is focused on UTF8 text processing. It seems easy to implement.


« Last Edit: September 01, 2016, 09:48:51 PM by John »

Tomaaz

  • Guest
Re: Processing
« Reply #3 on: September 02, 2016, 10:49:10 AM »
The V7 JavaScript engine doesn't have browser resource support...

As I understand it, to have an access to DOM, JavaScript engine needs to be embedded in a web browser. So, it's not focused on text processing - it just need to be build into a browser and given access to DOM. If you're thinking of using ScriptBasic instead Javascript in a browser, you would have to build your own custom browser for that. That would be pretty pointless as there are no websites that browser could interpret.

ScriptBasic

  • Guest
Re: Processing
« Reply #4 on: September 02, 2016, 04:49:57 PM »
No interest in embedding Script BASIC in a browser. I'm just using V7 for it's JSON, OOP and extensive library of JavaScript code that is available.

Tomaaz

  • Guest
Re: Processing
« Reply #5 on: September 02, 2016, 06:05:44 PM »
I'm just using V7 for it's JSON, OOP and extensive library of JavaScript code that is available.

I think that its speed is also worth mentioning. ;)

Aurel

  • Guest
Re: Processing
« Reply #6 on: September 02, 2016, 06:13:00 PM »
...and there is a Rust
mozzila project ...looks interesting even syntax is little bit more complex
than Processing ...which is easier to learn.
...and give me a break ..this thing have full support for winApi
not bad at all ...

Code: [Select]
winapi = "0.2"
user32-sys = "0.2"

main.rs:

extern crate winapi;
extern crate user32;
use std::ffi::OsStr;
use std::io::Error;
use std::iter::once;
use std::os::windows::ffi::OsStrExt;
use std::ptr::null_mut;

fn main() {
    let msg = "Hello, world!";
    let wide: Vec<u16> = OsStr::new(msg).encode_wide().chain(once(0)).collect();
    let ret = unsafe {
        user32::MessageBoxW(null_mut(), wide.as_ptr(), wide.as_ptr(), winapi::MB_OK)
    };
    if ret == 0 {
        println!("Failed: {:?}", Error::last_os_error());
    }
}
« Last Edit: September 02, 2016, 06:18:02 PM by Aurel »

ScriptBasic

  • Guest
Re: Processing
« Reply #7 on: September 02, 2016, 07:20:43 PM »
I'm just using V7 for it's JSON, OOP and extensive library of JavaScript code that is available.

I think that its speed is also worth mentioning. ;)

I see no degradation in Script BASIC execution calling V7 functions. I have static linked the V7 engine to the Script BASIC extension module. My js.so is less than 250K.  8)

Tomaaz

  • Guest
Re: Processing
« Reply #8 on: September 02, 2016, 08:23:14 PM »
...and there is a Rust

Aurel, Rust has nothing to do with Processing. Processing is easy, beginners-friendly, while Rust is a completely different beast. In fact, Processing is not a language at all. It's a general idea and set of functions that can be implemented in many languages. There is Java version, Python version, JavaSript and Ruby libraries. I can't see any connection between Processing and Rust, so why are you posting this here? Why didn't you start another topic? Let's try to keep this forum tidy and not to make it a complete mess. ;)

ScriptBasic

  • Guest
Re: Processing
« Reply #9 on: September 03, 2016, 01:11:18 AM »
It seems Script BASIC is faster with recursive functions and V7 gets slower the greater the recursion.

Code: [Select]
IMPORT js.bas

jscode = """
function fibonacci(n) {
  if (n <= 2) {
    return 1;
  } else {
    return fibonacci(n - 1) + fibonacci(n - 2);
  }
}   

print(fibonacci(24));
"""

jsobj = JS::CREATE()
results = JS::EXEC(jsobj, jscode, rtncode)
JS::DESTROY(jsobj)


jrs@laptop:~/sb/sb22/js$ time scriba js_fibonacci.sb
46368

real   0m1.273s
user   0m1.267s
sys   0m0.004s
jrs@laptop:~/sb/sb22/js$


Script BASIC native
Code: [Select]
FUNCTION Fibonacci(n)
  IF n <= 2 THEN
    Fibonacci = 1
  ELSE
    Fibonacci = Fibonacci(n - 1) + Fibonacci(n - 2)
  END IF
END FUNCTION

PRINT Fibonacci(24),"\n"


jrs@laptop:~/sb/sb22/test$ time scriba fibonacci.sb
46368

real   0m0.090s
user   0m0.076s
sys   0m0.008s
jrs@laptop:~/sb/sb22/test$

« Last Edit: September 03, 2016, 07:14:38 AM by John »

Tomaaz

  • Guest
Re: Processing
« Reply #10 on: September 03, 2016, 08:41:04 AM »
It seems Script BASIC is faster with recursive functions and V7 gets slower the greater the recursion.

Really? Try it with fibonacci(32) and fibonacci(36). I've tried it with Node and Python. Yes, with small recursion Python is faster, but then it can't compete with Node.

24

Quote
tomek@tomek-laptop ~/Documents $ time python3 untitled.py

real   0m0.063s
user   0m0.060s
sys   0m0.000s
tomek@tomek-laptop ~/Documents $ time nodejs 1.js

real   0m0.118s
user   0m0.112s
sys   0m0.004s

32

Quote
tomek@tomek-laptop ~/Documents $ time python3 untitled.py

real   0m0.908s
user   0m0.904s
sys   0m0.000s
tomek@tomek-laptop ~/Documents $ time nodejs 1.js

real   0m0.147s
user   0m0.140s
sys   0m0.004s

36

Quote
tomek@tomek-laptop ~/Documents $ time python3 untitled.py

real   0m6.068s
user   0m6.060s
sys   0m0.004s
tomek@tomek-laptop ~/Documents $ time nodejs 1.js

real   0m0.343s
user   0m0.336s
sys   0m0.008s

It looks like Node needs a little bit more time to start. If you'd test Julia, it would be the same (or, in fact, even worse).

ScriptBasic

  • Guest
Re: Processing
« Reply #11 on: September 03, 2016, 08:50:59 AM »
I could have lunch in the time V7 would take to do a fibonacci(32).

32
jrs@laptop:~/sb/sb22/test$ time scriba fibonacci.sb
2178309

real   0m3.648s
user   0m3.620s
sys   0m0.004s
jrs@laptop:~/sb/sb22/test$

Tomaaz

  • Guest
Re: Processing
« Reply #12 on: September 03, 2016, 08:57:18 AM »
I could have lunch in the time V7 would take to do a fibonacci(32).

Then, there must be something wrong with V7 or with the way you're using it.

ScriptBasic

  • Guest
Re: Processing
« Reply #13 on: September 03, 2016, 09:06:39 AM »
My guess is recursion is triggering GC.

I'm using it correctly.

Tomaaz

  • Guest
Re: Processing
« Reply #14 on: September 03, 2016, 09:14:13 AM »
My guess is recursion is triggering GC.

I'm using it correctly.

Then you need to add 1 to 7 and go for Google's JavaScript engine. ;)