10.014 CTD
  • Overview
  • Schedule
  • Administrative
    • Accessing Rhino remotely
    • Rhino for Mac
  • ASSIGNMENTS
    • Dates and rubrics
    • Generative design
      • Generative design
    • Parametric design
      • Parametric design
    • Simulated design
      • Simulated design
      • Simulated design
  • SESSION 1B
    • Computer Aided Design
    • Ranges and expressions 1
      • Ranges and expressions 2
      • Ranges and expressions 3
      • Ranges and expressions 4
      • Ranges and expressions 5
      • Ranges and expressions 6
  • SESSION 2A
    • Visual programming 1
      • Visual programming 2
      • Visual programming 3
      • Visual programming 4
    • Associative modelling 1
      • Associative modelling 2
      • Associative modelling 3
  • SESSION 2B
    • Logical Patterns 1
      • Logical patterns 2
      • Logical patterns 3
  • SESSION 3A
    • Spatial geometry 1
      • Spatial geometry 2
      • Spatial geometry 3
      • Spatial geometry 4
      • Spatial geometry 5
      • Spatial geometry 6
      • Spatial geometry 7
    • Curve geometry 1
      • Curve geometry 2
      • Curve geometry 3
      • Curve geometry 4
  • SESSION 3B
    • Surface geometry
    • Parametric modelling 1
      • Parametric modelling 2
      • Parametric modelling 3
      • Parametric modelling 4
  • SESSION 4A
    • Information nesting 1
      • Information nesting 2
      • Information nesting 3
    • Data landscapes 1
      • Data landscapes 2
      • Data Landscapes 3
      • Data landscapes 4
  • SESSION 4B
    • Mesh geometry 1
      • Mesh geometry 2
      • Mesh geometry 3
  • SESSION 5A
    • Space and time 1
      • Space and time 2
    • Modelling entities 1
      • Modelling entities 2
      • Modelling entities 3
  • SESSION 5B
    • Multibody dynamics 1
      • Multibody dynamics 2
    • Material elasticity 1
      • Material elasticity 2
      • Material elasticity 3
  • SESSION 6A
    • Form-finding 1
      • Form-finding 2
      • Form-finding 3
      • Form-finding 4
  • SESSION 6B
    • AI Image generation 1
      • AI Image generation 2
      • AI Image generation 3
  • APPENDIX
    • Spirograph 1
      • Spirograph 2
    • Curves
    • Swarm Intelligence 1
      • Swarm Intelligence 2
    • Hybrid programming 1
      • Hybrid programming 2
Powered by GitBook
On this page
  1. SESSION 1B
  2. Ranges and expressions 1

Ranges and expressions 5

Spreadsheet programming

PreviousRanges and expressions 4NextRanges and expressions 6

Last updated 9 months ago

Visual Attributes

CAD entities beyond their geometry, they can be assigned with visual attributes or styles. Some of those include colour, line-weight, layer index etc. Here we will expand the graphing calculator by introducing colour. We will plot a sequence of points and colour-code each using an RGB (red-green-blue) value.

Combining Multiple Commands

To achieve this we need to compose a sequence of commands per point. First we will draw the point using the “point” command. Then we will issue the “sellast” command which selects the last object placed in the document. Finally, we will invoke the “properties” command and send a sequence of parameters to modify the colour of the currently selected object. Here we will arrange all commands per point in a horizontal mode as seen in the figure. We can still use the copy/paste approach because the spreadsheet inserts tab characters between columns, for which the CAD application understands as “proceed to the next step” instructions.

Suppressing Visual Input

The “properties” command if executed, typically brings up a pop-up dialog box expecting the user to edit an object’s attributes using the graphical user interface (GUI). After all the purpose of CAD is to be a visual medium to geometric design!

However, we wish to suppress all these click requirements and redirect all input to the command line. To achieve this we can prefix the command with a hyphen “-“. Thus instead of the “properties” command, we will use the “-properties” idiom. To terminate the “properties” command we need to issue a series of artificial keystrokes, which is done by adding a couple of “enter” instructions.

Another minor annoyance comes from the spreadsheet’s formula conventions. If we start editing a cell’s contents with the symbol “=” or any other arithmetic operator, you guessed it, including the minus “-” symbol, the application thinks we are trying to enter a formula. This causes errors because “-properties” does not make sense!

We have a conflict of text-input conventions! To overcome this we need to prefix any text content placed in a cell starting with an arithmetic operator with the single quote (‘) character. The expression for the “properties” command as entered in the spreadsheet is seen below. Note that we copy and paste the cell contents the actual hyphens are not copied!

'-properties object color object

This is the second time we encounter the problem of symbolic notation conflict, first with the double quote ordeal for string literals, now with special escape sequence characters. This is all because we expect too much form text as a representation.

Creating Colour Gradients

Colour in computers is traditionally expressed using its primary RGB components. The values we are allowed to use for each component (or channel) is typically an integer in [0, 255], which maps to 8-bits of information per channel and 16 mil colours in total.

The colour [0, 0, 0] is black and [255, 255, 255] is white, with [r, g, b] as components. Colours where R=G=B are greyscale tones. The colour red is [255, 0, 0], green [0, 255, 0] and blue [0, 0, 255]. To produce colour gradients we relate each channel to our time range as seen below:

Channel

Expression

Formula

Red

=INT( B2 * 255 )

Linear Gradient

Green

=INT( B2 * B2 * 255 )

Quadratic Gradient

Blue

=INT( SQRT( B2 ) * 255 )

Square Root Gradient

The “int” function truncates a real number’s decimal places keeping only the integer part, hence int. For example, “int( 3.1415 ) → 3” i.e. no rounding, just dropping the digits. Multiplying the time [0, 1] range by the maximum value allowed “255”, we can create a linear gradient that spans the entire range of reds [0, 255]. To create an “upward” accelerating gradient we use the square of the “time” range for the green channel, and for a “downward” accelerating gradient for the blue channel we use the square root of the “time” range. You may plot the square and square root functions in a graph to get a sense of the “upward” and “downward” notion.

Notice that colours behave like 3D points but with integer coordinates. The formula for the colour-to-text conversion seen below is actually very similar to the point conversion expression but here we drop all decimal points.

= concat( fixed( G50, 0 ), ",", fixed( H50, 0 ), ",", fixed( I50, 0 ) )

Practice

  • Curve functions of the f( x ) = y form, that pass through [0, 0] and [1, 1] and stay within the unit square are very useful because for any input they just redistribute the output. For the colour channels we used f( x ) = x, f( x ) = x * x and f( x ) = sqrt( x ) to create equally spaced and accelerating colour tones. What other re-distributive functions can you think of and what effects they have to points and colours? Model an ease-in / ease-out curve used for in cinema for smooth camera motion.

  • Understanding the concepts of arranging commands both horizontally and vertically; experiment with commands that require such multiple arguments.

  • Experiment with the properties command and modify other object attributes beyond colour. You can execute commands step-by-step manually before automating the process.

  • Executing command line drawing instructions has a short latency involved in parsing the command, going though command user interaction phases, updating the document and rendering the graphics on-screen. We can take advantage of this to create animations by issuing drawing commands, followed by a selection command such as “sellast” or “selall”, followed by a “delete” command. Experiment with animating e.g. the trajectory of projectile following a parabolic path or a video game sprite jumping over an obstacle.

Colouring cells in excel
Colourful spiral example