# Apas Content (.apc) block reference > Every block of an Apas Content (.apc) document, with its attributes and a live example: text, maths, scripts, plots, diagrams, questions, slides, notebooks and mindmaps. This file is generated from the engine's own data: every example here is compiled by the engine before the file is published. The page with live examples is https://apasscript.com/docs/apc-blocks.html and the full function reference is https://apasscript.com/docs/. An `.apc` file is a lesson, worksheet, question set, notebook or slide deck written as plain text. It is an ordered list of blocks. The same file is shown on the web and printed as a PDF. ## Rules every file follows 1. A file is a flat list of blocks from top to bottom. There is no ``, `
`, `` or `` wrapper; those are errors. 2. Every line at the top level starts a block or belongs to one that is open. Prose goes in `

...

`. Markdown headings (`#`), bullets (`-`), numbered lines and code fences are not understood. 3. Put each block's tags on their own lines, as in the examples. An opening tag and its attributes stay on one line. 4. Only the tags on this page exist. An unknown tag is an error, not ignored. 5. Inline formatting is `**bold**`, `*italic*`, `$maths$` and code between backticks, each on one line. 6. Numbers are exact: `1/3` stays a fraction, `sqrt(2)` a surd. Ask for a decimal with `decimal(x)`. 7. A picture is written, not attached: a plot or diagram is a ` ``` In a PDF: Calculation lines become aligned equations; plots and diagrams are drawn as vector figures (the final state only). Flowcharts, 3D surfaces and animations have no PDF form. ### `` A code listing. ApasScript listings are also run and their output is shown. Use it to teach the code itself. With no `lang`, or `lang="as"`, the listing is run and its real output is printed under it, so the output is never typed by hand. Any other `lang` (Python, C, ...) is shown as a listing only. Attributes: - `lang`: "as" (the default) runs the listing. Any other language name shows it without running. ApasScript: listing and output: ```apc solve(x^2 + 6*x + 5 = 0, x) ``` Another language, with typed output: ```apc for i in range(3): print(i * i) 0 1 4 ``` ### `` Typed output shown verbatim, to pair with a listing in another language. Never run or checked: what is written is what shows. An ApasScript `` block makes its own output and does not need this. ```apc Enter a number: 7 7 is prime ``` ### `` Textbook pseudocode, shown as a numbered listing and a flowchart. Never run. Only each line's leading keyword and its indentation matter: `if` / `else if` / `else`, `while`, `for`, `repeat ... until`, `do ... while`, `return`, `break`, `continue`, and an optional `algorithm` or `procedure` header on the first line. The rest of the line is free text. A block that does not fit together (an `else` with no `if`, an `until` with no `repeat`) is an error, not a wrong chart. Attributes: - `title`: Shown above the listing. Optional. ```apc algorithm Largest(a, b, c) max ← a if b > max max ← b if c > max max ← c return max ``` In a PDF: The numbered listing only; the flowchart is a web feature. ## Plots A plot is a ` ``` ### Data: line, scatter and area Measured values held in arrays. `plot(g, xs, ys, ...)` joins the points; `scatter(g, xs, ys, colour, label)` shows them as dots; `area(g, xs, ys)` fills down to the axis. With one array, x counts 1, 2, 3, ... ```apc ``` ### Bar chart, pie chart and histogram Counts by category, parts of a whole, or raw data sorted into bins. `bar(g, xs, ys, colour, label)` draws one bar per value. With names for xs, `bar(g, ["Mon", "Tue"], ys)`, each bar is named on the axis; `stacked(g)` stands several bar series on one another. `pie(g, names, values)` draws parts of a whole with each name, value and share beside it; a fourth argument such as `0.6` leaves a hole, which makes a ring. `histogram(g, data, bins)` bins raw data itself. `graph(w, h)` sets the size of any of them in pixels. Bar chart: ```apc ``` Named bars, stacked: ```apc ``` Pie chart: ```apc ``` Ring: ```apc ``` Histogram: ```apc ``` ### Parametric and polar curves Curves given by x(t), y(t) or by r(theta). `plotParametric(g, "x(t)", "y(t)", tmin, tmax, ...)` and `plotPolar(g, "r(theta)", thetaMin, thetaMax, ...)`. `aspect(g, true)` gives both axes the same scale, so a circle looks like a circle. `tracePlot(g, seconds)` makes every curve of the graph draw itself in over that many seconds, a function from left to right, a parametric or polar curve in the order of its parameter. It works for `plot`, `plotParametric` and `plotPolar` alike; in a PDF the finished curves are shown. In one line: `tracePlot(g, "sin(x)", 0, 2*pi, 4)`, `tracePolar(g, "1 + cos(theta)", 0, 2*pi, 4)` and `traceParametric(g, "3*cos(t)", "2*sin(t)", 0, 2*pi, 4)` plot the curve and trace it, with the colour, line type and label after the seconds. ```apc ``` ### Logarithmic axis Growth and decay over many powers of ten. `logScale(g, "x")`, `logScale(g, "y")` or `logScale(g, "both")`. ```apc ``` ## Diagrams A diagram is a ` ``` ### Triangles and angle markers A polygon with its sides and angles labelled. `polygonOn(d, A, B, C, colour, label, fill)` takes any number of corners. `angleMarkerOn(d, vertex, pointOnRay1, pointOnRay2, radius, label, colour)` draws the arc and its label; `rightAngleMarkerOn(d, vertex, pointOnRay1, pointOnRay2, size, label, colour)` draws the square. Neither needs you to work out an angle. ```apc ``` ### Vectors and force diagrams Arrows from a point, by components or by length and angle. `drawOn(d, point, vec(dx, dy), colour, label, arrows)` draws an arrow by its components. `vectorFromOn(d, point, length, degrees, colour, label)` draws one by length and direction, and `segmentFromOn` the same without an arrowhead. `drawOn(d, p1, p2, colour, label)` with two points draws a plain line between them, with no arrowhead: a wire, a side, a plate, a ray path. For an arrow from `p1` to `p2`, add `"one"` after the label; `"two"` puts a head at both ends (a dimension line). Free-body diagram: ```apc ``` ### Curves, arcs and text Smooth paths between points, circular arcs and free labels. `curveBetweenOn(d, a, b, bend, colour, label, style, width)` bends a line between two points; `bend` is signed, and 0 is straight. `curveOn(d, p0, control, p1)` is a Bezier curve. `arcAtOn(d, centre, radius, startDegrees, sweepDegrees, colour)` is part of a circle. `textOn(d, point, "text", colour, fontSize)` places a label. ```apc ``` ### A graph of a function inside a diagram For a coordinate-geometry figure: axes, a line or curve, and marked points. Leave the axes and grid on. A `line` is drawn across the whole diagram; a parabola or other curve is a `plot` on a `graph()` (see Plots), which can sit next to a diagram in the same document. ```apc ``` ### Solids Textbook cubes, prisms, cylinders and spheres, with marked corners and edges. `cubeOn(d, origin, size, dx, dy, colour)` draws a cube in a slanted view; `dx`, `dy` is the offset of the back face. It returns a record whose `vertices` are the exact corner points, so markers and labels attach to the figure. `prismOn`, `cylinderOn` and `sphereOn` work the same way. `cornerMarkerOn(d, point, label, colour)` puts a labelled dot on a corner; `edgeMarkerOn(d, a, b, fraction, label, colour)` puts one part-way along an edge. ```apc ``` ### Springs, coils and fields Ready-made physics shapes and field pictures. `springOn(d, start, end, amplitude, turns, colour)`, `coilOn` and `inductorOn` draw between two attachment points. `vectorFieldOn(d, "Fx", "Fy", xmin, xmax, ymin, ymax, nx, ny, mode, scale, colour)` draws a grid of arrows; the mode is `"direction"`, `"scaled"` or `"capped"`. `pointChargeLinesOn(d, centre, charge, lineCount, xmin, xmax, ymin, ymax)` draws the field lines of one charge, and `fieldLineOn` traces one line of any field. Spring and mass: ```apc ``` Field of a positive charge: ```apc ``` ### Circuits Resistors, cells, meters and the other circuit symbols, one call each. Name the corners of the circuit as points, then put one component on each branch: `resistorOn(d, a, b, label)`, `cellOn`, `batteryOn(d, a, b, cells, label)`, `capacitorOn`, `bulbOn`, `variableResistorOn`, `inductorOn(d, a, b, label)`, `acSourceOn`, `diodeOn` and `zenerDiodeOn` (the triangle points from `a` to `b`), `meterOn(d, a, b, "A", label)` and `switchKeyOn(d, a, b, "open", label)`. Each draws its symbol in the middle of the branch and the lead wires out to both points, so do not draw the zigzag or the leads yourself. A cell's positive (long) plate faces its second point. The label is an argument, not a separate `textOn`: the engine puts it beside the symbol and clear of it, outside the circuit by default. Add a side (`"above"`, `"below"`, `"left"`, `"right"`) after the label to choose. `wireOn(d, p1, p2, p3)` joins the remaining corners, `junctionOn(d, p, "A")` marks and names a node, `currentArrowOn(d, a, b, "I")` shows a current on a wire, `terminalOn(d, p, "A")` ends a wire in an open ring, `groundOn(d, p)` earths a point and `labelAtOn(d, p, "+", "left")` writes beside a point. Three symbols take more than two points. `transistorOn(d, base, collector, emitter, "npn", label)` draws the transistor and its three leads: put the collector and emitter one above the other and the base to one side, level with their middle. `gateOn(d, "nand", inputA, inputB, output, label)` draws a logic gate (`"and"`, `"or"`, `"not"` with one input, `"nand"`, `"nor"`, `"xor"`, `"xnor"`) with its leads; give one gate's output point as the next gate's input to connect them. `twoWaySwitchOn(d, pivot, contactA, contactB, "a", label)` draws a switch thrown to contact `"a"` or `"b"`, or `"open"`. Symbols have a fixed size on the page, so set `xrangeOn` and `yrangeOn` first, and choose ranges that give each branch about 80 px or more: at least 2 units when the diagram shows 40 px per unit. Two resistors in parallel, with an ammeter: ```apc ``` ### Sliders and animation A picture the reader can change, or one that moves. `slider(label, min, max, step, start)` gives a value the reader can drag; the script runs again with the new value. `animate(tmin, tmax, frames, f)` calls your function `f(t)` once per frame; each call draws one frame with the functions that have no `On` (`draw`, `text`, `vectorFrom`, ...). Slider: ```apc ``` Animation: ```apc ``` In a PDF: A slider shows its starting value. An animation has no PDF form. ### 3D surfaces A surface z = f(x, y) the reader can turn. `surf("expression in x and y", xmin, xmax, ymin, ymax)` draws a shaded surface; `mesh` a wireframe; `surfc` adds contour lines on the floor. ```apc ``` In a PDF: None. Export a PNG from the web page and include it with ``. ## Images, audio and video Files that already exist. The path or address may be written between the tags or as a `src` attribute; use one form consistently. ### `` A picture from a file or web address. Use it for photographs, scans and drawings made elsewhere. A diagram you can describe is better written as a `