<jupyter_start><jupyter_text>Code, Notation, and DiagramWhile an introduction to computer programming is well-troddenground, there are two things that make this presentation unique. First,its pairing of a foundational discussion of code alongside computationalgeometry and visual design applications. Second, and perhapsmore importantly, the visual diagrammatic language which has beendeveloped for the express purpose of this text.  Setting the StageThe following block of code gets things ready for the example to follow: importing a few libraries we'll need, and defining a 'container' to hold some geometry. Unlike working in Grasshopper, in which the stage has already been set for us using the Decod.es plugin, nearly every piece of code we run here on the Jupyter platform will require some sort of header code such as this.**Don't panic**. We don't expect you to understand what you see here, an all will become clear in time.> To continue, **run the following code block**. > To run a code block, select it and press ***SHIFT + RETURN*** at the same time (or press the "Run" button in the toolbar). After you do so, the Python shell will execute the contained code, and may report some information back. In this case, expect to see that the decod.es library has successfully loaded by displaying a URL.<jupyter_code>from decodes.core import *
from decodes.io.jupyter_out import JupyterOut
out = JupyterOut.unit_square( grid_color = Color(0.95,0.95,0.95) )
import math<jupyter_output><empty_output><jupyter_text>A Sample ScriptWhile we have not yet discussed all the concepts we need to completelyunderstand this script, we can infer quite a bit from investigatingthe relationship between it and the **control flow diagram**, **objectmodel diagram**, and **geometry diagram** found below.> **Run the following code block**, in the same way you did above. Note that if you failed to run the above code, or have restarted the kernel since doing so, that you may recieve an error message.<jupyter_code>count = 100
scale = 0.15
pts=[]
for n in range(count):
    theta=((math.pi*2)/(count-1))*n
    pt = Point(theta*scale,math.sin(theta)*scale)
    pts.append(pt)
pl = PLine(pts)

out.put(pl)<jupyter_output><empty_output><jupyter_text>Textual OutputThe first place we'll look for feedback on what our scripts are doing is **the console**.The console is a graphic device which is our most directwindow on the inner workings of the shell. If the scripts we authorare one side of a conversation – a way of explaining to the shell whatwe would like it to do – then the console is one way that we cansee what the computer has to say in response.> **Run the following code block**, in the same way you did above.<jupyter_code>print(pl)<jupyter_output>pline[10v]<jupyter_text>Control Flow DiagramsThe control flow diagram is used to describe the order of executionof the various commands and definitions found in any piece of code.Although code is generally executed by the shell starting at the top ofthe script we provide, and concludes when it reaches the end, thereexist a range of structures which can alter this sequence. The connectedlines, indentation, arrows, and flowchart-style decision pointgraphics found in this diagram provide a visual representation of this“flow” of execution and the structures we may employ to control it. A simplified version of the control flow diagram may be found next to every piece of sample code in the text.  Geometric OutputNaturally, since decod.es is a geometry library, one of our primary means for understanding the working of our code will be to examine the results. While working in a CAD context, such as Grasshopper, will be invaluable in this regard, we have a limited means for viewing the geometric results of our scripts here in Jupyter. For the time being, the results we view here are limited to 2d plots.>**Execute the following code block**, in the same way you did above. When you do, you should see the results of this code plotted as a graphic.<jupyter_code>out.draw()
out.clear()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.055773955773955775, 'fraction_numerical': 0.004914004914004914, 'mean_word_length': 5.0670640834575265, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '322618', 'license': 'MIT', 'n_tokens_mistral': 1043, 'n_tokens_neox': 1001, 'n_words': 598, 'path': '101 - Elements of a Computation/014 - Code, Notation, and Diagram.ipynb', 'repo_name': 'ksteinfe/decodes_ipynb', 'size': '4070'}