Git Product home page Git Product logo

Comments (7)

Gaweph avatar Gaweph commented on September 17, 2024

The global.d.ts has been created so that you do not have to import the 'p5' module. It exposes both global and instanced p5.

If you would like to use import instead then you can do the following:

  1. Delete global.d.ts
  2. Remove/Change Module setting in tsconfig,.json

You should then be able to do something like the following:

import * as p5 from 'p5';
let sketch = (p: p5) => {    
    p.setup = () =>{

    }

    p.draw = () =>{

    }
}
new p5(sketch);

from p5-typescript-starter.

fcin avatar fcin commented on September 17, 2024

Hey, thanks, it worked however some functions are unavailable, such as color or radians. Do you know what is the correct way to use them? I'm trying to use p5.color('#777');, but I'm getting 'Cannot find name color' error.

from p5-typescript-starter.

fcin avatar fcin commented on September 17, 2024

Sorry I got confused. I think I have to pass it as a parameter or make it global.

from p5-typescript-starter.

fcin avatar fcin commented on September 17, 2024

Update: It compiles without errors, but I still get an error in the browser saying

Uncaught ReferenceError: define is not defined
    at build.js:1

I also set "module": "amd", but no luck.

from p5-typescript-starter.

Gaweph avatar Gaweph commented on September 17, 2024

This app has been written to expect the p5.min.js in the head of the HTML page and so does not use the require methodology (global.d.ts exposes the p5.js codebase for use in the ts files).

Does this help:
https://stackoverflow.com/questions/34675659/define-is-not-defined-in-nodejs-typescript-app

Sorry I'm not much help.

from p5-typescript-starter.

fcin avatar fcin commented on September 17, 2024

Hey thanks, I replaced dependencies wiith parcel-bundle so that I don't have to provide .tsconfig and it seems to be working.
In my index.html I have:

<body>
  <script src="./src/sketch.ts"></script>
</body>

And I can execute parcel index.html to build and run everything

from p5-typescript-starter.

Gaweph avatar Gaweph commented on September 17, 2024

Brilliant :)

from p5-typescript-starter.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.