P5.js inside sBasic

Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

P5.js inside sBasic

Post by Operator »

After some trials and based on rBytes great
weather example you can now code P5 inside
sBasic if desired.

First: turn capsyntax off
SET EDITOR CAPSYNTAX OFF
to avoid changes of the P5 code or P5-lib
when opened in the sB editor.

Download the P5-Folder : Dropbox-link
below...

Use P5 -Test- .tx to run the sample code
and P5_code_2.tx to edit/change the
P5 snippet...

Link:
https://www.dropbox.com/sh/xi1yc1myr1x3 ... P1KAa?dl=0
Attachments
image.jpg
image.jpg (129.07 KiB) Viewed 5890 times
image.jpg
image.jpg (146.07 KiB) Viewed 5890 times

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: P5.js inside sBasic

Post by GeorgeMcGinn »

Hello,

WOW - this is great!

I do have one question. What do I need to set to run this on an iPad? (I have an iPad Air 2, but there must be a way to set the canvas size based on the sb system variable that tells you what device is being used?

Or is this a limitation of P5?

This is still awesome. Maybe we can get VBScript/ASP working inside a SmartBASIC program ;) ;) ;)

George.

Operator wrote:After some trials and based on rBytes great
weather example you can now code P5 inside
sBasic if desired.

First: turn capsyntax off
SET EDITOR CAPSYNTAX OFF
to avoid changes of the P5 code or P5-lib
when opened in the sB editor.

Download the P5-Folder : Dropbox-link
below...

Use P5 -Test- .tx to run the sample code
and P5_code_2.tx to edit/change the
P5 snippet...

Link:
https://www.dropbox.com/sh/xi1yc1myr1x3 ... P1KAa?dl=0
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

Re: P5.js inside sBasic

Post by Operator »

For iPad screen-size fit...
In P5 -Test- .tx change browser window size..
In P5_code_2.tx change w, h ... to your
device screen_size in sBasic...

As far as I know ... in P5 you have to set the canvas-size first, then the width- and height-values can be called inside function draw with width,height...
P5 does't have a command to detect the
screen_size as in sBasic (as tested so far).

If you find a way..., just let us know..

Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

Re: P5.js inside sBasic

Post by Operator »

As for VBscript..., guess it is also possible
following a similar scheme as for P5...


http://www.csidata.com/custserv/onlineh ... s/vbs9.htm

https://www.tutorialspoint.com/vbscript ... cement.htm

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: P5.js inside sBasic

Post by GeorgeMcGinn »

Thanks for this and VBScript reply.

I will let you know about the screen sizing issue when I run my fist JScript program!

George.
Operator wrote:For iPad screen-size fit...
In P5 -Test- .tx change browser window size..
In P5_code_2.tx change w, h ... to your
device screen_size in sBasic...

As far as I know ... in P5 you have to set the canvas-size first, then the width- and height-values can be called inside function draw with width,height...
P5 does't have a command to detect the
screen_size as in sBasic (as tested so far).

If you find a way..., just let us know..
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: P5.js inside sBasic

Post by rbytes »

Thanks for pioneering in this new direction. There seems to be no limit to what can be done with sB and your imagination!

Got the page set for full iPad Air size, 1024 x 768. Also I set toolbar off to use the whole screen.

Very responsive even at full size! :D

A suggestion on detecting and using screen size. No problem incorporating a statement into the test file, since it is written in sB. You could then have the test file overwrite new lines 6 and 7 into the code file that contain the desired values for var w and var h.
Attachments
IMG_7616.PNG
IMG_7616.PNG (302.38 KiB) Viewed 5866 times
The only thing that gets me down is gravity...

Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

Re: P5.js inside sBasic

Post by Operator »

:D :D :D
Great Art-Work...

You already got rid of the toolbar...,
so if you want full screen edit P5_html_1
and set: padding: 1px; to 0px...

Re manipulating the P5 code file is a good idea to set the screen/canvas size ...
... the ultimate goal would be having a function
in sB and P5 ( guess in the browser js/html code) so they could exchange data during program execution, but this goes beyond my actual skills...

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: P5.js inside sBasic

Post by rbytes »

I hope you are able to create such a function. There are a lot of JavaScript code snippets on the web. I will keep on the lookout.

I should have thought of the padding setting. I just set the browser top right corner to -1,-1 and the size to sw+1, sh+1 to get rid of the 1 pixel bar, but I will go back and do it properly. :lol:
The only thing that gets me down is gravity...

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: P5.js inside sBasic

Post by rbytes »

Here is the P5 folder all set up to work on iPad. I also added a file P5_code_2a.tx that can be executed instead of file P5_code_2.tx
It will produce today's date at the top left of the browser. To run it, open P5 -Test- .tx and change the name of the code file From P5_code_2.tx to P5_code_2a.tx. I also enclosed a very simple program that lets you set Capsyntax off when you enter the folder.

https://www.dropbox.com/sh/8q6gpliqdlrs ... hsK9a?dl=0

There are many JavaScript snippets available at W3 Schools, all with demos to show them working. I have tried copying some of them into code files and substituting them for the supplied code file. Many of them don't work, for example the 3D primitives, so I am assuming that we don't have the libraries downloaded to run them. One that does work is in the folder I posted. It shows the current day and date. I tried a few variations to try to enlarge the very tiny font used, but no luck so far. On the positive side, I have been able to modify the supplied code file to change colors, font sizes, draw width and even the shape and shape size that is used for drawing.
The only thing that gets me down is gravity...

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: P5.js inside sBasic

Post by rbytes »

Here is the official site for P5 JavaScript, with lots of tutorials including examples of code, and the complete reference manual.

https://p5js.org

However there are quite a few different libraries, and if the script you download requires a library that has not been implemented in sB, it won't run. Operator, perhaps you could clarify which libraries you included and any plans you have to expand the selection. That may give other members more incentive to download and try out scripts.
The only thing that gets me down is gravity...

Post Reply