Learn creative coding writing simple programs
96. Easier mouse in a rectangle
Using rectMode(CENTER) makes it harder to find out if the mouse is inside a square. If we use rectMode(CORNERS) the program becomes much simpler because we don't need to calculate the position of the four walls of our rectangle: we already know them.
In this episode we also see a small example of how we can generate colors that have the same hue but a different brightness or saturation.
Code editor
You can make changes to the code below. Then
Reference
background
boolean
color
colorMode
draw
fill
float
if
int
mousePressed
mouseX
mouseY
noStroke
random
rect
rectMode
return
setup
size
void
background
boolean
color
colorMode
draw
fill
float
if
int
mousePressed
mouseX
mouseY
noStroke
random
rect
rectMode
return
setup
size
void
Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)
To indicate that a word in your comment is code, use the `backtick`. Example
Do `float` and `int` smell similar?
To highlight code blocks, surround it with ``` code-fences ``` like this:``` void setup() { size(600, 600); } ```