processing.js

Can I define a property within an object prototype (method)?

℡╲_俬逩灬. 提交于 2021-02-05 09:10:28
问题 Question part 1: I've made an object constructor with properties in it, but I am wondering if I could define another property of the object within one of it's methods. For example: var Player = function(p1) { this.property1 = p1; this.property2 = 0; } then, can I define this.property3 in a method, like: Player.prototype.drawMethod = funtion() { this.property3 = 1; } and have it accessible, like: var obj = new Player(true); if (obj.property3 ===1 && obj.property1 === 1) { //code } else { obj

Using p5.sound.js in instance mode: 'p5.Amplitude() not a constructor'

冷暖自知 提交于 2020-05-27 02:36:11
问题 I am using an npm, webpack, babel environment to write an application with p5.js. To be able to have the sketch as a module, I have the sketch in instance mode and import the library and add-ons as modules: import p5 from 'p5'; import 'p5/lib/addons/p5.sound'; import 'p5/lib/addons/p5.dom'; Then I load them to the window inside my sketch: const sketch = (p5) => { window.p5 = p5; ... } new p5(sketch); When I try to use: amp = new p5.Amplitude() I get a 'p5.Amplitude is not a constructor' error

Using p5.sound.js in instance mode: 'p5.Amplitude() not a constructor'

冷暖自知 提交于 2020-05-27 02:34:07
问题 I am using an npm, webpack, babel environment to write an application with p5.js. To be able to have the sketch as a module, I have the sketch in instance mode and import the library and add-ons as modules: import p5 from 'p5'; import 'p5/lib/addons/p5.sound'; import 'p5/lib/addons/p5.dom'; Then I load them to the window inside my sketch: const sketch = (p5) => { window.p5 = p5; ... } new p5(sketch); When I try to use: amp = new p5.Amplitude() I get a 'p5.Amplitude is not a constructor' error

How to run Processing+Twitter4j sketch in broswer

北慕城南 提交于 2020-01-11 11:17:48
问题 I'm a newbie programmer practicing Processing and I recently developed a sketch that uses Twitter4j. When I run the sketch in Java mode from the Processing Development Environment it works perfectly. Also, when I export the sketch from Java mode the resulting application runs perfectly. However, when I switch to JavaScript mode and try to run the sketch the browser preview does not display anything. I believe the problem is related to Twitter4j because when I remove the Twitter4j-related code

Using Processing.js across multiple pages

久未见 提交于 2020-01-06 07:57:52
问题 I have a problem using processing.js across multiple pages. I have a master page (test.html) which loads, via jquery, all pages into a div named "contentarea". This is just an exerpt of "test.html", just so you get the idea: <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <script src="js/processing.js"></script> <script> $(document).ready(function(){$("#contentarea").load("page1.html"); etc... </script> <div id="contentarea">...</div> As you can see the

Using Processing's loadImage in JavaScript

烈酒焚心 提交于 2020-01-05 07:41:49
问题 I am using the Processing API to draw an image to my HTML canvas, which I can use later in the code. The JavaScript code that I have is: var sketchProc = function(processingInstance) { with (processingInstance) { /* @pjs preload="images/hot-air.png" */ size(innerWidth, innerHeight); var testImage = loadImage("images/hot-air.png"); draw = function() { image(testImage, 0, 0, 500, 500); } } } var canvas = document.getElementById("canvas"); var processingInstance = new Processing(canvas,

Get Viewport Width With JQuery and Use In Processing JS

亡梦爱人 提交于 2020-01-01 03:57:05
问题 I'm writing a processingjs script that I want to resize depending on the users viewport width. As far as I know there's no functionality for this in processing, so I've been looking at JQuery and using $(window).width(); . Only I don't know how to get that value into the size(width, height) function in processing. Any ideas? Thanks Links if you need them: http://processingjs.org/ http://api.jquery.com/width/ 回答1: You can call $(window).width(); in the size function. Mixing js and p5 code is

how to access json data in processing.js

自古美人都是妖i 提交于 2019-12-25 03:22:30
问题 I am trying to access json data which is there inside data folder inside my project folder. But I am getting "Uncaught Processing.js: Unable to execute pjs sketch: ReferenceError: loadJSONArray is not defined" error. The JSON Data is as follows: [ { "month": "january", "total": 32393, "disease": 2761, "wounds": 83, "other": 324 }, { "month": "february", "total": 30919, "disease": 2120, "wounds": 42, "other": 361 } ] This is my HTML file and I am using processing version 1.3.6. <html> <head>

Make PGraphic Object the cursor

我的梦境 提交于 2019-12-24 10:18:16
问题 This is a follow-up of my question: Make the cursor a self-drawn image. I have a paint a picture application. The latest working version can be found here: https://knowledgeablekangaroo.github.io/paint-a-picture-backup/, where the code can be found in F12 > Sources > paint-a-picture.js . The user can choose a color, set the background, set the thickness, shape, and opacity. There is also an eraser functionality. I want there to be a better user experience, so I am trying to draw the eraser

Make the cursor a self-drawn image

做~自己de王妃 提交于 2019-12-24 07:13:52
问题 I have a paint application program I have programmed from scratch in processing.js and incorporated it into my markdown code on my GitHub page. This means I would prefer to not use CSS (I would have to link to a JavaScript program that creates a link element to the CSS file and appends it to the head). In the paint program, there is an eraser that just paints the background, but I want it to look more like they are using an eraser by changing the cursor to the eraser when they have the eraser