RetroBASIC

Offtopic => Offtopic => Topic started by: Tomaaz on August 25, 2016, 05:59:51 PM

Title: Processing
Post by: Tomaaz on August 25, 2016, 05:59:51 PM
Processing 3 comes with a new Python Mode (http://py.processing.org/). 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 (http://p5js.org/) for Processing programmers and a version for Android (http://android.processing.org/).
Title: Re: Processing
Post by: Tomaaz 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.
Title: Re: Processing
Post by: ScriptBasic 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.


Title: Re: Processing
Post by: Tomaaz 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.
Title: Re: Processing
Post by: ScriptBasic 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.
Title: Re: Processing
Post by: Tomaaz 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. ;)
Title: Re: Processing
Post by: Aurel 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());
    }
}
Title: Re: Processing
Post by: ScriptBasic 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)
Title: Re: Processing
Post by: Tomaaz 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. ;)
Title: Re: Processing
Post by: ScriptBasic 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$

Title: Re: Processing
Post by: Tomaaz 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).
Title: Re: Processing
Post by: ScriptBasic 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$
Title: Re: Processing
Post by: Tomaaz 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.
Title: Re: Processing
Post by: ScriptBasic on September 03, 2016, 09:06:39 AM
My guess is recursion is triggering GC.

I'm using it correctly.
Title: Re: Processing
Post by: Tomaaz 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. ;)
Title: Re: Processing
Post by: ScriptBasic on September 03, 2016, 09:49:03 AM
Before I abandon V7, I'll post a comment on their forum and see if they have a fix.

Quote
V8 is Google's open source high-performance JavaScript engine, written in C++.

Sorry, not interested in trying to make a C++ JavaScript engine work as a C extension module for scriba.
Title: Re: Processing
Post by: Tomaaz on September 03, 2016, 03:58:13 PM
Duktape (http://duktape.org/) or Mujs (http://mujs.com/)?

What about creating library with Processing functions? That would be something. I even don't know how difficult that would be, but at least we are back on topic. ;)

EDIT I've tried the example with JSDB based on SpiderMonkey. It's much slower than Node, but just a little bit slower than Python.
Title: Re: Processing
Post by: ScriptBasic on September 03, 2016, 05:51:08 PM
Sorry about taking your thread OT. If V7 is still is of interest, I have a thread going on All BASIC.
Title: Re: Processing
Post by: Tomaaz on September 04, 2016, 09:19:23 PM
No worries. ;) I'm interested in JavaScript. It just shouldn't be in this topic. The problem is that, even if we start a new topic, I can't see anyone else joining us. So, it shouldn't be on this forum either. ;)
Title: Re: Processing
Post by: ScriptBasic on September 04, 2016, 09:50:55 PM
You could join the All BASIC forum and start a Processing thread.

I just reviewed your Python results again and noticed that like V7 the greater the recursion the more in the toilet it goes. Too bad V8 is C++. It looks fast.

I downloaded V8 and might take a shot at trying to integrate it with AIR's JADE C++ version of C BASIC.

What a nightmare trying to round up the dependencies to build V8. I took a peek at a couple samples and C++ isn't my cup of tea. I'm going to stay the V7 route for now.