REFPIN.RU e-mael для контактов: refpin.ru@mail.ru |
Лабораторна робота 1
Вивчення графічних елементів для створення простих рисунків за допомогою мови програмування Processing Language та середовища програмування Processing
Мета заняття.
Вивчити функції для встановлення параметрів графічного вікна
Вивчити функції для малювання графічних примітивів
Намалювати малюнок у програмі Procesing відповідно до варіанту.
Теоретичні відомості:
Джерело інформації сайт http://processing.org/
Мова Processing розроблена для полегшення створення складних візуальних рисунків.
Одна з найпростіших структур програми складається з двох фрагментів
void setup()
{
Функції для налаштування вікна для графіки (розмір, колір)
}
void draw()
{
Функції для малювання графіки (графічні примітиви, їхній розмір та колір)
}
Деякі функції для налаштування вікна для графіки
size(); // розмір вікна для малювання в пікселях
background(); //rgb колір фону
fill();//колір малювання
noFill();
stroke();// колір обводу контуру
noStroke();
Деякі функції для створення графіки
arc();//дуга кола та частини круга
ellipse();//еліпс
line();//лінії
point();//точки
qard();//полігон
rect();//прямокутники
triangle();//трикутники
Детальний опис функцій
Examples arc(); |
arc(50, 55, 50, 50, 0, HALF_PI); noFill(); arc(50, 55, 60, 60, HALF_PI, PI); arc(50, 55, 70, 70, PI, PI+QUARTER_PI); arc(50, 55, 80, 80, PI+QUARTER_PI, TWO_PI); arc(50, 50, 80, 80, 0, PI+QUARTER_PI, OPEN); arc(50, 50, 80, 80, 0, PI+QUARTER_PI, CHORD); arc(50, 50, 80, 80, 0, PI+QUARTER_PI, PIE); |
Description |
Draws an arc to the screen. Arcs are drawn along the outer edge of an ellipse defined by the a, b, c, andd parameters. The origin of the arc's ellipse may be changed with the ellipseMode() function. Use thestart and stop parameters to specify the angles (in radians) at which to draw the arc. |
Syntax |
arc(a, b, c, d, start, stop) arc(a, b, c, d, start, stop, mode) |
Parameters |
a float: x-coordinate of the arc's ellipse b float: y-coordinate of the arc's ellipse c float: width of the arc's ellipse by default d float: height of the arc's ellipse by default start float: angle to start the arc, specified in radians stop float: angle to stop the arc, specified in radians |
Name |
ellipse() |
Examples |
ellipse(56, 46, 55, 55); |
Description |
Draws an ellipse (oval) to the screen. An ellipse with equal width and height is a circle. By default, the first two parameters set the location, and the third and fourth parameters set the shape's width and height. The origin may be changed with the ellipseMode() function. |
Syntax |
ellipse(a, b, c, d) |
Parameters |
a float: x-coordinate of the ellipse b float: y-coordinate of the ellipse c float: width of the ellipse by default d float: height of the ellipse by default |
Name |
line() |
Examples |
line(30, 20, 85, 75); line(30, 20, 85, 20); stroke(126); line(85, 20, 85, 75); stroke(255); line(85, 75, 30, 75); // Drawing lines in 3D requires P3D // as a parameter to size() size(100, 100, P3D); line(30, 20, 0, 85, 20, 15); stroke(126); line(85, 20, 15, 85, 75, 0); stroke(255); line(85, 75, 0, 30, 75, -50); |
Description |
Draws a line (a direct path between two points) to the screen. The version of line() with four parameters draws the line in 2D. To color a line, use the stroke() function. A line cannot be filled, therefore the fill() function will not affect the color of a line. 2D lines are drawn with a width of one pixel by default, but this can be changed with the strokeWeight() function. The version with six parameters allows the line to be placed anywhere within XYZ space. Drawing this shape in 3D with the z parameter requires the P3D parameter in combination with size() as shown in the above example. |
Syntax |
line(x1, y1, x2, y2) line(x1, y1, z1, x2, y2, z2) |
Parameters |
x1 float: x-coordinate of the first point y1 float: y-coordinate of the first point x2 float: x-coordinate of the second point y2 float: y-coordinate of the second point z1 float: z-coordinate of the first point z2 float: z-coordinate of the second point |
Name |
point() |
Examples |
noSmooth(); point(30, 20); point(85, 20); point(85, 75); point(30, 75); size(100, 100, P3D); noSmooth(); point(30, 20, -50); point(85, 20, -50); point(85, 75, -50); point(30, 75, -50); |
Description |
Draws a point, a coordinate in space at the dimension of one pixel. The first parameter is the horizontal value for the point, the second value is the vertical value for the point, and the optional third value is the depth value. Drawing this shape in 3D with the z parameter requires the P3D parameter in combination with size() as shown in the above example. |
Syntax |
point(x, y) point(x, y, z) |
Parameters |
x float: x-coordinate of the point y float: y-coordinate of the point z float: z-coordinate of the point |
Name |
quad() |
Examples |
quad(38, 31, 86, 20, 69, 63, 30, 76); |
Description |
A quad is a quadrilateral, a four sided polygon. It is similar to a rectangle, but the angles between its edges are not constrained to ninety degrees. The first pair of parameters (x1,y1) sets the first vertex and the subsequent pairs should proceed clockwise or counter-clockwise around the defined shape. |
Syntax |
quad(x1, y1, x2, y2, x3, y3, x4, y4) |
Parameters |
x1 float: x-coordinate of the first corner y1 float: y-coordinate of the first corner x2 float: x-coordinate of the second corner y2 float: y-coordinate of the second corner x3 float: x-coordinate of the third corner y3 float: y-coordinate of the third corner x4 float: x-coordinate of the fourth corner y4 float: y-coordinate of the fourth corner |
Name |
rect() |
Examples |
rect(30, 20, 55, 55); rect(30, 20, 55, 55, 7); rect(30, 20, 55, 55, 3, 6, 12, 18); |
Description |
Draws a rectangle to the screen. A rectangle is a four-sided shape with every angle at ninety degrees. By default, the first two parameters set the location of the upper-left corner, the third sets the width, and the fourth sets the height. The way these parameters are interpreted, however, may be changed with the rectMode() function. |
Syntax |
rect(a, b, c, d) rect(a, b, c, d, r) rect(a, b, c, d, tl, tr, br, bl) |
Parameters |
a float: x-coordinate of the rectangle by default b float: y-coordinate of the rectangle by default c float: width of the rectangle by default d float: height of the rectangle by default r float: radii for all four corners tl float: radius for top-left corner tr float: radius for top-right corner br float: radius for bottom-right corner bl float: radius for bottom-left corner |
Name |
triangle() |
Examples |
triangle(30, 75, 58, 20, 86, 75); |
Description |
A triangle is a plane created by connecting three points. The first two arguments specify the first point, the middle two arguments specify the second point, and the last two arguments specify the third point. |
Syntax |
triangle(x1, y1, x2, y2, x3, y3) |
Parameters |
x1 float: x-coordinate of the first point y1 float: y-coordinate of the first point x2 float: x-coordinate of the second point y2 float: y-coordinate of the second point x3 float: x-coordinate of the third point y3 float: y-coordinate of the third point |
Варіанти завдань
Врахувати: що вісь х йде зліва направо, а вісь у - згори на низ.
1.
2.
3.
.
4.
5.
6.
7.
8.
9.
10,
11.
12.
13
Один з елементів на вибір
1. Особливості мови об’єктно-орiєнтованого програмування С++
2. Типові оператори та базові конструкції мови програмування Паскаль
5. Кросплатформне програмування
7. Програмування циклічних обчислень
8. Програмування циклічних алгоритмів на С++