GameMaker (2.3)
Icon

Positronic Graphics and Plotting

Kerry Michael Soileau

You must be logged in to obtain assets

Description

USAGE

Allows the selection of any area of the display for plotting, defining the scaling for the plot, the pen color, optional axes, and a surrounding frame. 2D and 3D plotting is supported; in the 3D case the user can specify a perspective 3D plot (distant objects appear smaller) or a parallel 3D plot in which there is no foreshortening. Clipping is also supported.

DEMO

OVERVIEW

Before calling any of the Positronic Graphics functions, you first must call the ps_graphics() function.

ps_graphics();

Having done this, you next must define the physical area of the screen on which you will draw. This is done with a call to ps_locate. ps_locate takes four parameters a, b, c, d; ps_locate(a,b,c,d) defines the drawing area to be the rectangle with upper left corner (a, b) and lower right corner (c, d). For example:

ps_locate(120,100,650,400);

Next, you must define the correspondence between the physical points on the screen and the virtual scaled points. To do this you simply specify the range of x-values from left to right of the located rectangle, and the range of y-values from bottom to top of the rectangle.

ps_scale(-1,5,-2,3);

If you want the script to do "clipping," i.e. draw only within the confines of the located area, this will be taken care of by default. If for some reason you want to permit plotting outside the box, so to speak, you may optionally turn off the clipping function with this:

ps_clip(false);                 

At this point you may choose to do either 2D or 3D graphics.

==== 2D Graphics ====

To draw a line segment in a scaled rectangle, say from (x1,y1) to (x2,y2), you can make a call to ps_move followed by a call to ps_draw. For example, if you want to draw a line connecting the point (2.3,-4.5) to the point (-2.8,3.4), you could do it this way:

ps_move(2.3,-4.5);
ps_draw(-2.8,3.4);

If you wrote

ps_move(2.3,-4.5);
ps_draw(-2.8,3.4);
ps_draw(1.1,-1.2);

the script will first plot a line segment from (2.3,-4.5) to (-2.8,3.4), and then a line segment from (-2.8,3.4) to (1.1,-1.2), thus creating a path with two segments.

If instead you wanted two unconnected line segments, one from (2.3,-4.5) to (-2.8,3.4) and another from (1.1,-1.2) to (3,4), you would write

ps_move(2.3,-4.5);
ps_draw(-2.8,3.4);
ps_move(1.1,-1.2);
ps_draw(3,4);

You might think of it this way: ps_move lifts the "pen" and drops it at the specified point without making a mark, while ps_draw draws a line segment from the most recent pen position to the specified draw point. Doing a draw automatically updates the pen position.

==== 3D Graphics ====

3D graphics is different from 2D graphics, in the sense that instead of specifying a point in the plane, you specify a point in three dimensional space. The script then computes the appropriate scaled point in the located area and performs draw and move functions accordingly. To do this, the script needs to know the viewpoint position (the "eye") from which the scene is being viewed. The eye is assumed to be looking directly at the point (0,0,0) by default; optionally you can change this "gaze point" with a call to the ps_gaze function. The "up" direction is assumed to be along the positive z-axis, so for instance a line segment from (0,0,0) to (0,0,1) will be rendered as a vertical line segment in the located area. Finally, the script needs to know whether the projection desired is parallel or perspective. A perspective rendering shows foreshortening with distance and is a realistic view. A parallel projection omits foreshortening.

Drawing a line segment from, say, (1,5,-3) to (2,-1,1) as viewed from viewpoint (3,3,3) for a perspective rendering could be done with the following code:

ps_project(ps_PERSPECTIVE);
ps_eye(3,3,3);
ps_move(1,5,-3);
ps_draw(2,-1,1);

End User Licence Agreement (EULA).

Age Rating: 17+

Version

GMS2.3 - Version 23.4.1. Published April 11, 2023

Loading, please wait

Package contents

Loading, please wait

What is the issue?

Loading, please wait