Comments (3)
looking into this further...
the problem is if you link a sketch.js script with code something like
background(255, 0, 0);
rect(0, 0, 50, 50);
without setup and draw, it gets evaluated before the page body is loaded, and before the pCreate() function is called via onload.
one way around this is to stick the js link in the body, however, this is a little confusing. also, if there is no createGraphics() call, there is no canvas even if the body is loaded because the default canvas gets created in pCreate.
workaround using requirejs or something?
another option is to do something more like what current processingjs does, requiring you to link the script as a data-source in a div. not sure which would be the least confusing for users.
I was thinking maybe bocoup might have some ideas on this one?
from p5.js.
Oh! Yes of course. JS is so loose that these problems must come up all the time, but unfortunately it means we need to be so clear with pjs so the pjs model is
- easy to use
- can still play nice with other libs
I am spending today working on pjs stuff, I will think about this idea, and also look into the 'undefined' test and the color stuff.
from p5.js.
Ben at Bocoup had two suggestions for this problem, neither having to do with loading hacks but more conceptual changes:
- Require that people call setContext('someCanvas') and if that canvas isn't in the HTML, create it. I sort of like this idea because it starts solidifying the concept that you this state-driven and you need to set the context. However, I don't love calling it setContext and would like us to consider calling it setCanvas. I am not 100% on this but I like the conceptual clarity and also how it sort of maps to the DOM, so that later on people realize they are treating DOM elements. When I asked him if it would be confusing for a beginner to have to type out the following:
setCanvas('a');
background(255, 0, 0);
rect(0, 0, 50, 50);
He said we could say "before you can draw you need to tell pjs where to draw, because iet's possible to have multiple canvases"
- Load pjs.js at the bottom of the file, and require that they make a
<canvas></canvas>
in the HTML, which guarantees it will exist.
I am not sure, these ideas seem nice because they deal with the DOM directly and aren't overly complex.
On the other hand, they're not quite as sand-boxed as we were previously thinking.
Thoughts?
Ping me on GChat if you see me there and want to discuss today or tomorrow!
from p5.js.
Related Issues (20)
- [p5.js 2.0 RFC Proposal]: A visual loading indicator in place of the current "Loading" text HOT 7
- Add guideline about chaining to style guide HOT 2
- [p5.js 2.0 RFC Proposal]: expand keyIsDown() to work with characters as arguments
- [p5.js 2.0 RFC Proposal]: New Document outlining FAQs & Guidelines on Licensing & Usage
- [p5.js 2.0 RFC Proposal]: Transitioning to a simpler, less complex License HOT 2
- Force Git Squash and Git Rebase before every PR being merged HOT 6
- cursor() - the image not displayed as the cursor HOT 5
- [p5.js 2.0 RFC Proposal]: Batching for the rendering of objects. HOT 14
- [p5.js 2.0 RFC Proposal]: Publish original proposals through new proposal form HOT 4
- Beginning of WebGL curves don't have a cap since v1.8 HOT 2
- Introduce Depth Access for Filters Functionality HOT 2
- 1.9.1 Release HOT 5
- Issue with fill artifact in WebGL mode when rendering in LINE mode using beginShape
- Documentation: Clarification of the necessity of `npm test` before `npm run build` for the Git Workflow portion of the Contributor Docs
- Allow p5 classes (like `p5.Color`, `p5.Vector` etc.) to be used outside of the browser (node, deno, bun etc.)? HOT 4
- p5.dom `select('form')` does not select `<form>` element HOT 1
- mouseButton contains incorrect value after pressing both mouse buttons and releasing one of them HOT 2
- Add a version of Processing's loadShader() function to p5.js HOT 4
- Why does the shadow appear above the image in this p5.js code? HOT 3
- Default fonts broken in 1.9.1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from p5.js.