MPDA’22
October 14, 2021
Programming is a way to “instruct the computer to perform various tasks”.
'instruct the computer'
?It means that you privide the computer with a set of instructions in a language it can understand.
That language, in our case, will be python
'perform various tasks'
?A task could be anything. For example:
Python
?Python is an object-oriented programming language, first developed in 1980.
It has become extremelly popular in recent years due to its ease of use.
object oriented means that the language is structured around objects
, which are also called classes
:
class
contains (or encapsulates) a specific functionality.During this semester, we’ll be making this two questions a lot:
Python
structureVariables store information to be referenced and used by programs.
They also provide a way of labeling data with a descriptive name.
Computed variables have values that are the result of an operation.
This operation can be very simple (like a sum), or extremelly complex.
Functions (also called methods sometimes), encapsulate a specific functionality in a specific name.
This allows you to reuse the same logic in different parts of your program.
Functions can have many inputs, but only one output called the return value of the function
class Person:
name = "Alan"
surname = "Rynne"
def FullName(name, surname):
return name + " " + surname
Classes contain variables and methods(functions), that are related to the same concept.
Libraries are a collection of classes defined by a given name and have to be imported into your script.
math
library contains many usefull functions like sin()
or cos()
Rhino
library contains everything Rhino relatedPython already comes with some basic classes, which are usually refered to as data-types.
These data-types contain the most basic of functionality
Some basic data-types are:
Type | Name | Example |
---|---|---|
int |
Integer | 5 |
double |
Double | 1.0435 |
bool |
Boolean | True , False |
str |
String | "Just text" |
char |
Character | 'a' |
Other more complex data-types include collections:
Type | Name | Example |
---|---|---|
[] |
List | [1,4,5,8] |
() |
Tuple | ("Alan","Programmer") |
{} |
Dictionary | {1:"Steve", 2:"Bill"} |
We will be using many Rhino
classes during this course. Mainly the ones under Rhino.Geometry
Some of the most popular ones will be
Type | Name | Example |
---|---|---|
Point3d |
3D Point | RG.Point3d() |
Vector3d |
3D Vector | RG.Vector3d() |
Polyline |
Polyline | RG.Polyline() |
NurbsCurve |
3D Curve | RG.NurbsCurve() |
Mesh |
Polygonal Mesh | RG.Mesh() |
NurbsSurface |
Nurbs Surface | RG.NurbsSurface() |
We will be using the GHPython
component
And VSCode further in the course
Comments
Comments are just text, they do not affect our code in any way.
They are used to include detailed instructions or clarifications in our code.
Comments in
Python
always start with a hashtag#