# Not Understanding This

**URL:** <https://discourse.processing.org/t/not-understanding-this/5826>\
**Category:** Beginners\
**Created:** [November 22, 2018, 11:29am UTC](https://discourse.processing.org/t/not-understanding-this/5826 "2018-11-22T11:29:01Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![HoboGreed](https://avatars.discourse-cdn.com/v4/letter/h/da6949/32.png) [@HoboGreed](https://discourse.processing.org/u/HoboGreed)\
**Post date:** [November 22, 2018, 11:29am UTC](https://discourse.processing.org/t/not-understanding-this/5826/1 "2018-11-22T11:29:01Z")

</div>

Why does set(int(X),int(Y),255); work in Setup but not in draw and yet set(int(X),int(Y),0xffffffff); does work in draw ?

```auto
float X,Y;

void setup(){
  size(512,512);
  background(0);
  X=256;Y=256;
  //set(int(X),int(Y),255);
  
}

void draw(){
  //set(int(X),int(Y),255);
  set(int(X),int(Y),0xffffffff);
}

```

---

<div class="post-metadata">

**Author:** ![Sarah](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sarah/32/1675_2.png) [@Sarah](https://discourse.processing.org/u/Sarah)\
**Post date:** [November 22, 2018, 12:41pm UTC](https://discourse.processing.org/t/not-understanding-this/5826/2 "2018-11-22T12:41:55Z")

</div>

Does:

```auto
void draw() {
  background(0);
  set(int(X), int(Y), 255);
}

```

Work for you?

---

<div class="post-metadata">

**Author:** ![fritzpal](https://avatars.discourse-cdn.com/v4/letter/f/b38774/32.png) [@fritzpal](https://discourse.processing.org/u/fritzpal)\
**Post date:** [November 22, 2018, 1:36pm UTC](https://discourse.processing.org/t/not-understanding-this/5826/3 "2018-11-22T13:36:36Z")

</div>

Because it expects parameters like set(int, int, color);

```auto
float X,Y;
color yourColor = color(255, 100, 0);

void setup(){
size(512,512);
background(0);
X=256;Y=256;
set(int(X),int(Y),yourColor);

}

void draw(){
set(int(X), int(Y), yourColor);
}

```

---

<div class="post-metadata">

**Author:** ![HoboGreed](https://avatars.discourse-cdn.com/v4/letter/h/da6949/32.png) [@HoboGreed](https://discourse.processing.org/u/HoboGreed)\
**Post date:** [November 22, 2018, 1:41pm UTC](https://discourse.processing.org/t/not-understanding-this/5826/4 "2018-11-22T13:41:02Z")

</div>

Yes, that’s it Fritz. Always wondered what data type color was for as it is seems to be exactly like int.  
Now I see it’s ‘special’. 🙂

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [November 22, 2018, 5:03pm UTC](https://discourse.processing.org/t/not-understanding-this/5826/5 "2018-11-22T17:03:02Z")

</div>

It still does not explain why it works in setup and not in draw.

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 22, 2018, 8:28pm UTC](https://discourse.processing.org/t/not-understanding-this/5826/6 "2018-11-22T20:28:28Z")

</div>

Color actually is really close to an int, because it is represented by the numbers -1 to -16million~, that’s also why 255 doesn’t work. What you could do is use color(255) instead of 255. This will return -16million as an int, while color(0) would give out -1.

---

<div class="post-metadata">

**Author:** ![Sarah](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sarah/32/1675_2.png) [@Sarah](https://discourse.processing.org/u/Sarah)\
**Post date:** [November 22, 2018, 10:29pm UTC](https://discourse.processing.org/t/not-understanding-this/5826/7 "2018-11-22T22:29:32Z")

</div>

That’s odd. Maybe @GoToLoop might know more?

---

<div class="post-metadata">

**Author:** ![HoboGreed](https://avatars.discourse-cdn.com/v4/letter/h/da6949/32.png) [@HoboGreed](https://discourse.processing.org/u/HoboGreed)\
**Post date:** [November 22, 2018, 10:50pm UTC](https://discourse.processing.org/t/not-understanding-this/5826/8 "2018-11-22T22:50:57Z")

</div>

I did notice that P5.js and processing.js were very strict about having to declare the var as a color. So even being able to just use 0x… as a color is is a plus for processing.

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 23, 2018, 1:13am UTC](https://discourse.processing.org/t/not-understanding-this/5826/9 "2018-11-23T01:13:26Z")

</div>

I think that’s due to the fact that int and color both are similar and to avoid confusing ints with color and viceversa that might have to be set explicitly, to avoid a color being used as normal int… although i can’t think of a case in which that would apply… so take what i said with a grain of salt(or a spoon of salt actually 😅)

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 23, 2018, 1:21am UTC](https://discourse.processing.org/t/not-understanding-this/5826/10 "2018-11-23T01:21:18Z")

</div>

- Processing’s `color` is merely a syntactic sugar for the Java’s keyword `int`.
- Not sure about the initial reason for its inclusion.
- Maybe b/c Processing is a multi-language library, and the actual datatype can be diff. for each 1.
- And having its own `color` keyword allows Processing to represent a webcolor value across diff. flavors under the same label.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 23, 2018, 1:24am UTC](https://discourse.processing.org/t/not-understanding-this/5826/11 "2018-11-23T01:24:15Z")

</div>

Color-related functions interpret the passed `color` argument as gray if it’s within a 0 to 255 range. 🏴  
Otherwise it treats it as a full 32-bit aRGB `color` value. 🖌
