News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_ComSoft6128

Histogrammes 3D by Michel Archambault

Started by ComSoft6128, 07:14, 26 February 22

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ComSoft6128

Type-in from the July/August 1986 issue of the French 'CPC' magazine by the above programmer and author.

From the magazine (taken from CPCRulez):
"3D Histograms
A histogram is a graphical representation of numerical data, in the form of more or less high "buildings" and with several "slices". They are very common in economics journals. They are also called "vertical bar charts". For example, to represent the production of cars, trucks and motorcycles for five countries, each bar represents a country, and is divided into three layers whose height is proportional to the number of units manufactured.
First there was the flat histogram, where each bar is actually a rectangle of varying height; then the three-dimensional histogram where each bar is drawn in perspective, in order to give an impression of volume, of "relief". The visual effect is infinitely nicer, more "flashy", to the point that we would no longer dare to publish a flat histogram, so sad and outdated is the latter compared to its 3D counterpart. And yet, this uniform thickness adds absolutely nothing representative. Note that there are 3D histograms where this thickness is variable since it is proportional to a third parameter: having already experienced it, I can tell you that it is absolutely "undrinkable"!

SOFTWARE OR DEMO?
The author has already offered you two software for graphical representation of data: in "Camembert" (CPC n° 2, page 19) ; in graphics ("TRAGRAPH", CPC No. 6, page 46) . The first idea was therefore to do the same with the histograms; however, the number of questions-parameters turned out to be off-putting for a future user. Not valid. Indeed, in practice, this utility will always have the same histogram to represent, except for heights of course. Better (personal opinion) to present a demonstration program, but explained in every detail, so that you can quickly program yours, to the measurements of your precise problem. It will become a subroutine of your program (accounting, statistics, etc.).

Since the listing is short, try it quickly. Lazy people can dispense with the REM and lines 400 to 460, but with lines 500 to 530.

THE FINAL RESULT
Let's say right away that the digital volumes presented as examples are completely bogus and bear no relation to reality, far from it... The theme is professional microcomputers in five European countries. So, five bars (we also say "columns". In each, three headings: from bottom to top IBM-PC (in yellow), APPLE (in sky blue) and miscellaneous (in red).

Each bar is surmounted by its legend. At the bottom of the screen, the legends of headings in three colors.

For a drawn bar, we will talk later about its "front", its "flank" and its "top". To give relief, these three faces are delimited by the outline of the edges in dark blue. The total trace is done in 10.8 seconds. By typing a key, you cause a CLS.

Small optional gadget (lines 400 to 460), each block-heading is captioned by the numerical value that gave it birth.

THE DETAILED PROGRAM
The numerical values as well as the legends have been put in DATA (lines 50 to 90). We call N the column number (1 to 5) and R the heading number (1 to 3).

The horizontal progression X

On the X axis, there are 640 points; here is how they are distributed: space between columns (or BORDER) = 30. That is a total for the spaces of 30 x (5+1) = 180 points. It therefore remains for the bars 640-180 = 460, or 460/5 = 92 points per bar. These are divided into 70 points for the front plus 22 for the right flank.

The inter-column "step" is therefore 92 + 30 = 122 points. OK ? So, you would know to redo these simple calculations for another number of columns (3, 4, 6, etc.).

Let's explain line 220: we will start the first bar at X = 30, then we will have four jumps to make to end with number five. Hence a progression in X up to 30 + (4 x 122) = 518 in steps of 122.

The vertical progression Y

We have 400 points. Let's count a maximum height per bar of 300 points. Remain 100 to distribute between low and high margins.

The oblique lines that will draw the side are 22 in X. For them to be straight and not in steps of stairs, they must rise at 45°; therefore also 22 in Y.

We will draw a horizontal line of 70 followed by an oblique line of 22 by 22 whose PEN number will be that of the R section. We will stack these lines upwards but with a STEP in Y of 2 and not of 1 . Why ? Because AMSTRAD's 400 Y-points actually correspond to 200 screen lines! A STEP of 1 would cause the same line to be drawn twice on itself (= about twice the time).

