<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with constructor() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=constructor%28%29</link>
      <pubDate>Sun, 08 Aug 2021 17:39:50 +0000</pubDate>
         <description>Tagged with constructor() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedconstructor%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Translating Processing classes to js classes</title>
      <link>https://forum.processing.org/two/discussion/28133/translating-processing-classes-to-js-classes</link>
      <pubDate>Fri, 05 Oct 2018 02:36:10 +0000</pubDate>
      <dc:creator>syang</dc:creator>
      <guid isPermaLink="false">28133@/two/discussions</guid>
      <description><![CDATA[<p>Hi all! Getting practice with p5js and translating Processing code into js. Struggling with this one in particular, especially the move() method. Does anyone mind giving me some pointers as to where it might not be working? I am just getting a stationary white dot, on a black background for now.  Thank you!</p>

<pre><code>class Spot {
  constructor() {
let x;
let y;
let speed;
let diameter;
let direction = 1;
  }
  display() {
    ellipse(spot.x, spot.y, spot.diameter, spot.diameter);
  }

  move(x, y, speed, height,  diameter, direction) {
//let x;
//let y;
//let speed;
//let diameter;
    direction = 1;
    y += speed * direction;
    if (y &gt; height - diameter / 2 || y &lt; diameter / 2) {
      direction *= -1;
    }
  }

  // Spot(xpos, ypos, dia, sp) {
  //   x = xpos;
  //   y = ypos;
  //   diameter = dia;
  //   speed = sp;
  // }
}

let spot = new Spot();

   function setup() {
 createCanvas(100, 100);
 noStroke();
 spot = new Spot(33, 50, 30, 1.5);
 console.log(spot);

  //sp = new Spot(33, 50, 30);

  spot.x = 33;
  spot.y = 50;
  spot.diameter = 30;
}

function draw() {
  spot.move();
  fill(0, 15);
  rect(0, 0, width, height);
  fill(255);

  //background(0);
  spot.display();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>problem to create an object list.</title>
      <link>https://forum.processing.org/two/discussion/25906/problem-to-create-an-object-list</link>
      <pubDate>Thu, 11 Jan 2018 00:51:36 +0000</pubDate>
      <dc:creator>Golden_Paper</dc:creator>
      <guid isPermaLink="false">25906@/two/discussions</guid>
      <description><![CDATA[<p>I want to create an object list in another object and have access later to the information contained in the objects of this list. The problem is that when I create a list I can not access this list later. I will send you the address of my project if someone can help me.
<a href="https://gitlab.com/codemasterjr/Schematic_Clock.git" target="_blank" rel="nofollow">https://gitlab.com/codemasterjr/Schematic_Clock.git</a>
I want to create a list of object "pin" in the object "dip" which does not always contain the same number of pin.
thank you in advance</p>
]]></description>
   </item>
   <item>
      <title>issues passing an instance of one class into another class in P5.js</title>
      <link>https://forum.processing.org/two/discussion/24978/issues-passing-an-instance-of-one-class-into-another-class-in-p5-js</link>
      <pubDate>Sun, 12 Nov 2017 20:56:46 +0000</pubDate>
      <dc:creator>digitalcoleman</dc:creator>
      <guid isPermaLink="false">24978@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to convert some code and am nearly there but realize I do not understand how javascript and P5.js handles passing in an instance of one class to a method of another class. In this case, I am passing an instance of a paddle into the puck for a pong style game.</p>

<pre><code>   ` //in the main program we initialize
    var puck = new Puck(); 
    var left = new Paddle(true);
    var right = new Paddle(false);
    //and then call the method like this
    puck.checkPaddleLeft(left);
    puck.checkPaddleRight(right);
...`


  `  //in the puck class we have this
    function Puck(){
     this.x = 600/2; // Place the puck in the middle of the x axis.
     this.y = 400/2; // Place the puck in the middle of the y axis.
     this.xspeed = 0; // Sets the initial puck speed along the x axis.
     this.yspeed = 0; // Sets the initial puck speed along the y axis.
     this.r = 12; // Establishes the radius of the puck at 12 pixels.
     //reset();

    Puck.protoype.checkPaddleLeft = function(p) { // Function to determine collision between the puck and the left paddle.
      if (y &lt; p.y + p.h/2 &amp;&amp; y &gt; p.y - p.h/2 &amp;&amp; this.x - this.r &lt; p.x + p.w/2) {
        if (this.x &gt; p.x) {
          var diff = y - (p.y - p.h/2);
          var rad = radians(45);
          var angle = map(diff, 0, p.h, -rad, rad);
          this.xspeed = 5 * cos(angle);
          this.yspeed = 5 * sin(angle);
          this.x = p.x + p.w/2 + this.r;
        }
      }
    }
...}`
</code></pre>

<p>When you try to run this, it returns "Cannot set property 'checkPaddleLeft' of undefined"
Any assistance on how to structure such calls is appreciated.</p>
]]></description>
   </item>
   <item>
      <title>[Newbie to p5.js] Making a mini avoidance game, hazard doesn't seem to be showing up?</title>
      <link>https://forum.processing.org/two/discussion/23745/newbie-to-p5-js-making-a-mini-avoidance-game-hazard-doesn-t-seem-to-be-showing-up</link>
      <pubDate>Tue, 08 Aug 2017 13:15:21 +0000</pubDate>
      <dc:creator>FullArt</dc:creator>
      <guid isPermaLink="false">23745@/two/discussions</guid>
      <description><![CDATA[<p>Hi there! I've recently taken up learning p5.js after a friend showed me its potential, and I wanted to try some simple but complete stuff, but I've not worked with anything like this for very long. I've ham-fisted together some of the examples from the p5.js site and youtube, and I got the movement of the player working, but I can't seem to display the hazards. I'm thinking the issue is purely somewhere between line 28 and 53, where the bulk of the hazard's code is but can't quite visualize all the variables physically. Any thoughts?</p>

<pre><code>var canvasWidth = 700;
var canvasHeight = 400;
var yoff = 0.0;   

function setup() { 
  createCanvas(canvasWidth, canvasHeight);
} 


function draw() {
  drawBackground();
    drawCar();
}


//Car (player)
var car = {
  x : 50,
  y : 230,
  draw : function() {
    fill(0);
    rect(this.x, this.y, 50, 50);
    }
}



//Rock (enemies to avoid)
var rocks = [];

function rock(I) {
  I.active = true;
  I.yvelocity = 2;
  I.width = 20;
  I.height = 20;
  I.y = Math.random() * (canvasHeight-I.height);
  I.x = 400;
  I.inBounds = function() {
    return I.x &gt;= 700 &amp;&amp; I.x &lt; canvasWidth + I.width;
  };
  I.draw = function() {
    //fill(0); this comes up as an error every now and then, not sure how to add 
    //this attribute to the var in the array, unlike I did with the car. 
    //The rect attribute also comes up with an error sometimes
    rect(I.x, I.y, I.width, I.height);
  };
  I.update = function() {
    I.active = I.active &amp;&amp; I.inBounds();
    I.x -= I.xvelocity;
  };
  return I;

}


//Background and setting
function drawBackground() { 
  background(175, 213, 255);
  //noStroke();
  fill(225, 212, 160);
  beginShape(); 
    var xoff = 0;     
    // Iterate over horizontal pixels
    for (var x = 0; x &lt;= width; x += 10) {
        // Calculate a y value according to noise, map to 
        var y = map(noise(xoff, yoff), 0, 1, 100,200);
        vertex(x, y); 
        // Increment x dimension for noise
        xoff += 0.05;
    }
    // increment y dimension for noise
    yoff += 0.01;
    vertex(width, height);
    vertex(0, height);
  endShape(CLOSE);
}


//Car controls / drawing
function drawCar() {

  car.draw();
  if (keyIsDown(DOWN_ARROW)) {
    if (car.y + 5 &gt;= 350)
      car.y = 350;
    else
      car.y += 5;
    }
    if (keyIsDown(UP_ARROW)) {
    if (car.y &lt;= 150)
        car.y = 150;
    else
      car.y -= 5;
    }
}

if(Math.random() &lt; 0.05){
    rocks.push(rock({}));
}

rocks = rocks.filter(function(rock){
  return rock.active;
});
rocks.forEach(function(rock){
    rock.update();
  rock.draw();
});
</code></pre>
]]></description>
   </item>
   <item>
      <title>Movement on the y-axis but not the x-axis??</title>
      <link>https://forum.processing.org/two/discussion/22155/movement-on-the-y-axis-but-not-the-x-axis</link>
      <pubDate>Sun, 23 Apr 2017 18:45:56 +0000</pubDate>
      <dc:creator>benjim1996</dc:creator>
      <guid isPermaLink="false">22155@/two/discussions</guid>
      <description><![CDATA[<p>Hey, I have some code from a university project, and am trying to implement key based movement. I have got the movement to work up and down along the y-axis, but cannot get it to move left and right along the x-axis, and am unsure why.</p>

<p>My code for the object, and movement is as follows:</p>

<p>`function bomberMan(){</p>

<p>this.x = 100;
  this.y = 100;
  this.xpseed = 0;
  this.yspeed = 0;</p>

<p>this.dir = function(x,y){
    this.xspeed = x;
    this.yspeed = y;
  }</p>

<p>this.update = function(){
  this.x = this.x + this.xpseed;
  this.y = this.y + this.yspeed;
  }</p>

<p>this.show = function(){
    fill(0);
    rect(this.x, this.y, 15, 15);
  }</p>

<p>}</p>

<p>function keyPressed(){
  if (keyCode === UP_ARROW){
    bomber.dir(0, -1);
  }</p>

<p>if (keyCode === DOWN_ARROW){
    bomber.dir(0,1);
  }</p>

<p>if (keyCode === LEFT_ARROW){
    bomber.dir(-1,0);
  }</p>

<p>if (keyCode === RIGHT_ARROW){
    bomber.dir(1,0);
  } 
}`</p>

<p>Any help as to why this doesn't seem to work would be greatly appreciated, thanks so much!</p>
]]></description>
   </item>
   <item>
      <title>stuck again (Invaders)</title>
      <link>https://forum.processing.org/two/discussion/22094/stuck-again-invaders</link>
      <pubDate>Thu, 20 Apr 2017 04:52:08 +0000</pubDate>
      <dc:creator>tim50</dc:creator>
      <guid isPermaLink="false">22094@/two/discussions</guid>
      <description><![CDATA[<p>How do I make these aliens into one variable? Once I start shooting them, they become a mess of confusion.</p>

<p>I have no idea what do to.</p>

<p>If you answer, please talk to me like you'd talk to a five year old... Thanks.</p>

<p><a href="https://openprocessing.org/sketch/421935" target="_blank" rel="nofollow">https://openprocessing.org/sketch/421935</a></p>
]]></description>
   </item>
   </channel>
</rss>