Графічні примітиви
команда | дія |
size (400,400); | розмір аркуша |
background (0,255,255); | фон аркуша |
point (100,100); | точка |
strokeWeight(6); | товщина точки |
line(40,30,60,90); | лінія |
stroke (red,green,blue); | колір лінії |
rect(40,30,30,70); | прямокутник |
fill(255,255,0, 128); | заливка фігури |
Setting
Цикли
size (500,500);
background (255,255,255);
int a=60;
int y=100;
int x=0;
while (a>5)
{
int red=int(random(255));
int green=int(random(255));
int blue=int(random(255));
fill (red,green,blue);
rect(x,y,a,a);
x=x+a;
a=a-5;
}
Цикли з параметром
size (500,500);
background (255,255,255);
int x=250;
int y=250;
for (int r=100; r>=0; r -=5 )
{
int red=int(random(255));
int g=int(random(255));
int b=int(random(255));
fill (red,g,b);
ellipse (x, y, r, r );
}
Цикли з параметром
size (500,500);
background (255,255,255);
int x=255;
int y=255;
for (int r=100; r>=0; r -=5 )
{
int red=int(random(255));
int g=int(random(255));
int b=int(random(255));
fill (red,g,b);
rect(x, y, r, r );
}
Подія
void setup()
{
size (640,480);
background (255,0,0);
strokeWeight(6);
stroke(0,255,0);
}
void draw()
{
point (mouseX, mouseY);
}
void draw()
{
line (pmouseX, pmouseY, mouseX, mouseY);
}
void setup()
{
size (640,480);
background (255,0,0);
strokeWeight(6);
stroke(0,255,0);
}
void mousePressed()
{
background (255,0,0);
}
void draw()
{
if (mousePressed == true)
{
line (pmouseX, pmouseY, mouseX, mouseY);
}
}
Системні змінні
float green=dist(mouseX,mouseY,width/2,height/2);
stroke(0,green,0);
float speed = dist(pmouseX, pmouseY, mouseX, mouseY);
float alpha = map(speed, 0, 20, 0, 255);
float lineWidth = map(speed, 0, 10, 10, 1);
lineWidth=constrain(lineWidth,0,10);
обмежує значення товщини лінії lineWidth в межі від 0 до 10.
float red = map(mouseX, 0, width, 0, 255);
float blue = map(mouseY, 0, width, 0, 255);
float green = dist(mouseX,mouseY,width/2,height/2);
float speed =
dist(pmouseX, pmouseY, mouseX, mouseY);
float alpha = map(speed, 0, 20, 0, 255);
float lineWidth = map(speed, 0, 10, 10, 1);
lineWidth = constrain(lineWidth, 0, 10);
stroke(red, green, blue, 255);
strokeWeight(lineWidth);
line (pmouseX, pmouseY, mouseX, mouseY);