Author Topic: Processing  (Read 1036 times)

Tomaaz

  • Guest
Processing
« on: 25. August 2016, 19:59:51 »
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: 01. September 2016, 23:30:16 »
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.

John

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
Re: Processing
« Reply #2 on: 01. September 2016, 23:45:25 »
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: 01. September 2016, 23:48:51 by John »

Tomaaz

  • Guest
Re: Processing
« Reply #3 on: 02. September 2016, 12:49:10 »
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.

John

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
Re: Processing
« Reply #4 on: 02. September 2016, 18:49:57 »
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: 02. September 2016, 20:05:44 »
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

  • Regular Member
  • Sr. Member
  • *
  • Posts: 272
    • View Profile
Re: Processing
« Reply #6 on: 02. September 2016, 20:13:00 »
...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: 02. September 2016, 20:18:02 by Aurel »
new basic pro forum on;
http://basicpro.spacefor.site/smf/
GUEST posting enabled

John

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
Re: Processing
« Reply #7 on: 02. September 2016, 21:20:43 »
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: 02. September 2016, 22:23:14 »
...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. ;)

John

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
Re: Processing
« Reply #9 on: 03. September 2016, 03:11:18 »
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: 03. September 2016, 09:14:38 by John »

Tomaaz

  • Guest
Re: Processing
« Reply #10 on: 03. September 2016, 10:41:04 »
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).

John

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
Re: Processing
« Reply #11 on: 03. September 2016, 10:50:59 »
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: 03. September 2016, 10:57:18 »
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.

John

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
Re: Processing
« Reply #13 on: 03. September 2016, 11:06:39 »
My guess is recursion is triggering GC.

I'm using it correctly.

Tomaaz

  • Guest
Re: Processing
« Reply #14 on: 03. September 2016, 11:14:13 »
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. ;)