1 of 12

Графічні примітиви

2 of 12

3 of 12

команда

дія

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);

заливка фігури

4 of 12

2D Primitives

5 of 12

Setting

6 of 12

Цикли

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;

}

7 of 12

Цикли з параметром

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 );

}

8 of 12

Цикли з параметром

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 );

}

9 of 12

Подія

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);

}

10 of 12

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);

}

}

11 of 12

Системні змінні

  • width - ширина полотна
  • height - висота полотна
  • frameCount - кількість опрацьованих кадрів
  • millis - кількість мілісекунд від запуску проекту
  • screen.width - ширина екрану
  • screen.height - висота екрану
  • key - остання натиснута клавіша
  • keyPressed - чи натиснута клавіша (True or False)
  • mousePressed - чи натиснута кнопка миші (True or False)
  • mouseButton - яка кнопка миші натиснута

12 of 12

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);