OLR C ea
Build Your Own 3D Sigil
Generator
hyperritual
Contents
1-1: Constructing Sigils with a Computer .....0.:sssesnnnnnnnie een
1.2: Introducing Processin,
1-3: Course Outline.
Week 2...
Week 3... 15,
‘Week 5... / ee AM NS e ROMS 25 23
Week 6 cect A on PES 28Build Your Own 3D Sigil Generator Iyperritual
14: Constructing Sigils with a Computer
‘Most of us here likely have a pretty commion notion of what a sigil is, but for those new to the
subject or who may yet be wondering what constitutes a sigil in the context of this course,
please see the Wikipedia entry on sigils,
There are many Ways of constructing sigils: formal, informal, rigorous, spontaneous... And
there are many ways of constructing sigils with a computer, you could use your favorite
drawing program, for example (T usually use Inkscape and/or GIMP). For this class, we are
going to create our own drawing program from scratch, There are again many ways we could
do this, but they all involve telling the computer how to dravw the sigil, in-a language the
computer understands, That is, we must specify an algorithm that breaks the drawing process
down into a finite series of steps that the computer can do, which when synthesized produce a
sigil that we can use in ritual magic [1]. Soive er coagula.
There are existing algorithmic methods for constructing magical sigils. Sigils drawn with
devices such as kameas or magic squares, of the Rose-Cross cipher, are good examples that
readily meet the formalities of computer programming languages. These are well-defined
arrangements of letters having magical correspondences, to which we can map words
expressing or representing our intentions. An algorithm for constructing a sigil using the
Rose-Cross cipher miight look like this:
+ Decide on a word to express or represent our intent (if we were creating @ computer
program, this would be the input)
+ For each letter in that word...
+ locate the letter's position on the cipher, and...
+ draw a line from that position to the position corresponding to the next letter in the
word.
+ If there is no "next" letter ~i.¢, we are at the end of the word ~ then stop drawing.
That is something we can easily implement with a computer, and we will during this course,
but we are going to take it into another dimension. Imagine that the cipher is not drawn on a
two-dimensional plane, but in a three-dimensional space, and that the letters in the cipher do
not only vary horizontally (x axis) and vertically (y axis), but also deeply (z axis). Now when
‘we map our input word to the cipher, the result (i.e. oufput) isa sigil in three dimensions.
This could be difficult to do physically. How would we suspend the letters in space, in order
to draw lines between them? [2] But with a computer, for which space is virtual, we can
easily show the points and lines between them in three dimensions. [3] We can move the
points (called vertices) while conserving their relative distances, and thus rotate the si
2Build Your Own 3D Sigil Generator Iyperritual
along all three axes
‘The computer programming language we are going to demonstrate this with is called
Processing. Please see section 1-2 for more about that and to get started with it
So as not to obfuscate the basic principles before we have learned them, we are going to work
with a regular cubic structure and the present English alphabet of 26 characters. Since 26 is
not evenly divisible by 3, we will add a "space" character to the center of the cube, around
which to arrange the remaining 26 as a 3x3 super-cube:
ABC JKL R&T
DEF M N/UVW
GHI OPQ Wya
However, please feel free to share your ideas about other alphabets and arrangements, and
also to create and share Processing sketches that demonstrate your ideas. This course is
intended to teach you the basics of Processing, which will start you on your way toward very
different means of drawing sigils, if that is what you care to do.
‘As with other courses at Arcaiorium, you are encouraged to maintain your own journal and
share you ideas and accomplishments there (click the New Topic button at right, give it a
name e.g. "Hypetritual’s Journal,” then post your journal entries as replies to this topic).
1. Computers are capable of generative art that uses complexity or randomness to produce
forms that are not specified in detail by the computer's programmer ~- ie. suprising forms —
‘but the methods of generative art are still algorithmic.
2. Thave used Zome for this purpose.
3. And more. A computer ean draw sigils in four, five... as many dimensions was we like, but
for dimensions greater than three, we can only visnalize that part of the n-dimensional sigil
that can be seen in three dimensions.Build Your Own 3D Sigil Generator Iyperritual
1-2: Introducing Processing
Processing is an open source programming language and integrated development
environment (IDE) built for the electronic arts and visual design communities with the
purpose of teaching the basies of computer programming in a visual context, and to serve as
the foundation for electronic sketchbooks (Wikipedia)
‘Here are some things vou can do with Processing, For some suggestions about how to map
these sorts of digital media to ritual magic, please see these pages from a previous course,
Beginning Interactive Multimedia Ritual Design: 1, 2
‘The version of Processing we will use is 1.5.1. Ifyou have 1.2.x, you should be OK, but you
‘may want to update to 1.5.1.
For the first week of this course, please download and install Processing, and run through two
quick tutorials that will show you how to get around the IDE and introduce you to the
language:
© downloading and installing (and troubleshooting)
©) tutorial 1
© tutorial 2
Tam working on # document that will introduce basic programming concepis using
Processing, similar to the one | did for the Scratch class.
‘Ifyou encounter any issues or have any questions, please share them here. Next week we will
begin with a series of sketches that will build up to the 3D sigil generator.Build Your Own 3D Sigil Generator Iyperritual
1-3: Course Outline
Here is an outline of what I expect to cover in the next several weeks, so that you all can get
an idea of what is coming up and also what is nor coming up. If there is something you want
to talk about that is not listed, please mention it in in your journal, and I will try to address it.
Week 1
* downloading and installing Processing
Week 2
* program structure
* drawing 2D lines and shapes
* controlling color and line thickness
* translation
* variables and arrays
Week 2
* keyboard and mouse input
Week 3
* drawing 3D lines and shapes
Week 4
* installing a library
* cteating graphical nser interface (GUI) controls
Week 5
* saving images and movies
Week 6
* putting it all together
* variations
* catch upBuild Your Own 3D Sigil Generator Iyperritual
Week 2
These exercises will introduce you to some basic two-dimensional drawing techniques in
Processing. By now, you should have run through the two online tutorials inked to in Week
1, Here are some things you may have learned during the Week 1 tutorials, but are worth
reviewing:
“Processing (like Java) is case sensitive — x and X mean different things. Most of
‘what you write will be in lower case. Constants are conventionally typed in all caps
(eg., Xs a variable, X is a constant). Class names are capitalized, e.g. Plmage is a
class (more about classes, later).
For compound identifiers such as names of methods, keywords, and variables that
have more than one word, capitalize the first letter of each word except the first (Le.
CamelCase) — e.g., loadimage() instead of loadimage() or load_image() or
something else. Only classes have the first letter capitalized, e.g. Pimage.
“All statements that are not code blocks should end with a semicolon.
Example:line(100, 50,100, 100);
+*Code blocks are enclosed in curly braces
itt) { Line (i*5,.50, i*5, 100)
.for (int i/= 07 4/107
Comments in code begin with two forward slashes (//), or are enclosed between
slashes and asterisks (I* ... */), like this:// this is a one-line comment; it
will not be run by Processing/* this is a multi-line comment;
it-will also not be run */
+Processing's online help is an excellent resource. If you want to know what
something does, e.g. line(), highlight line in the Processing window, right-click on it,
and select Find in Reference, or press [Ctrl + Shift + F]. That will bring up an HTML
help file about line(). You can also review the entire reference by selecting it from the
Help menu, or on processing orgireferencel.Build Your Own 3D Sigil Generator Iyperritual
While you can run a single or batch of statements in Processing, programs are typically
organized like this (do not worry if you do not understand all of the terms, now; (you will
encounter them again and become more familiar with them as we go through the course):
// import Libraries
// declare objects
// declare variables
// run the setup, which runs one time
void setup() {
}
// run the draw loop, which repeats until the program stops
void draw() {
}
// any other functiohs, standard or user-definedBuild Your Own 3D Sigil Generator Iyperritual
Let us run through an example. You can either type or copy-and-paste
this into your Processing window, then press the Play button to run
it. Pay attention to the comments (iI); they explain what each statement is
doing.
void setup() {
size (300, 300); // set window size to 300x300 pixels
background(0); // set background color to black
// set fill color to red using RGB values
// notice that color() is embedded within £i11()
£11 (color (255, 0, 0))5
// set stroke (i.e, out/line) color to RGB green
stroke (color(0, 255, .0))7
strokeWeight (3); ///set out/line thickness to 3 pixels
rectMode (CENTER); // draw rectangls around a center point
}
void draw() (4
// draw a:rectangle in the center of the window
rect (width/2, height/2, 50, 50);
// same\as rect(150, 150, 50,50); since size is 300x300
}Build Your Own 3D Sigil Generator Iyperritual
Variables allow us to generate dynamic content. Let us create a
variable for the square's x (horizontal) position, and move the
square by changing the variable's value.
// declare a variable for the x (horizontal) position of the box
int xPos = 0;
void setup() {
size (300, 300);
background (0) 7
Fill (color (255, 0, 0))7
stroke (color (0, 255, 0));
strokeWeight (3)
rectMode (CENTER) ;
}
void draw() {
// now the tectangle has a vatiable x position
rect (xPos, height/2, 50, 50);
J] each time draw/) runs, increase xPos by 1
unless xPos = width of the window ie. the right edge
if (xPos < width) {// if xPos is less than the width of the window
xPos++; // increment xPos by 1, same as xPos = xPos + 1
}
+
Notice that the square leaves a trail as it moves across the screen: That is because we are
not “clearing” the screen between draws. Notice what happens when we move
background() from setup() to draw():
int xPos = 0;
void setup() {
size(300, 300);
£ill (color (255, 0, 0))7
stroke (color(0,’ 255, 0));
strokeWeight (3);
rectMode (CENTER) 7
}
void draw() {
rect (xPos, height/2, 50, 50);
if (xPos < width) {
=Post+;
}
}Build Your Own 3D Sigil Generator Iyperritual
You can get a cool motion blur effect by drawing a big black
rectangle to cover the entire window, instead of using background(),
and making that rectangle a little transparent by changing the alpha value of its color:
int xPos = 0;
void setup() {
size (300, 300);
£ill (color (255, 0, 0))7
stroke(color(0, 255, 0));
strokeWeight (3);
rectMode (CENTER) ;
}
void draw() {
£111(0, 30); /// set £111 color to black -w/’an alpha of 30
// experiment w/ different values between 0 and 255
// draw rectangle from upper-left corner instead of center
rectModé (CORNER) ;
// draw a blackrectangle from upper-left corner to bottom right
// covers\the entire. window, just like background()
// except: rectangles ‘color is a little transparent
rect(0, 0, width, height);
// change £111 color back to red before drawing square
fill (color (255, 0, 0))7
//. change rectMode back to CENTER before drawing square
re¢tMode (CENTER)
rect (xBos, height/2, 50, 50); // draw the square
// move the square
if (xPos < width) {
xPost+7
)
)
translate() is useful for drawing positions with negative values, which our sigil generator wil
Normally, the coordinate pair (0, 0) is the upper-left-most pixel in the window, and a pixel
drawn at (-1, 0) would not be visible. We can use translate() to effectively move (0, 0) toa
different position in the window.
Here is another way to think about it. If | tell you to draw a square in the middle of a piece of
Paper, you can either move your pencil to the middle of the paper, and begin drawing, or you
can keep your pencil still and move the paper until its middle is just beneath your pencil
Using translate() is like moving the paper. | will show you an example.
10Build Your Own 3D Sigil Generator Iyperritual
The following sketch draws a rectangle from (-25, -25), 50 pixels wide and high.
void setup() {
size (300, 300);
fill(color(255, 0, 0))¢
stroke (color(0, 255, 0))7
strokeWeight (3):
rectMode (CORNER) 7
)
void draw() {
background (0);
rect (-25, -25, 50, 50);
point (80, 80); // just to show you where (80,80) is
(0,0) is here.
Cannot se
(-25, -25).
nBuild Your Own 3D Sigil Generator
By adding just one line to sketch, we “move”
position:
void setup() {
size(300, 300);
fill(color(255, 0, 0))z
stroke (color(0, 255, 0));
strokeWeight (3);
rectMode (CORNER) ;
}
void draw() {
background (0);
translate(80, 80); // tmoves™ (0, 0) to (80)
rect (-25, -25, 50,/50)7
}
(0,
80)
Iypervitual
0) to a different
12Build Your Own 3D Sigil Generator Iyperritual
Do not worry if you do not yet quite grok translate(). It can get especially
confusing when you start working with multiple translations. The main reason I mention it at
all in this course is that it will be part of our sigil generator.
You can use smooth() smoothen lines by slightly blurring them (a technique called anti-
aliasing). Compare the following two sketches (run them in Processing).
void setup() {
size (300, 300)7
fill (color (255, 0, 0))7
stroke (color(0, 255, 0));
strokeWeight (3);
e1LipseMode (CENTER);
}
void draw()
background (0)
ellipse (width/2, height/2,/100, 100);
}
Now with smooth() added:
void setup() {
size (300, 300);
fill (color (255, 0, 0))+
stroke(color(0, 255, 0));
strokeWei ght. (3) ¢
e1]ipseMode (CENTER) ;
smooth ();/// draws smooth’ lines
}
void draw() {
background (0) 7
ellipse (width/2, height/2,100, 100);
}
3Build Your Own 3D Sigil Generator Iyperritual
Arrays and loops.
An array is a variable that can hold more than one value, like a
list of items. A loop tells Processing to repeat a set of operations
a certain number of times or until something happens. Check out this
example:
// declare an integer array
int xPos[] = (1, 2, 3, 5, 8, 13, 21, 34, 55, 89};
void setup() {
size (300, 300);
background (0) ;
stroke (255) 7
}
void draw() {
for (int i = 0;/4 < xPos.lengthy i++) {
Line (xPos[il, 0, xPos{il, height);
printin("loop: "+i#" "#"xPos: "+xPos[11) 7
}
i
It is worth taking some time to analyze and understand this one.
int xPos[] means declare an array of integers, and name the array xPos (the [] tells
Processing that xPos is an array and not just a single integer).
= {1, 2, 3, 5, 8, 13, 21, 34, 55, 89} means put all of those values into the array xPosf].
for (Inti = 0; i < xPos.lenath; I++) } creates a loop code block that repeats some number
of times (i., for each i), in this case, as many times as there are elements in the xPos[]
array (or 10 times; since there are 10 elements in the array).
xPos[l] returns the element of xPos[] at the I'th position. Processing (like most computer
programming languages) begins counting with 0, not 1, so xPos[0] is 1, xPos[1] is 2,
xPos|2] is 3, xPos[3] is 5, etc. The first time the fori) loop runs, I == 0, and we set the x
ition for line() to xPos[0] i.e. 1. The second time the for() loop runs, 1
. The third time the loop runs, |
(Note that | wrote ==, not =. In Processing, the equal sign (=) is used to assign a value to a
variable, so two equal signs together (==) is used to mean “is equal to.” x = 1 means “set
variable x to 1." x == 1 means "x is equal to 1” (which is either true or false, depending on
the value of x),
Here, printin() is used to write something to the screen, in this case, the current values of i
and xPos|i]. This can be very useful for checking your values while debugging or
troubleshooting your code. Note that printin() does not print to the Processing display
‘window; for that you need text(), which we will look at later. printin() does not affect how
anything is drawn; you may comment it out without changing how the sketch appears when it
renders.
Week 3 will not introduce so many new ideas or have as many examples, so you should have some
time then to continue learning this stuff, if you need it. If you have time after running through the
above examples, write some of your own sketches that re/combine the things you have leamed this
week. Feel free to share your creations on the forum. If you have any questions, please post them in
‘your journal on the forum.
4Build Your Own 3D Sigil Generator Iyperritual
Week 3
This week we will look at ways of using the keyboard and mouse to interact with our
drawings. | created more examples and introduced more new ideas than | had intended to,
but this is a good thing. There should be time over the next three weeks to catch up with the
high volume of new ideas introduced in weeks 2 and 3.
mousePressed is a system variable and a Boolean variable, meaning it is either true or
false; itis true when a mouse button is pressed, and false when a mouse button is not
pressed. The mouseX and mouseY system variables are always set to the x and y
coordinates, respectively, of the mouse cursor within the Processing draw window. Here is a
an example that uses both; every time a mouse button is pressed (while the cursor is in the
draw window), the white ball (ellipse) moves to the cursor's position.
int Pos - 107 // variable x position for ball
int yPos -|150; // variable y position for bali
void setup() {
size (300, 300); // set canvas’ size
nostroke () #\//-disable outlining
f111(255)7 // set f111 color to white
ellipseMode (CENTER); // draw ellipses from the center
smooth ();// draw smooth lines
}
void draw() {
background(0); // draw a black background
if (mousePressed) { // if a mouse button is pressed
xP0s - mouseX; // sét, xPos to the mouse X position
yPos = mouseY; // set yPos to the mouse ¥ position
}
ellipse (xfos, yPos, 30, 30); // draw an ellipse (xP0s, yPos), 30px
wide and high
}
Notice what happens when you move your mouse around while keeping the button pressed,
Also notice that it does not matter which mouse button is pressed; the program should
behave the same whether the left of right (or center) button is pressed,
5Build Your Own 3D Sigil Generator Iyperritual
‘There is also a mousePressed() function (note the parentheses) which you will see in the
following example, and to go with it, mouseReleased() and mouseDragged().
Hfyou need to detect which mouse button has been pressed, use mouseButton, which can
have a value of LEFT, RIGHT, or CENTER.
int ballcolor = 255; // variable ball color
void setup() {
size (300, 300);
background (0);
noStroke ()
£111 (255);
e1LipseMode (CENTER) +
smooth ();
I
void draw() {
// nothing in draw(); we are) going to;draw only in response to
// the mousePressed() and mouseReleased() functions
}
// do this, when a mouse button is pressed
void mousePressed() {
if (mouseButton == LEFT) {
ballColor\= color (255, 0, 0); // set ballcolor to.red
} else if (mouseButton’== CENTER) {
baliGolor = color(0, 255, 0); // set ballcolor to green
} else if (mouseButton == RIGHT) {
ballcolor = color(0, 0, 255); // set ballcolor to blue
1
f£ill(balicolor); // set fill coler.to ballcolor
ellipse (width/2, height/2, 100, 100); // draw the ball
}
// do, this when the mouse button is released
void mouseReleased() {
background(0); // clear-the screen
}
16Build Your Own 3D Sigil Generator Iyperritual
Here is a sketch that flashes faster the further the mouse cursor
moves to the right side of the draw window.
int x = 0; // counter
void setup() (
size (300, 300);
frameRate(1); // start w/ 1 frame per second
)
void draw() {
if (x82 > 0) ( // if x is evenly divisble by 2
background (0); // draw black background
} else { // otherwise
background (255); // déaw white background
)
xtt; // inctement x by 1
// change, framerate to correlate w/ mouse x position
frameRate (map (mousex, 0,300, 1, 20));
t
The % in x%2 indicates a modulo (or modulus) operation, and it returns the remainder of a
division operation. it wll not be used in the sigil generator, so you need not worry about
understanding it, although it is a useful operation. Review the reference page for it if you
‘want to learn more. In the above sketch, itis just a Way of acting on every other number in
the counter (x), since every other number is evenly divisible by 2 (1, 2,3, 4, 5, 6, etc.) thus
returning a mod of 0.
‘The map() function is one of the most useful in Processing, in my opinion. Use it to map a
value from one range to another. In the above case, the range of possible mouseX values is
0 to 300, since the draw window is 300 pixels wide. But | do not want to set the frame rate as
high as 300; in fact, | (arbitrarily) do not want to set it greater than 20 or less than 1. So | use
map() to map the mouseX value from a range of 0 to 300, to a range of 1 to 20. As you work
more with Processing, you will likely discover many uses for map(), and realize how valuable
it
Notice again the embedded functions: the output of map(mouseX, 0, 300, 1, 20) becomes
the input of frameRate().
7Build Your Own 3D Sigil Generator Iyperritual
You can make Processing respond to keyboard input as well, using the keyPressed() and
keyReleased() functions, and key and keyCode system variables.
‘The key variable is used for all ASCII character keys (including BACKSPACE. TAB, ENTER,
RETURN, ESC, and DELETE). keyCode is used for non-ASCII keys such as the arrow
keys. Here is a sketch that moves the square as the up, down, left, and right arrow keys are
pressed.
int xPos = 150;
int yPos = 150;
void setup() {
size(300, 300);
£ill (color (255, 0, 0)17
stroke (color (0, 255, 0))j
strokeWeight (3) 7
rectMode (CENTER) +
}
void draw() {
backgrotind (0) ;
rect (xPos, yPos, 50, 50);
}
void keyPressed() {
// A left arrow key i3 pressed AND xPos is greater than 0
if( (keycode == LEFT && xPos > 0) {
xPos-=10; //“same as xPos = xPos ~ 10
} élsé if (keyCode == RIGHT && xPos < 300) {
xPost=10; // same as.xPos = xPos + 10
} else if (keycode == UP && yPos > 0) {
yPos-=107
} else if (keycode
yPost=10;
}
}
DOWN && yPos < 300) {
Notice in each iff) or else if() statement, we check both the keyCode and the xPos or yPos
values to make certain the latter are not beyond the size of the draw window. The double
ampersands (&&) mean AND. Without the latter check, the square would keep moving
beyond the window until we could no longer see it.
‘Two pipes (||) are used for a logical OR, and an exclamation point (!) is used for a logical
NOT. AND, OR, and NOT can only be used with Boolean expressions i.e. expressions that
retum either true or false. Examples:
sif (a G& b) // means "if a is true and b is also true"
if (a || b) // means “if a or b is true”
vif (!a) // means "if not a” i.e. returns true if a is false,
false if a is true
8Build Your Own 3D Sigil Generator Iyperritual
Here is a sketch that draws the lines of a pentagram as keys 1
through 5 are pressed. Press the C key to clear the screen.
void setup() {
size(300, 300); // set canvas size
background(0); // set background color to black
£111(0); // set fill color to black
stroke (color(255, 0, 0)); // set stroke color to red
smooth (); // draw smooth lines
)
void draw() {
// all drawing for this,sketch is handled in keyPressed()
}
void keyPressed() {
if (key == 10)
line (150, 30,227, 270); // top to lower right
} else if (key == 12") (
Line (227, 270,23, 121)7 // lower right) to upper left
} else if (key == '3') ( Y
Line (23, 121,276, 121); // upper left! to upper right
} elbe if\ (key == '4") [
Line (276,121, 72) 210); // upper right to lower left
} else if (key == *5")>{
line (72,270, 150, 30); // lower left to top
} else if (key == te" || key == 'C")
background(0); // clear all lines
}
}
Notice the logical OR (\j) for the C key. Since lower-case ¢ and upper-case C are technically different
characters. we need to tell Processing to clear the screen when one or the other is pressed (if that is
what we want it to do).
19Build Your Own 3D Sigil Generator Iyperritual
In the last part of the lesson for this week, I am going to show you how to render text in
Processing, and introduce you to string variables. This will also and incidentally introduce
‘you to declaring objects and calling their methods.
‘The first thing you need to render text in Processing is a font. To create a font for Processing, 20 to
Tools — Create Font...
‘sketch _jun17c | Processing 1.5.1 =
File ait Sketch (TORR) Hep
Crete Font.
Color Sector
Sketeh_junt7¢ Archive Sketch
Fix Encoding & Reload
Select a font from your computer: I will use DejaVuSans. Pay atfention to the filename (in this case,
DejaVuSans_48.viw); you will need that later. You'can let the size-and characters default, and keep it
smooth. }
‘Use this tool to create bitmap fonts for your program.
Select a font and size, and click’OK to generate the font,
Itwill be added to the data folder of the current sketch,
Sze: [48 | [J] Snooth
Filename: DejaluSans-$3
(anes)Build Your Own 3D Sigil Generator Iyperritual
Now run and study the following sketch, replacing the font file name with your own.
PFont myFont; // declares a font object
String myString; // declares a string object
void setup() {
size(300, 300); // set window size
£111(255); // set fill color to white
// load the font file into object myFont
my£ont = loadFont ("DejavaSans-48.v1w");
iI set myFont as the font for rendering text
textFont(myFont, 24);
iI you can change the font size here by doing something such as
iItextFont(myFont, 24),
i/o render myFont in 24-point size
+
void draw() {
background(0);
J! put some characters into myString
myString = "ABCD";
JI display myString in the draw window
text(myString, 10, 50);
iI the 10 and 50 arex and y positions to begin drawing text from
1! could also do this
text("efgh", 10, 100);
}
21Build Your Own 3D Sigil Generator Iyperritual
in the draw window. There are some String methods called in this script. Do not worry too
much if you have trouble understanding these, although we will use them in the sigil
generator (to create the input word for the sigi). If you want to explore String in more detail,
you can review its reference page.
PFont myFont; // declares a font object
String myString = ""; // declares a string object
// initializing it w/ "" prevents NullPointerException errors later
void setup() {
size (300, 300); // set window size
£111 (255); // set fill color, to white
myFont = loadFont ("DejavuSans-48.vlw"); // replace file name w/ your
own
‘textFont (myFont,/24)7
}
void draw(}. {
background (0) ¢
text (myString, 10, 50);
}
void keyPressed()\ {
// “aze-the backspace key to delete the’ last character from myString
//4£ there is_one
if: (key == BACKSPACE && myString.length() > 0) {
// this just sets myString to myString minus the last character
myString = myString.substring(0, myString.length() - 1);
}
// at keys a-z, B-Z, or a space
else if((key >= ‘a! £8’ key <= 'z') I| (key >=
(key ==)
// add the pressed key to myString
7/ but prevent more than/8 characters’ from being typed
R& key <="'2") JI
// and rememeber Processing begins counting at 0
if (mystring. length () /< 8) {
myString += key?
'
}
‘Next week, I will show you how to draw and animate 3D images.
22Build Your Own 3D Sigil Generator Iyperritual
Week 5
Build Your Own 3D Sigil Generator
This week we will lear how to import a library and use it with our 3D drawing program. A
library is some code written by someone, that extends what we can do with Processing. E.g.,
‘the minim library allows us to write sketches for processing audio. After importing the minim
library into our sketch, we can create objects and call methods from that library, which saves
Us from having to write all of that code from scratch. Here is a page of popular Processing
libraries.
The library we will use this week is called controlP5, and it includes a variety of graphical
user interface (GU!) classes and methods we can include in our sketches. We will create
sliders to control the red, green, and blue hues of the sigi's color, and the sigi's rotation
speed, and a box to toggle the sigi's animation onioff.
To install the controlPS library, first download it from the controlPS site. You should have a
Processing folder in your My Documents folder (Windows) or ~/Documents folder (Mac).
Inside that Processing folder should be a folder named libraries; if not, create one. Within
the libraries folder, create a new folder named controlP5, and unzip the four folders
(examples, library, reference, src) you downloaded, into that folder. The final directory.
structure should look like this (Windows example):
My Documents
Processing
libraries
controlPS
examples
library
reference
src
if you encounter problems, see if the instructions on this page help. When you have installed
the library, exit out of the Processing application (if you have it open), and restart
Processing. You can look through the sketches in the examples folder, to see some of the
many ways to use controlP5.
This week there will be only one sketch — it’s a big one. I will include it here in this document as well
as post it on the Arcanorium forum with the proper spacing preserved, so you can copy-and-paste it
into Processing. After the sketch in this document, I will explain some of the additions.
23Build Your Own 3D Sigil Generator Iyperritual
// import the controlP5 library
import controlP5.*;
// declare a PGraphics object named sigil
PGraphics sigil;
ControlP5 controlP5; // declare controlP5 object
controlP5.Label label; // declare label object
// declare slider objects
Slider rSlider, gSlider, bSlider, speedSlider;
// declare variables associated with controlP5 objects
int r = 255; // red color
int g = 285; ///green color
int b = 255; // blue color
float speed |= 0.01; // rotation speed
boolean animate = false; // animation state variable
// declare variables for constructing \sigil
String word = ""; iY
float{] xPos {-1,0,1,-1,0,1,-1,0,1, 1,01, -1,.0,1, -470,1,-1,0,1,-
1,0,1,-1;0, 17
float{] yBos = {-1,
1,0,0,0/4,1,1
float []zPos 4=1,-1,-1,
1,0,0,0,0,0,0,0,0,0,1,1,1,
char[] alphabet
CRUE CLD eh Et, Tere, *Tt ee, LE,
+ MMI Dp BE ONZE, 8" LSmh TONE, IE IK, EEE Dy
float{][] sigilPos = new float[16] [3];
int. multiplier 100,
float xRot:
float yRot,
float zRot:
-1,0,0,0,1,1,1,
-1,0/0,0/1,4,1,
1,-1,-1,-1,-
i
Mey, Pode 1 be
void setup() 'f
size (800, 400);
stroke (255);
// create the controlP5 object
controlP5 = new ControlPs (this);
// create the slider and toggle objects
rSlider = controlPS.addSlider("r", 0,255, r, 430, 50,256, 10);
label = rSlider.captionLabel ();
label.set( "red" );
gSlider = controlPS.addSlider("g", 0,255, g, 430, 70,256, 10);
label = gSlider.captionLabel ();
24Build Your Own 3D Sigil Generator Iyperritual
label.set( "green" );
bSlider = controlP5.addSlider("b", 0,255,b, 430, 90,256, 10);
label = bSlider.captiontabel ();
label.set( "blue" );
speedSlider =
contro1P5 .addSlider ("speed", 0.01, 0.1, speed, 430,110, 100,10) ;
contro1P5 .addToggle ("animate", false, 430,130, 20,20);
// create the sigil object
sigil = createGraphics (400, 400,~P3D);
}
void draw() {
background (0); // €lear the) screen
// set sigil vertices from the word to sigilize
if(word.length() > 1) {
for(intii = 0;\i < word-length()? i++
for(int 3=0; J
0) {
word = word.substring(0, word.length() - 1)7
} else if((key >= 'a' @& key <= 'z') II (key >= 'A' && key <= 'Z')
I (key == ))
if(word.length() < 16) {
String newletter = "";
newletter += key;
word += newLetter.toUppercase() +
}
}
println("sigil text?" + word);
?
explain the conirolP5 stuff, then the PGraphics stuff.
controlP5.
To import the controlPS library into Processing, we include import contro1ps.*; atthe
top of the sketch. Then where we declare objects and variables, we declare a ControlP5
‘object that does the main controlPS processing, and any additional controlP5 objects (see
the code). The reason we declare Contro1P5.1abel is so we can change the labels on
the sliders (see blow; they default to the names of variables we associate with them).
Within setup () , we create the controlP5 object that we declared, and slider and toggle
‘objects. | will break down the red slider (sSlider) so you can see how it works:
rSlider =controlP5.addslider("r",0,255,r, 430, 50,256, 10) 7
label = rSlider.captionLabel ();
label.sét( "red" 7
rSlider = controlps.addSlider() creates anew slider object named rSlider. Here
is a breakdown of the parameters:
+"r’— the name of the variable that will be changed by moving the slider (we declared
the variable as an integer, near the top of the sketch)
-0 — the beginning of the range of values for this slider (the red hue of a color can be
any integer from 0 to 255, so this number is 0)
+255 — the end of the range of values for this slider
“Tr ~ this parameter is for the default value of the slider. We could have written a
number here (e.g., 255), but since we declared the variable r with a default value of
255 earlier in the sketch, | am just calling r here. This way, if | want to change the
default values, | can change them where | declare the variables, and not have to
search through the code for where | create the sliders.
-430 - the x position to begin drawing the slider
+50 — the y position to begin drawing the sliderBuild Your Own 3D Sigil Generator Iyperritual
+256 — the width (in pixels) of the slider. Since there are 256 values between 0 and
255, | am drawing the slider 256 values wide.
+10 — the height (in pixels) of the slider.
By default, the slider's label would be R (because of the ‘r’ at parameter), but that is not very
descriptive, so | want to change that to RED. To do so, | create a new label and set it to
“red”:
label = rSlider.captionLabel ();
label.set( "red" );
You can change other properties of the sliders, such as their background and foreground
colors, fonts and fonts colors, etc. See the controlP5 reference documentation for more info.
Adjusting the red, green, and blue sliders, changes the r, g, and b variable values, and so
changes the color of the sigil as determined by this line in the sketch:
sigil.stroke(color(r, g, b)):
The toggle box is created similarly but has fewer parameters because it does not have a
Tange of values. The toggle box has two states that map to the animate variable; itis
either on (animation = true), of off (animation = false). Then when we draw the sigil,
we check to see the status of animate, and if itis true, we increase the xRot, yRot. and
zRot values according to the position of the speed slider (speedS1ider, associated with
the variable, speed), thereby animating the sigil.
PGraphics
Last week, we saw how to draw in 3D using the P3D mode. Now, controlP5 comes with its
‘own font for drawing lables and such. Fonts work differently in P3D and OPENGL modes
than that do in Processing's 2D modes, and if we try to draw controlPS objects onto a 3D
canvas, the label fonts become distorted. To work around that, we are going to draw the sigil
into a graphics buffer using PGraphics. and then display the sigil as an image on a 2D
canvas.
You do not need to install a new library to use PGraphics; it is part of the standard
Processing code base.
First, we declare a PGraphics object named sigill, near the beginning of our sketch:
PGraphics sigil;
Then in setup (), we create the sigil, object. Note that the mode of this object is P3D,
but our sketch itself is not P3D (as it was last week); this will allow us to draw a 3D image
‘onto a 2D canvas.
All of the statements for drawing the sigil are enclosed between sigil.beginDraw() and
sigil.endDraw(). and begin with sigi1. , which tells Processing to draw into the
Graphics buffer instead of directly onto the canvas. Finally, the contents of the graphics
buffer are drawn to the canvas as an image (at position 0, 0):
image(sigil, 0, 0)5
‘As always, if you have questions or concems, please post on the forum, Next week I will show you
how to create images and videos of the sigils we have created.
27Build Your Own 3D Sigil Generator Iyperritual
Week 6
For this final week in the course, we will lear how to save images and video files of our 3D
sigils.
save()
The following sketch will draw a 3D sigil. Press the 1, 2, 3, 4, 5, or 6 key to rotate the sigil
‘one way or the other on its three axes. Press the 7 key to save a PNG file of the sigil. The
file will be written with the name sigil.png, to your sketch's folder (look under the Sketch
menu, Show Sketch Folder). You can change the file name or type within save(); allowable
file types are TIFF (tif), TARGA (tga), JPEG (Jpg), and PNG (png)
float [] xPos'= {-1,0/1,-1,0)2)<1,0,1,-140/1,-1,0,2,-1,0,1,-1,0,1,-
1,0,1,-1, 0)1)2
float[] yPos
1,0,0,0/1,1,1)
float] /zPos = {-1,-1,-1,<1}-tyt1 “1-440
1,010) 0,0,010¢0e0/0/1,1/Tydy ed, 1,1, Ie
char[] alphabet
UAGOBN NCD
Nt, BttQr,
float(i{] sigilPos
int multiplier = 1007
string word = "HYPERITUAL"; // change this to your own word
Float xRot
float yRot
float 2Rot = 0
void setup() {
size(400, 400, ‘P3D):
noFill (V7
stroke (255) +
smooth () 7
}
void draw() {
background (0}
for(int i = 07/i/< wordslength(); i++); {
for(int } = 0; j < alphabet-length; i+#) {
{-1,-1yp 1 94 0,0,1,1,1,-1y 1, 71,0, 0,0, 1,141,-1,-1,-
cont, IP,
BS" 9 Th EGON
new float [16] [3];
28Build Your Own 3D Sigil Generator Iyperritual
if(word.charAt (i) == (alphabet [j])) {
sigilPos[i][0] = xPos[j] * multiplier;
sigilPos[i][1] = yPos[j] * multiplier;
sigilPos[i][2] = 2Pos[j] * multiplier;
}
}
i
translate(width/2, height/2, 0);
rotateXx (xRot) 7
rotateY (yRot) ;
rotatez (zRot) 7
for(int i = 0; i < word.length()>= 17 itt) {
line(sigilPos[i][0], sigilPos[il[1], sigilPos{i] [2], sigilPos[it1]
[01, sigilPos[iti][1, sigitPosfit1112])7
}
}
void keyPressed() {
Af (key == 4) {
xRot —= 0.01;
} else if (key == '2')
xRot += 0.017
} else if (key—= 13") {
yRot|-= 0.01;
} else if (key = 14") 1
yRot += .0.01;
} else if (key
zRot == 0.01
} else if (key
zRot #= 0.01;
} else if(key.—— '7') {
saye("sigil.png")?
:
saveFrame()
Seay |
6) 4
Using saveFrame() will write a new image each time the 7 key is pressed, instead of
overwriting a single image. Not very useful with the above sketch, but here is one that will
‘that will save 30 frames of animation when the 7 key is pressed.
float [] xPos =-{71,0,1,-1,0,17-1,0,1,-1,071)-1,0,1)"1,0,1,"1,0,1,—
1,0,1,-1,0/1.
float [] yPos = {-1,~
1,0,0,0,1,1,1}+
float [] zPos = {-1,-1,-1,-1,-1,-1,-1)-1,-
1, 0,0, 0,0, 0, 0,0, 0,0, ly t¢tetyt, 1,4, 1, 1)5
char[] alphabet
cat tor,
po, 0/0/0,1,1,1,-1,22,-2)0,0,0;1,1,1,-1,-1,-
float[]{] sigilpos = new float [16] [317
int multiplier - 1003
String word - "HYPERITUAL"; // change this to your own word
float “Rot - 0;
float yRot = 0;
float zRot = 0;
29Build Your Own 3D Sigil Generator Iyperritual
boolean makeAnimationFiles = false;
int counter = 0;
void setup() {
size (400, 400, P3D);
noFill ();
stroke (255) 7
smooth ()
}
void draw() {
background (0);
for(int i = 0; i < word.length(); i++) {
for(int j = 0; j < alphabet.length; j++), {
if(word.charAt (i) == (alphabet (j])) 1
sigilPos[i][0] = xPos{j] * multiplier;
sigilPos[i] [1], yPos{j] * multiplier;
sigilPos [i] [2]/ = 2Pos[j]) * multiplier;
t
}
}
translate (width/2, height/2,\ 0);
xRot += 0.017 Y
yRot += 0.01;
zRot| $= 0.01;
rotatex(xRot) 7
rotateY (yRot) 7
rotatez(zRot);
for(int i= 07 i < word.length() - 1; i++) {
line (sigilPos[i][0], sigilPos[i][1], sigilPos[i] (21,
sigilPos[itl1[0], sigilPos{it1][1], sigilPos[it11[21);
}
if (makeanimationFiles == true) {
counter++;
saveFrame("sigil"+counter+" png");
if (counter == 30) {
makeAnimationFiles = falsey
}
}
void keyPressed(){
if (key == '7') (
counter = 0;
makeAnimationFiles = true;
}
IBuild Your Own 3D Sigil Generator Iyperritual
MakeMovie
‘The MakeMovie class is part of Processing’s standard video library, and can create a movie
{.mov) file of the sigil. Using the following sketch as an example, press the 7 key to begin
recording the movie, and the 8 key to stop recording.
import processing.video.*;
MovieMaker mm; // declare MovieMaker object
float[] “Pos = {-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0/1,-1,0,1,-1,0,1,~
1,0,1,-1,0,1}7
float [] yPos = {-1,
1,0,0,0,1,1, 11
float [] zPos = {-1,-2y-L,-1)-1,-1,-1,-1,>
1, 0,0, 0,0, 0,0, 0,0/0/1,1,441, ¥,1)1) V4) 5
char[] alphabet
{1At, BY, Cyt ENE PGN NHS, "I"
+ 1H", 10", PEESOR fir CATER EEMAy OV" SWNT Ee
float {][] sigilPos = new, float [161(31;
int multiplier = 100;
string word =\"HYPERTTUAL";:// change this to your own/word
float, ¥Rot)
float yRot
float 2Rot =
boolean makeMovieFile\= false;
void setup() {
sige (400, 400,-P3D);
// create MovieMaker object with size, filename,
// framerate, compression codec, and quality
-1,0,0,0,1,1,1,
+-1,0,0,0,1,1,1
mm\= new MovieMaker (this, width, height, "drawing.mov",
30, MovieMaker.H263, MovieMaker.HIGH) ;
noFill();
stroke (255);
smooth ();
}
void draw() {
background (0);
for(int i= 07/4 < word.length(); i++) {
for(int 3 = 0; j