Statements and Comments
Coordinates
Width and Height
Setup and Draw
No Loop
Loop
Redraw
Functions
Recursion
Recursion 2
CreateGraphics
Points and Lines
Shape Primitives
Simple Curves
Pie Chart
Vertices
Triangle Strip
Bezier
Bezier Ellipse
Variables
Integers and Floats
True/False
Characters and Strings
Datatype Conversion
Variable Scope
Iteration
Embedded Iteration
Conditionals 1
Conditionals 2
Logical Operators
Increment/Decrement
Operator Precedence
Modulo
Distance 1D
Distance 2D
Sine
Sine and Cosine
Sine Wave
Additive Wave
Polar to Cartesian
Arctangent
Graphing 2D Equation
Random
Double Random
Noise 1D
Noise 2D
Noise 3D
NoiseWave
Letters
Words
Displaying
Background Image
Pointillism
Transparency
Sprite
Alphamask
CreateImage
Hue
Saturation
Brightness
Color Wheel
Reading
Creating
Relativity
Linear Gradient
Radial Gradient
Wave Gradient
Translate
Scale
Rotate
Triangle Flower
Arm
Mouse 1D
Mouse 2D
MousePress
Mouse Signals
Easing
Constrain
Storing Input
Mouse Functions
Keyboard
Keyboard Functions
Milliseconds
Clock
Array
Array 2D
Array Objects
Objects
Multiple Constructors
Composite Objects
Inheritance
Neighborhood
Embedded Links
Loading Images
This example is for Processing (BETA) version 149+. If you have a previous version, use the examples included with your software. If you see any errors or have comments, please let us know .
Modulo.
The modulo operator (%) returns the remainder of a number divided by another. As in this example, it is often used to keep numerical values within a set range.
int num = 20;
float c;
void setup()
{
size(200,200);
fill(255);
frameRate(30);
}
void draw()
{
background(0);
c+=0.1;
for(int i=1; i<height/num; i++) {
float x = (c%i)*i*i;
stroke(102);
line(0, i*num, x, i*num);
noStroke();
rect(x, i*num-num/2, 8, num);
}
}