Lecture 2 - Primitive Output
Lecture 2 - Primitive Output
Line: A line is a geometrical structure joining two point.
Rectangle: In general, a rectangle is a four-sided polygon
that has two pairs of parallel and concurrent sides with all
interior angles as right angles.
Rounded Rectangle: A rectangle with arched edges is
known as rounded rectangle. Is represented by Rectangle
class.
Circle: A circle is a line forming a closed loop, every point
on which is a fixed distance from a centre point.
Ellipse: An ellipse is defined by two points, each called a
focus. If any point on the ellipse is taken, the sum of the
distances to the focus points is constant. The size of the
ellipse is determined by the sum of these two distances.
Shape Classes by JavaFX (2)
7
Polygon: A closed shape formed by a number of coplanar
line segments connected end to end.
Polyline: Is the same as a polygon except that a polyline is
not closed in the end. Or, continuous line composed of one or
more line segments. A Polyline is represented by Polygon
class.
Cubic Curve: Is a Bezier parametric curve in the XY plane is
a curve of degree 3.
QuadCurve: A quadratic curve is a Bezier parametric curve
in the XY plane is a curve of degree 2.
Arc: An arc is part of a curve.
Properties of 2D Objects
8
Property Description
fill Used to fill the shape with a defined paint.
stroke It represents the colour of the boundary line of the shape.
strokeType It represents the type of the stroke (where the boundary line will
be imposed to the shape) whether inside, outside or centered.
strokeWidth It represents the width of the stroke.
2D Shapes – Rectangles
9
Or
circle.setCenterX(100);
circle.setCenterY(100);
circle.setRadius(50);
Writing Pixels
13
1. Create a pane
Pane pane = new Pane();
2. Create a canvas
Canvas canvas = new Canvas(500, 600);
3. PixelWriter pixelWriter =
canvas.getGraphicsContext2D().getPixelWriter();
4. pixelWriter.setColor(100, 200, Color.BLACK);
There is other Java classes can be used to write a pixel to the screen
Exercise
14