<?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 (cast) - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=%28cast%29</link>
      <pubDate>Sun, 08 Aug 2021 19:36:08 +0000</pubDate>
         <description>Tagged with (cast) - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged%28cast%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Eclipse Processing Classes</title>
      <link>https://forum.processing.org/two/discussion/27963/eclipse-processing-classes</link>
      <pubDate>Sun, 13 May 2018 17:29:05 +0000</pubDate>
      <dc:creator>bug_ugly</dc:creator>
      <guid isPermaLink="false">27963@/two/discussions</guid>
      <description><![CDATA[<p>Hello everyone. I am here with yet another problem, hoping for your help. 
I've recently started using Eclipse for my Processing project because the number of classes started exceeding the available tabs in Processing app.</p>

<p>So I've got a question about classes. 
Let's say I have an object of another class created inside my main class, also there is a boolean variable:</p>

<pre><code>import processing.core.PApplet;
    public class MainClass extends PApplet {
            MyClass obj;
            boolean variable;

        public static void main(String[] args) {
            PApplet.main("MainClass");

        }

        public void settings() {
            size ( 1280, 720);
        }

        public void setup() {
             obj = new MyClass(this);
        }

        public void draw() {

        }
    }
</code></pre>

<p>Then there is another class which, if it was created in Processing app, would see both "obj" and "variable", but in Eclipse it doesn't recognise them:</p>

<pre><code>import processing.core.PApplet;

public class AnotherClass{
  PApplet parent;

  public AnotherClass( PApplet p) {
      parent = p;

  }
  void update() {
         variable = true; 
         obj.doSomething();
  }
}
</code></pre>

<p>How can I, in a not very complicated way, make "AnotherClass" recognise both " obj" and "variable" in a similar manner to how it happens in Processing app?
Thanks in advance!</p>
]]></description>
   </item>
   <item>
      <title>How to access a field/method of the sketch from MainActivity?</title>
      <link>https://forum.processing.org/two/discussion/27903/how-to-access-a-field-method-of-the-sketch-from-mainactivity</link>
      <pubDate>Wed, 02 May 2018 12:07:36 +0000</pubDate>
      <dc:creator>ddaann88</dc:creator>
      <guid isPermaLink="false">27903@/two/discussions</guid>
      <description><![CDATA[<p>I have <code>public void init_game()</code> in <code>public class colors_game extends PApplet</code>
What do I have to do to access <code>public void init_game()</code> from <code>public class MainActivity</code>?
Thanks in advance.</p>
]]></description>
   </item>
   <item>
      <title>class extends</title>
      <link>https://forum.processing.org/two/discussion/26510/class-extends</link>
      <pubDate>Sat, 24 Feb 2018 12:32:00 +0000</pubDate>
      <dc:creator>GeorgeJava</dc:creator>
      <guid isPermaLink="false">26510@/two/discussions</guid>
      <description><![CDATA[<p>Hello, my code not working, i dont know how to get the variable ... :/ can you tell me how ?</p>

<pre><code>ArrayList&lt;Entity&gt; entities;
void setup() {
  size(500, 500);
  entities = new ArrayList &lt;Entity&gt;();
  entities.add(new Sign("Hello!", 200, 64));
}
void draw() {
  background(0);
  println(entity.get(0).Sign.text); // WHY ? HOW TO GET VARIABLE FROM SIGN?
  for (Entity entity : entities) {
    entity.show();
    entity.handle();
  }
}


public class Sign extends Entity {
  String text;
  public Sign(String text, int mapX, int mapY) {
    super(mapX, mapY, 14, 8);
    this.text = text;
  }
  void show() {
    noStroke();
    fill(80);
    rectMode(CORNER);
    rect(xPos, yPos, w, h);
    stroke(0);
    line(xPos + 2, yPos + 2, xPos + w - 3, yPos + 2);
    line(xPos + 2, yPos + 5, xPos + w - 3, yPos + 5);
  }

  void handle() {
      textAlign(CENTER, CENTER);
      fill(255);
      text(text, xPos, yPos-32);
  }
}

public abstract class Entity extends GameObject {
  public Entity(int xPos, int yPos, int w, int h) {
    this.xPos = xPos;
    this.yPos = yPos;
    this.w = w;
    this.h = h;
  }
  abstract void show();
  abstract void handle();
}

public abstract class GameObject {
  int xPos, yPos;
  int w, h; 
  abstract void show();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Float and int, one works but why not the other?</title>
      <link>https://forum.processing.org/two/discussion/23691/float-and-int-one-works-but-why-not-the-other</link>
      <pubDate>Thu, 03 Aug 2017 12:48:36 +0000</pubDate>
      <dc:creator>DurzoBeats</dc:creator>
      <guid isPermaLink="false">23691@/two/discussions</guid>
      <description><![CDATA[<p>the code works perfectly the way i want, im just curious as to why when i initialise the size value in the form of float the code works, but it dosnt work as int size; can someone explain why? just sheer curiosity for the future.</p>

<p>(edit was just to make the text fit better)</p>

<pre><code>                int y = 100;
                int speed = 3;
                float size = 50;

            void setup(){
              size(500,500);
              stroke(0);
              fill(175);
            }
            void draw(){
              background(255);
              y+= speed;
              if ((y&gt;500) || (y&lt;0)) {
                speed = speed * -1;
              }
              ellipse(y, y,size, size);
            } 
            void mouseReleased(){
              size = random(20,60);
              redraw();
            }
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to store multiple different objects with the same parent class</title>
      <link>https://forum.processing.org/two/discussion/22981/how-to-store-multiple-different-objects-with-the-same-parent-class</link>
      <pubDate>Wed, 07 Jun 2017 23:04:37 +0000</pubDate>
      <dc:creator>CantSayIHave</dc:creator>
      <guid isPermaLink="false">22981@/two/discussions</guid>
      <description><![CDATA[<p>Say I have a parent class called <code>Bicycle</code>, and three different classes that extend this are called <code>BikeA</code>, <code>BikeB</code>, and <code>BikeC</code>.</p>

<p>Now, I have found that I can store all of these child objects inside an <strong>ArrayList</strong> declared <code>ArrayList&lt;Bicycle&gt;</code>. When it comes to scanning through the list, though, I need to differentiate these into their respective classes. Would <code>getClass()</code> still work, or have they been typecasted to <code>Bicycle</code>? I suppose I could always put an enum in the parent class and then typecast them later, but I'd prefer to go with the former option.</p>
]]></description>
   </item>
   <item>
      <title>Using int() on an Integer is a Bad Thing</title>
      <link>https://forum.processing.org/two/discussion/21843/using-int-on-an-integer-is-a-bad-thing</link>
      <pubDate>Wed, 05 Apr 2017 22:45:54 +0000</pubDate>
      <dc:creator>ajohnsonlaird</dc:creator>
      <guid isPermaLink="false">21843@/two/discussions</guid>
      <description><![CDATA[<p>Apologies in advance if it's just me having a bad brain day, but I'm getting some rather odd results with this sketch:</p>

<pre><code>    void setup()
    {
      Integer myInteger = 0x23456789;

      println("myInteger in hex=" + hex(myInteger)); // Just using hex()
      println("myHexFromCast =" + hex((int)myInteger, 8)); // hex of an  int cast
      println("myHexFromMethod =" + hex(int(myInteger), 8)); // hex of the int() method
    }
</code></pre>

<p>Yeah, I realize (now) that int(myInteger) is wrong given that int() is just for primitive data types, but I would have thought that something somewhere would have yelped in pain that I even tried to do it.</p>

<p>The output I get is:
            myInteger in hex=23456789
            myHexFromCast =23456789
            myHexFromMethod =23456780</p>

<p>So no error, but a subtly wrongo result.</p>

<p>If you change the initial value of myInteger to 0x2345FFFF you get:</p>

<pre><code>    myInteger in hex=2345FFFF
    myHexFromCast =2345FFFF
    myHexFromMethod =23460000
</code></pre>

<p>It has the hallmarks of either some weird conversion, some kind of binary format issue, with a tad of a rounding error thrown in (rounding for integers?) Or it's just my addled brain with a parity error.</p>

<p>Anyone know what's going on, please?</p>

<p>Andy. :)</p>
]]></description>
   </item>
   <item>
      <title>Variable casting speed</title>
      <link>https://forum.processing.org/two/discussion/20582/variable-casting-speed</link>
      <pubDate>Tue, 31 Jan 2017 20:23:03 +0000</pubDate>
      <dc:creator>Moxl</dc:creator>
      <guid isPermaLink="false">20582@/two/discussions</guid>
      <description><![CDATA[<p>I just ran a little test and this</p>

<pre><code>void setup() {
}

void draw() {
  for (int i=0; i&lt;1000000000; i++) {
    float var = i;
  }
}
</code></pre>

<p>runs about 3 times faster than this</p>

<pre><code>float var;

void setup() {
}

void draw() {
  for (int i=0; i&lt;1000000000; i++) {
    var = i;
  }
}
</code></pre>

<p>which is (at least to an ignorant like me) counter-intuitive, because in the first example, variable <code>var</code> is <em>cast</em> a billion times, whereas in the second one, it's merely <em>changed in value</em>. How comes?</p>
]]></description>
   </item>
   <item>
      <title>controlp5 behaving differently in setup and draw</title>
      <link>https://forum.processing.org/two/discussion/18414/controlp5-behaving-differently-in-setup-and-draw</link>
      <pubDate>Wed, 05 Oct 2016 09:19:01 +0000</pubDate>
      <dc:creator>SnailPropulsionLabs</dc:creator>
      <guid isPermaLink="false">18414@/two/discussions</guid>
      <description><![CDATA[<p>Hi all, I have a difficulty with controlp5.
I am trying to update the value in a textbox but it won't accept my new string.
The code below is my test code to get this working.</p>

<p>In the setup I can pass a string into the .setValue(); and it works but when it comes to the draw I can no longer pass a string into it, it throws an error that says it expects a float.</p>

<p>So the question is why? I can't for the life of me work out why this works then doesn't.</p>

<p>Thanks.</p>

<pre><code>import controlP5.*;

ControlP5 cp5;

String newInput = "boop";

void setup() {
  size(700, 400);

  PFont font = createFont("arial", 20);

  cp5 = new ControlP5(this);

  cp5.addTextfield("Word 1")
    .setPosition(20, 170)
    .setSize(200, 40)
    .setFont(font)
    .setAutoClear(true)
    .setValue(newInput)
    .setColor(255) //text color
    .setColorBackground(0)
    .setCaptionLabel(" ")
    ;

  textFont(font);
}

void draw() {
  background(210);
  newInput = cp5.getController("Word 1").getStringValue();
  cp5.getController("Word 1").setValue(newInput);
  println("NI:" + newInput);
  text(newInput, mouseX, mouseY);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>catch variable from class Object when this one is a instanceof :</title>
      <link>https://forum.processing.org/two/discussion/17617/catch-variable-from-class-object-when-this-one-is-a-instanceof</link>
      <pubDate>Fri, 22 Jul 2016 16:53:24 +0000</pubDate>
      <dc:creator>Stanlepunk</dc:creator>
      <guid isPermaLink="false">17617@/two/discussions</guid>
      <description><![CDATA[<p>I try to write generic method to pass different class by this one. My idea is test the obect to see if it is an instance of my target class, but when I'm testing positively the nature of class, I cannot catch the method or var of this class :</p>

<pre><code>Mother mother = new Mother(1) ;
ArrayList&lt;Mother&gt; list_mother = new ArrayList&lt;Mother&gt;() ;

void setup() {
  list_mother.add(mother) ;

  method_list(list_mother) ;
}

void method_list(ArrayList list) {
  for(Object obj : list) {
    if(obj instanceof Mother) {
      println("list Mother") ;
      println(obj.x) ;
    }
  }
}

class Mother {
  int x ;
  Mother(int x) {
    this.x = x ;
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Why can't I append a new vector to an array of vectors?</title>
      <link>https://forum.processing.org/two/discussion/17524/why-can-t-i-append-a-new-vector-to-an-array-of-vectors</link>
      <pubDate>Wed, 13 Jul 2016 20:43:39 +0000</pubDate>
      <dc:creator>brooklev</dc:creator>
      <guid isPermaLink="false">17524@/two/discussions</guid>
      <description><![CDATA[<p>Hi Sages,</p>

<p>I'm new to Processing and trying to reverse understand from Python.</p>

<p>I have vTr, an array of 2D vectors, with a single element (the starting coordinates of my object) in it.
When I try to append vN (new coordinates) to vTr, I get "Type mismatch, "java.lang.Object" does not match with "processing.core.PVector[]":</p>

<pre><code>xPos = xPos + speed * vP.x;

yPos = yPos + speed * vP.y;

vN = new PVector(xPos, yPos);

vTr = append(vTr, vN); //This underlines in red and delivers the message above.
</code></pre>

<p>Does this mean I have to use an ArrayList? The Processing 3.0 page claims append() works with objects.</p>

<p>Thanks for any help!</p>
]]></description>
   </item>
   <item>
      <title>pointers and ArrayLists problem</title>
      <link>https://forum.processing.org/two/discussion/16417/pointers-and-arraylists-problem</link>
      <pubDate>Wed, 04 May 2016 02:54:07 +0000</pubDate>
      <dc:creator>makspll</dc:creator>
      <guid isPermaLink="false">16417@/two/discussions</guid>
      <description><![CDATA[<p>hi, iam using an array list to store an object of class entity, which is a parent to classes weapon and tribute. i want to be able to do:</p>

<p><code>entitiesList.get(currentEntity.getID()).pickUp();</code></p>

<p>where pickUp is a function of the subclass weapon;
however i cannot do that as i get a, "function doesnt exist" error, now i havent actually tried it but would</p>

<p><code>weapon temp = (weapon)entitiesList.get(currentEntity.getID()); temp.pickUp();</code></p>

<p>that work ?
would the weapon object created point to the original, or would it be a new object ?
if it is the latter, then is there any way i can store the originals in one arraylist and then use two other arraylists to store weapons and tributes as pointers to the original array ?,</p>
]]></description>
   </item>
   <item>
      <title>ArrayList with different object-types</title>
      <link>https://forum.processing.org/two/discussion/4551/arraylist-with-different-object-types</link>
      <pubDate>Sun, 20 Apr 2014 11:38:45 +0000</pubDate>
      <dc:creator>necip</dc:creator>
      <guid isPermaLink="false">4551@/two/discussions</guid>
      <description><![CDATA[<p>Hello! it is possible to put in an arraylist different types of objects, right?</p>

<p>e.g.</p>

<p>ArrayList al;</p>

<p>al.add (new Circle(0,0,10));
al.add (new Rect(0,0,10,10));</p>

<p>How can I figure out which class is stored when I iterate through that array?</p>

<p>for (int i=0; i&lt;al.size(); i++)
  CLASS? obj = (CLASS?) ai.get(i);</p>
]]></description>
   </item>
   <item>
      <title>[Solved] How to properly use type 'Object', or if there is a work around?</title>
      <link>https://forum.processing.org/two/discussion/14143/solved-how-to-properly-use-type-object-or-if-there-is-a-work-around</link>
      <pubDate>Fri, 25 Dec 2015 01:27:57 +0000</pubDate>
      <dc:creator>Frekvens1</dc:creator>
      <guid isPermaLink="false">14143@/two/discussions</guid>
      <description><![CDATA[<p>Thanks for clicking here, and to not waste your time, let's get to the point.</p>

<p>I'm currently working on a file library, because it will be handy in future builds. My way of doing this is to make an ArrayList of a class I've made to store information on the file.</p>

<p><code>long newID; long newID(){return newID++;} //Generates a new ID when called.</code></p>

<p><code>class file { //File class. Stores information about a file.</code>
 <code>String name, type, path; long ID; Object content;</code></p>

<p><code>file(String fileName, String filePath){</code>
   <code>String temp[] = split(fileName,"."); //Splits the file name into name and type.</code>
   <code>name = temp[0]; //The name of the file, mostly for file search.</code>
   <code>path = filePath; //The file path on local machine.</code>
  <code> ID = newID(); //Generates a new ID for the file, could be handy.</code>
   <code>type = ""; //Empty means folder</code></p>

<p><code>if (temp.length &gt; 1){</code>
     <code>type = temp[1].toLowerCase(); //There is a file type, let's assign it.</code>
   <code>}</code></p>

<p><code>}</code>
<code>}</code></p>

<p>To simplify my question:
I would like my code to work like this:</p>

<p><code>file temp = new file("test.png", "C:\\test.png");
temp.content = loadImage(temp.path);
image(temp.content, 0, 0, width, height);</code></p>

<p>The problem is 'temp.content' is not the type PImage, and I don't know a way to make it accepted, without declearing a new temporary PImage which loads the image instead, which is not acctually what I'm after. I want to load all files at launch, and then there should be no need to load them again. I could expand my class to contain all the different types, like PImage, sound, text, but that is just plain messy. I like it clean and simple. This operation works in most languages, so I was hoping so did Processing due to Java.</p>

<p>For those who wonder, I can simply use a if statement on the 'temp.type' to find out if it is a image, sound or whatever it is, so it won't create a runtime error.</p>

<p>Any help would be greatly appreciated, thanks for reading!</p>

<p><strong>EDIT</strong></p>

<p>I'm bad at explaining, but what I meant is I want the 'Object content' to be a variable I can change. Pretty much like: 'content = new PImage' or 'content = new className'. Like it would change the type which content represented. It would be really handy, but not quite sure how to achieve this.</p>
]]></description>
   </item>
   <item>
      <title>(float)?</title>
      <link>https://forum.processing.org/two/discussion/13011/float</link>
      <pubDate>Wed, 14 Oct 2015 13:29:35 +0000</pubDate>
      <dc:creator>rodrigolebrun</dc:creator>
      <guid isPermaLink="false">13011@/two/discussions</guid>
      <description><![CDATA[<p>I'm doing Daniel Shiffman's tutorial on <a rel="nofollow" href="https://processing.org/tutorials/pixels/">image manipulation</a> and I came across (float). I'm pretty sure this is quite basic, but this is the first time I see it. What does it do? I mean, I know without it, the code won't work, but I thought data types were only used to create variables. Anyone? Thanks.</p>

<pre><code>PImage img;
int cellsize=8;
int cols,rows;
void setup() {
 size(200,200,P3D);
 img=loadImage("IMG_6753.jpg");
 surface.setResizable(true);
 surface.setSize(img.width,img.height);
 cols=width/cellsize;
 rows=height/cellsize;

}


void draw() {
  background(0);
  loadPixels();

  for(int i=0; i&lt;cols; i++) {
     for(int j=0; j&lt;rows; j++) {
       int x=i*cellsize+cellsize/2;
       int y=j*cellsize+cellsize/2;
       int loc=x+y*width;
       color c=img.pixels[loc];

       float z=(mouseX/(float)width)*brightness(img.pixels[loc])-10;
       pushMatrix();
       translate(x,y,z);
       fill(c);
       noStroke();
       rectMode(CENTER);
       rect(0,0,cellsize,cellsize);


       popMatrix();



  }


  }



}
</code></pre>
]]></description>
   </item>
   <item>
      <title>If "i+=0.5" is OK, why not "i+=1/2"?</title>
      <link>https://forum.processing.org/two/discussion/12516/if-i-0-5-is-ok-why-not-i-1-2</link>
      <pubDate>Tue, 15 Sep 2015 08:53:20 +0000</pubDate>
      <dc:creator>naockovich</dc:creator>
      <guid isPermaLink="false">12516@/two/discussions</guid>
      <description><![CDATA[<p>Say I want to draw 2 circles. One followed by another, both spreading out.
To make the second circle come behind the first one, I'd use variable i,j like below.
This one works as I expect, but when I write<code>j+=1/2</code> instead of <code>j+=0.5</code>, it doesn't work.
What's wrong with the a fraction?</p>

<pre><code>    float i,j=0;

    void setup(){
      size(200,200);
    }
    void draw(){
      ellipse(width/2,height/2,i,i);
      ellipse(width/2,height/2,j,j);
      ++i;
      j+=0.5;
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Accessing member fields using interfaces</title>
      <link>https://forum.processing.org/two/discussion/12310/accessing-member-fields-using-interfaces</link>
      <pubDate>Sun, 30 Aug 2015 19:02:02 +0000</pubDate>
      <dc:creator>_vk</dc:creator>
      <guid isPermaLink="false">12310@/two/discussions</guid>
      <description><![CDATA[<p>So I thought the code below would work, but it does not...</p>

<p>I'd like to hold some classes that implements an Interface in the same collection, but if I can't access member fields, then maybe it's useless... What am I doing wrong?</p>

<pre><code>I i ;

void setup() {
  i = new C();
  // throws a cannot be resolved or is not a field
  println(i.x);
}

interface I {
}

class C implements I {
  int x;

  C() {
    x= 0;
  }
}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>