RetroBASIC
Offtopic => Offtopic => Topic started 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:
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/).
-
Javascript library is even more cool. Here is a very simple example (it comes with the editor):
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.
-
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.
-
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.
-
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.
-
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. ;)
-
...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 ...
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());
}
}
-
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)
-
...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. ;)
-
It seems Script BASIC is faster with recursive functions and V7 gets slower the greater the recursion.
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
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$
-
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
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
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
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).
-
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$
-
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.
-
My guess is recursion is triggering GC.
I'm using it correctly.
-
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. ;)
-
Before I abandon V7, I'll post a comment on their forum and see if they have a fix.
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.
-
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.
-
Sorry about taking your thread OT. If V7 is still is of interest, I have a thread going on All BASIC.
-
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. ;)
-
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.