1 Rome- Monumental Art. 2 Arch of Constantine, dedicated 315 AD.
Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.
-
Upload
nicholas-henderson -
Category
Documents
-
view
224 -
download
0
Transcript of Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.
![Page 1: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/1.jpg)
Programming for Art:Programming for Art:ArraysArrays
ART 315ART 315
Dr. J. R. ParkerDr. J. R. Parker
Art/Digital Media LabArt/Digital Media Lab
Lec 01 Fall 2010Lec 01 Fall 2010
![Page 2: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/2.jpg)
Variables
A variable is a name for a value, a value that can change as we need it to.
It can hold one value.
So: the speed of a ball on the screen could be:
int speed = 0;
![Page 3: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/3.jpg)
Variables
HOWEVER:
What if there are many balls, and each has a speed?
int speed1=0, speed2=0;
What if we wish to be flexible, and allow various numbers of balls?
The we need an array.
![Page 4: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/4.jpg)
Array Variables
An array is a collection of variables that have a common name and type, and that can be accessed through a number called an index.
When the array is declared, a size is usually specified. This means that the array’s size is always known.
Legal indices start at 0 and run to N-1, where N is the number of elements in the array.
![Page 5: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/5.jpg)
ArrayAn array is a set of adjacent memory
locations each of which contains the same type of value.
An array of integers representing speeds could look like this:
212 0 32 41
0 1 2 3 4 5 N-1 Indices
Values
4...
![Page 6: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/6.jpg)
ArrayThis array could be declared as:
int [] speed = new int[12];
And accessed as a variable using an index:
k = speed[3];
so speed[3] has the value 0.
212 0 32 41
0 1 2 3 4 5 N-1 Indices
Values
4...
![Page 7: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/7.jpg)
Array
int [] speed = new int[12];
Type it’s an name create size is array space 12
ints
212 0 32 41
0 1 2 3 4 5 N-1 Indices
Values
4...
![Page 8: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/8.jpg)
Array of grey levels
int [] grey = new int[24]; int greyIndex = 0;
This is an array of 24 grey values to be used, say, to fill rectangles and ellipses.
Each time DRAW is called, use the next colour in this collection.
![Page 9: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/9.jpg)
The Program
int greyIndex = 0;
int [] grey = new int[24];
void setup()
{
size(400, 400);
background(128,128, 0);
grey[0] = 1; grey[1]=12;
grey[2]=24; grey[3]=48;
grey[4]=128;
grey[5]=200; grey[6]=64; grey[7]=255]; grey[8]=96;
grey[9]=176; grey[10]=199; grey[11]=143; grey[12]=121; grey[13]=13;
}
void draw(){ fill(grey[greyIndex]); rect(random(width), random(height), 20,20); greyIndex = greyIndex + 1; if(greyIndex > 13) greyIndex = 0;}
![Page 10: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/10.jpg)
What it Does
video
![Page 11: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/11.jpg)
What do we use arrays for?
For remembering past positions.For colour maps/tablesVelocities/positions of multiple
objects
![Page 12: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/12.jpg)
Multiple ObjectsLet’s have an example in which we
have many objects (EG Balls) that can move about.
The X position of each is found in X[i]
The Y position is found in Y[i]Velocity (motion in each time unit) is
in Dx[i] and Dy[i] for the X and Y directions.
![Page 13: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/13.jpg)
Arrays for position
/* Position of up to 20 objects */int [] X = new int[20];int [] Y = new int[20];.
![Page 14: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/14.jpg)
Arrays for speedint Nobjects = 5; /* How many are there
now*//* Position of up to 20 objects */int [] X = new int[20];int [] Y = new int[20];.
/* Speed of up to 20 objects */int [] Dx = new int[20];int [] Dy = new int[20];
![Page 15: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/15.jpg)
Drawing objects
We know where each ball is, and can draw it in its proper place using the array and a loop.
for (i=0; i<Nobjects; i++) { blackCircle (X[i], Y[i]); /* Draw object */ /* Use the blackCircle function already written */
![Page 16: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/16.jpg)
Updating SpeedAfter each iteration, use Dx and Dy to
change the position of the balls.
for (i=0; i<Nobjects; i++) { blackCircle (X[i], Y[i]); /* Draw object */ X[i] = X[i] + Dx[i]; /* Update
position */ Y[i] = Y[i] + Dy[i];
![Page 17: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/17.jpg)
Random DirectionsAt random, change the speed in each direction if (random(10) < .1) /* Change speed at random */
{
if (random(10)<5)
{
Dx[i] = Dx[i]+1; Dy[i] = Dy[i] - 1;
} else {
Dx[i] = Dx[i] - 1; Dy[i] = Dy[i] + 1;
}
}
![Page 18: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/18.jpg)
Here it is:
![Page 19: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/19.jpg)
The Objects wander off …
So when a ball goes off the edge, maybe move it to a random place.
if ((X[i] < 0) || (X[i] > width)) X[i] = (int)random(width); if ((Y[i] < 0) || (Y[i] > height)) Y[i] = (int)random(height);
![Page 20: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/20.jpg)
![Page 21: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/21.jpg)
How about Bouncing?As we did in Gamemaker with
the ‘change direction’ button for Pong. Not as simple, but nearly…
if ((X[i] < 0) || (X[i] > width)) Dx[i] = -(Dx[i]); if ((Y[i] < 0) || (Y[i] > height)) Dy[i] = -(Dy[i]);
![Page 22: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/22.jpg)
The Bounce
This was remarkablyeasy to do.
![Page 23: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/23.jpg)
Main loopThis last version is much like a video
game ‘main loop’, in which all objects are drawn, then the object’s positions are updated based on their current speeds.
All objects are kept track of in the game ‘AI’ and events that happen to them are implemented.
What about collisions??
![Page 24: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/24.jpg)
Collisions
There are N objects, in this case all are circular.
The size of each object is ‘circlesize’.
If any two objects are within a distance ‘circlesize’ of each other then they have collided.
![Page 25: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/25.jpg)
Collisions
If two balls collide then we will change their color.
This means keeping track of object colors, too.
An array again:
int [] cols = new int [20]; /* Initially black */
![Page 26: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/26.jpg)
‘collide’ function
We shall make a function that takes ints I and j, and determines whether objects i and j have collided.
Then we will do this: for (i=0; i<N; i++) for (j=i; j<N; j++) if (collided(i,j)) { cols[i] += 10; cols[j] += 1; }
![Page 27: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/27.jpg)
Collisions
The collided function simply determines whether the two objects are nearer than circleSize to each other.
Return 1 if so, 0 otherwise.
![Page 28: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/28.jpg)
collisionint collided (int i, int j){ float d1, d = 0.0; d = (X[i]-X[j])*(X[i]-X[j]); d1 = (Y[i]-Y[j])*(Y[i]-Y[j]); d = sqrt (d + d1); if (d <= circleSize) return 1; return 0;}
![Page 29: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/29.jpg)
Change colour for (i=0; i<Nobjects; i++)
{
blackCircle ( X[i], Y[i], cols[i] );
void blackCircle ( int x1, int y1, int level )
{
stroke(0); fill (level);
ellipseMode(CENTER);
ellipse (x1,y1,circleSize, circleSize);
}
![Page 30: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/30.jpg)
The Result
![Page 31: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/31.jpg)
PolaroidThe Model 95 was Polaroid's first camera, and it was introduced in 1948.
![Page 32: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/32.jpg)
1950s• Theremin, invented in 1928,
released as a kit from Moog.
• Minicomputers - CDC-160A
![Page 33: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/33.jpg)
Mixing Media
• TV Theme 'My Favorite Martian' uses a theremin.
![Page 34: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/34.jpg)
1960s• 1960 - PDP-1 minicomputer (and SpaceWar computer
game)• October 17, 1969, George Smith and Willard Boyle
invented the charge-coupled device (CCD)
1963: Douglas Englebart – first mouse1963 Ivan Sutherland – Sketchpad, interactive CG system- pop-up menus
![Page 35: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/35.jpg)
1960s
• 1967 – First computer animation
• •
![Page 36: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/36.jpg)
1960s• 1968 - PDP-8
minicomputer
The first ARPANET link was established between the University of California, Los Angeles and the Stanford Research Institute on 22:30 hours on October 29, 1969.
![Page 37: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/37.jpg)
1970s• Commercial video games• First home computers• Atari releases home Space Invaders• VCR – although the first home vcr was the
Sony model CV-2000, it was $1000, monochrome, and used reels.
• 1970 Philips developed a home videocassette format.
• Betamax November 1975• VHS format, introduced in Japan in September
1976
![Page 38: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/38.jpg)
1970s
• Apple I 1976 (a kit)• The Apple II was
introduced on April 16, 1977 (VisiCalc spreadsheet)
1971 – Andromeda Strain. Short 3D graphics segment.1973: John Whitney. Jr. and Gary Demos – “Westworld”, claims to be first film with computer graphics.
![Page 39: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/39.jpg)
1971 -Andromeda Strain
![Page 40: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/40.jpg)
1973 -Westworld
![Page 41: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/41.jpg)
Westworld
![Page 42: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/42.jpg)
1980s• SONY - 1981, the first prototype digital camera, the Mavica.
• 570*490• 50 still frames• floppy 3.5" disks• CCD sensor
![Page 43: Programming for Art: Arrays ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 01 Fall 2010.](https://reader034.fdocuments.us/reader034/viewer/2022051417/5697c01c1a28abf838ccff9f/html5/thumbnails/43.jpg)
1980s• In 1982, two events happened that eventually led to
the home camcorder boom: JVC introduced the VHS-C format, and Sony released the first professional camcorder named Betacam.
Cameramen did not welcome Betacam, because before it, carrying and operating the VCR unit was the work of a video engineer; after Betacam they came to be required to operate both video camera and VCR.