<?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 *args - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=%2Aargs</link>
      <pubDate>Sun, 08 Aug 2021 20:00:39 +0000</pubDate>
         <description>Tagged with *args - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged%2Aargs/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>How to add a mouse event in a child class</title>
      <link>https://forum.processing.org/two/discussion/26369/how-to-add-a-mouse-event-in-a-child-class</link>
      <pubDate>Thu, 15 Feb 2018 19:29:09 +0000</pubDate>
      <dc:creator>solub</dc:creator>
      <guid isPermaLink="false">26369@/two/discussions</guid>
      <description><![CDATA[<p>Following this <a rel="nofollow" href="https://forum.processing.org/two/discussion/comment/117219#Comment_117219">thread</a> I'm trying to add a mouse event to a sketch using the toxiclibs library.</p>

<p>I'd like to be able to move a specific particle with the mouse and see the distortion on the springs grid.</p>

<p>Here's what the sketch looks like</p>

<p><a href="https://imgur.com/a/vUSd1" target="_blank" rel="nofollow">https://imgur.com/a/vUSd1</a></p>

<p><img src="https://i.imgur.com/smqSOFj.png" alt="" /></p>

<p><strong>Main .Pyde file</strong></p>

<pre><code>add_library('verletphysics')
add_library('toxiclibscore')
from toxi.physics2d import VerletPhysics2D
from toxi.physics2d.behaviors import GravityBehavior 
from Particle import particle
from Locker import locker

def setup():
    size(600, 600, OPENGL)
    smooth(10)
    global physics, collection, lockers, n_rowcol

    physics = VerletPhysics2D()
    physics.addBehavior(GravityBehavior(Vec2D(0, 1)))

    collection, springs, lockers  = [], [], []
    n_rowcol, lngth, strength = 40, 10, .6

    #Display particles and add to Physics
    [[collection.append(particle(100 + (e * 10), 10 + (f * 10))) for f in range(n_rowcol)] for e in range(n_rowcol)]
    [physics.addParticle(e) for e in collection]

    #Lock specific particles
    [collection[e].lock() for e in (0, n_rowcol - 1, n_rowcol ** 2 - n_rowcol, n_rowcol ** 2 - 1)]

    #Display springs
    for e in range(0, n_rowcol ** 2 , n_rowcol):
        for f in range(n_rowcol - 1):
            a = collection[e + f]
            b = collection[e + f + 1]
            s = VerletSpring2D(a, b, lngth, strength)
            physics.addSpring(s)

    for e in range(n_rowcol):
        for f in range(0, n_rowcol ** 2 - n_rowcol, n_rowcol):
            a = collection[e + f]
            b = collection[e + f + n_rowcol]
            s = VerletSpring2D(a, b, lngth, strength)
            physics.addSpring(s)

    #Display lockers (red circles to move with mouse) 
    for e in (0, n_rowcol - 1, n_rowcol ** 2 - n_rowcol, n_rowcol**2 - 1):
        lockers.append(locker(collection[e].x(), collection[e].y()))


def draw():
    background(0)

    #Framerate
    [fill(255), text(int(frameRate), 10, 20)]

    #Run physics
    physics.update()

    #Draw lockers (red circles, not lockers really)
    for e in lockers:
        e.display()
        e.mousePressed()
        e.mouseDragged()

    #Draw particles
    [e.display() for e in collection]

    #Draw springlines
    springlines()


def springlines():
    for e in range(0, n_rowcol ** 2, n_rowcol):
        for f in range(n_rowcol - 1):
            a = collection[e + f]
            b = collection[e + f + 1]
            stroke(255)
            line(a.x(), a.y(), b.x(), b.y())

    for e in range(n_rowcol):
        for f in range(0, n_rowcol ** 2 - n_rowcol, n_rowcol):
            a = collection[e + f]
            b = collection[e + f + n_rowcol]
            stroke(255)
            line(a.x(), a.y(), b.x(), b.y())
</code></pre>

<p><strong>Locker.py file</strong></p>

<pre><code>    class locker(object):

        def __init__(self, x, y):
            self.x = x
            self.y = y
            self.over = False
            self.locked = False

        def display(self):

            if dist(self.x, self.y, mouseX, mouseY) &lt; 20:
                self.over = True
                fill(0, 0, 255)
            else:
                self.over = False
                fill(255, 20, 20)
            noStroke()
            ellipse(self.x, self.y, 20, 20)

        def mousePressed(self):
            if mousePressed and self.over:
                self.locked = True
            else:
                self.locked = False

        def mouseDragged(self):
            if self.locked:
                self.x = mouseX
                self.y = mouseY
</code></pre>

<p><strong>Particle.py file</strong></p>

<pre><code>    from toxi.physics2d import VerletParticle2D

    class particle(VerletParticle2D):

       over = False

        def display(pos):
            if dist(pos.x(), pos.y(), mouseX, mouseY) &lt; 4:
                pos.over = True
                fill(255, 20, 20)
            else:
                pos.over = False
                fill(255)

            ellipse(pos.x(), pos.y(), 4, 4)
</code></pre>

<p>The problem lies in the last snippet above (Particle.py):</p>

<p>To drag a specific particle when mousePressed, I need to access the x and y coordinates of the ellipse (the particle) and say something like:</p>

<pre><code>    def mousePressed(): 
        if pos.over:
            pos.x() = mouseX
            pos.y() = mouseY
</code></pre>

<p>But doing so gives me an error: "can't assign to function call" because x() and y() appear as functions.</p>

<p>How can I access the x and y coordinates and make that mouse event work ?</p>
]]></description>
   </item>
   <item>
      <title>Class inheritance with toxiclibs (Python)</title>
      <link>https://forum.processing.org/two/discussion/26346/class-inheritance-with-toxiclibs-python</link>
      <pubDate>Wed, 14 Feb 2018 11:55:27 +0000</pubDate>
      <dc:creator>solub</dc:creator>
      <guid isPermaLink="false">26346@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone !</p>

<p>I'm really excited to start using the toxiclibs library following <a rel="nofollow" href="https://www.youtube.com/watch?v=jrk_lOg_pVA">this</a> Daniel Shifmann tutorial but i'm having hard times implementing the following snippet in Python:</p>

<pre><code>class Particle extends VerletParticle2D {

  Particle(float x, float y) {
    super(x, y);
  }

  void display() {
    fill(255);
    ellipse(x, y, 10, 10);
  }
}
</code></pre>

<p>This is supposed to get the x and y coordinates from the main .pde file and make them "move"/'"change" according to the toxiclibs VerletPhysics engine.</p>

<p>I believe the corresponding Python code would be:</p>

<pre><code>import toxi.physics2d.VerletParticle2D as VerletParticle2D

class Particle(VerletParticle2D):
    def __init__(self, x, y):
        super(Particle, self).__init__(x, y)
        self.x = x
        self.y = y


    def display(self):
        fill(255)
        ellipse(self.x, self.y, 10, 10)
</code></pre>

<p>But I must have missed something because the coordinates don't change and all my points stay still on the screen. Do you have any idea what I'm doing wrong here ?</p>
]]></description>
   </item>
   </channel>
</rss>