# Where should my size(640, 480) go in my py.processing code?

**URL:** <https://discourse.processing.org/t/where-should-my-size-640-480-go-in-my-py-processing-code/10858>\
**Category:** Processing.py\
**Created:** [May 3, 2019, 12:54am UTC](https://discourse.processing.org/t/where-should-my-size-640-480-go-in-my-py-processing-code/10858 "2019-05-03T00:54:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SanguineL](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sanguinel/32/4959_2.png) [@SanguineL](https://discourse.processing.org/u/SanguineL)\
**Post date:** [May 3, 2019, 12:54am UTC](https://discourse.processing.org/t/where-should-my-size-640-480-go-in-my-py-processing-code/10858/1 "2019-05-03T00:54:41Z")

</div>

Hello, I am having some confusion about where my `size()` code will go.

`

```
Balls = []
class Ball:
    def __init__ (self, x, y, xvel, yvel, radius):
        global Balls
        self.x = x
        self.y = y
        self.xvel = xvel
        self.yvel = yvel
        self.radius = radius
        m = radius*.1
    
        self.ball = self
        fill(250)
        self.drawing = ellipse(x, y, radius, radius)
    
        Balls.append(self)
    
def update(self):
    self.x += xvel
    self.y += yvel
    
def checkWall(self):
    if self.x > 640 - self.r:
        self.xvel = -self.xvel
    if self.x < 0 + self.r:
        self.xvel = -self.xvel
    if self.y > 480 - self.r:
        self.yvel = -self.yvel
    if self.y < 0 + self.r:
        self.yvel = -self.yvel
        
        
    draw()
        
    def display(self):
        noStroke()
        fill(255)
        ellipse(self.x, self.y, radius, radius)
        
def draw():
    background(255)

if len(Balls) > 0:

    for b in Balls:
        b.update()
        b.display()
        b.checkWall()
    
def settings():
    size(640, 480)

settings()

Ball(100, 100, 20, 10, 50)
Ball(500, 300, 10, 3, 200)`

```

I currently get the error: ’`size()` cannot be used here.’

Any place `size()` could go?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [May 3, 2019, 12:57am UTC](https://discourse.processing.org/t/where-should-my-size-640-480-go-in-my-py-processing-code/10858/2 "2019-05-03T00:57:21Z")

</div>

does that help?  
[https://py.processing.org/reference/size.html](https://py.processing.org/reference/size.html)

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [May 3, 2019, 5:12am UTC](https://discourse.processing.org/t/where-should-my-size-640-480-go-in-my-py-processing-code/10858/3 "2019-05-03T05:12:45Z")

</div>

You are using animation, so you’ll have to include a `setup()` function (not settings). The `size()` is placed within this. However, there are several issues with your script. I’ve added the `setup()` function, but had to make a few other adjustments to get it working:

```auto
Balls = []

class Ball:
    def __init__ (self, x, y, xvel, yvel, radius):
        global Balls
        self.x = x
        self.y = y
        self.xvel = xvel
        self.yvel = yvel
        self.radius = radius
        self.r = self.radius/2
        m = radius*.1
    
        self.ball = self
        fill(250)
        self.drawing = ellipse(x, y, radius, radius)
    
        Balls.append(self)

    def update(self):
        self.x += self.xvel
        self.y += self.yvel
        
    def checkWall(self):
        if self.x > 640 - self.r:
            self.xvel = -self.xvel
        if self.x < 0 + self.r:
            self.xvel = -self.xvel
        if self.y > 480 - self.r:
            self.yvel = -self.yvel
        if self.y < 0 + self.r:
            self.yvel = -self.yvel
            
    def display(self):
        fill(255)
        ellipse(self.x, self.y, self.radius, self.radius)

def draw():
    background(255)
    
    if len(Balls) > 0:
    
        for b in Balls:
            b.update()
            b.display()
            b.checkWall()

def setup():
    size(640, 480)
    global Balls
    Ball(100, 100, 20, 10, 50)
    Ball(500, 300, 10, 3, 200)

```

There’s still some redundant code in there. You might want to look at removing what you do not need.

---

<div class="post-metadata">

**Author:** ![SanguineL](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sanguinel/32/4959_2.png) [@SanguineL](https://discourse.processing.org/u/SanguineL)\
**Post date:** [May 3, 2019, 10:07am UTC](https://discourse.processing.org/t/where-should-my-size-640-480-go-in-my-py-processing-code/10858/4 "2019-05-03T10:07:48Z")

</div>

Thanks, mate! I’m still learning what all the functions are and how it works.

But thanks again for your help!

---

<div class="post-metadata">

**Author:** ![SanguineL](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sanguinel/32/4959_2.png) [@SanguineL](https://discourse.processing.org/u/SanguineL)\
**Post date:** [May 3, 2019, 10:09am UTC](https://discourse.processing.org/t/where-should-my-size-640-480-go-in-my-py-processing-code/10858/5 "2019-05-03T10:09:01Z")

</div>

Thanks, mate! I’m still learning what all the functions are and how it works.

But thanks again for your help!

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [May 4, 2019, 12:33pm UTC](https://discourse.processing.org/t/where-should-my-size-640-480-go-in-my-py-processing-code/10858/6 "2019-05-04T12:33:22Z")

</div>

To learn those basics see the introduction tutorials, particularly the Overview, here

> **[Processing Overview \\ Tutorials](https://py.processing.org/tutorials/overview/)**
>
> Python Mode for Processing extends the Processing Development Environment with the Python programming language.

> Interactive programs are drawn as a series of frames, which you can create by adding functions titled setup() and draw() as shown in the code below. These are built-in functions that are called automatically.