The ORY variable is the Y origin for each heading start. Initially, line 230, we initialize it to 50, this is our low margin.

As soon as a section is finished, ORY takes the last accumulated value of Y (line 260), in order to attack the next section.

We have thus just traced the front and the side of a bar. The coordinates of the graphic cursor are then stored (line 280).

TOP OF THE BAR
It is drawn by horizontal lines length 70 to the left, starting from the stored point and descending this starting PLOT obliquely. Everything is in line 290. In the end, the cursor is in the top left corner of the facade. Let's take this opportunity to move it in order to write in TAG the caption of the column (line 300). Reminder: a TAG string must be followed by a semicolon, otherwise the string would be followed by strange characters...

In line 300, why a PLOTR of 33.40? A letter occupies a square of 16x16 graphic points in MODE 1, the graphic cursor is at the top left of the first square-letter. The height of the column "top" is 22; leave at least 2 dots between it and the letter, which starts 16 dots above. We have 22 + 2 + 16 = 40 points in Y. On the other hand, our country legends make three letters, i.e. 16x3 = 48 points: to center on the back face of the bar, it will be necessary to shift from (70-481 /2 = 11, plus 22 for the left oblique edge = 33 offset in X.

The outline of the edges

We put the cursor back where it had been stored (line 310), we trace downwards diagonally, horizontally, we come back to the "break", and we trace the large vertical edge. Elementary.

The display of quantities (lines 400 to 460)

Completely optional, because if a heading block is less than 20 points high, it would be a disaster with numbers 16 high!

On the other hand, writing by TAG poses problems because it must be combined here with transparency (with CHR$(22)). The listing having become much too heavy for this gadget, we have simplified by displaying it by LCOATE; hence positionings "rounded" to the nearest, which therefore are not always well centered in the section.

The finale (lines 500 to 530)

Without the CALL &BB06 waiting for a key, we would have a terrible "READY" at the top left of the screen! Here you can insert a hard-copy screen command on the printer.

SOME VARIANTS
Our numeric values in DATA never exceed a total of 300 per column, because of our 300 graphic points. With your real values, it is up to you to define a multiplier coefficient which will transform them into a number of graphic points.
If you want a title at the top of the screen, consider lowering this maximum from 300 to around 260.
For more than three sections, it would be a shame to switch to MODE 0; after PEN 3, continue with PEN 5, PEN 6, etc. ( = PEN 1, PEN 2, etc.) avoiding PEN 4 ( = PAPER). In order to differentiate these colors bis, use for these headings a STEP of 4, from where a layout in hatchings completely acceptable.
SCREEN COPY ON PRINTER

With a simple hard-copy program, the whole column will be black with all three edges white. Not pretty ! Two remedies:

a) Use commercial software that translates the different PENs into different shades. Example "TASCOPY".

b) Hatch with STEP 4 the headings n° 1 and 3. To do this, add a line 245:

245 ST = 4: IF R = 2 THEN ST = 2 then modify line 250 by replacing STEP 2 with STEP ST. Similarly, line 290, replace STEP 2 with STEP 4.

CONCLUSION
We wanted to demonstrate two things: that we can draw professional quality histograms with a short listing. That the calculations of these parameters are within everyone's reach."


Links:
https://www.cpc-power.com/index.php?page=detail&num=9305
https://www.cpc-power.com/index.php?page=staff&lenom=Michel%20ARCHAMBAULT
https://cpcrulez.fr/auteur-michel_archambault.htm
https://www.cpcwiki.eu/index.php/CPC_(magazine)

Not emulated - original hardware and software.
Please note that  the aspect ratio for this YouTube video is 16:9 but the CPC monitor
has an aspect ratio of 4:3 so you may wish to adjust your viewing device accordingly.




Powered by SMFPacks Menu Editor Mod