Braitenberg code. Page 1
|
|
- Bartholomew Conley
- 6 years ago
- Views:
Transcription
1 // Processing source code : Braitenberg's Vehicles // Based on program written by william ngan <contact@metaphorical.net> // SensoryField class stub coded by Prof. Mateas and Mayhew Seavey in //...and slightly-further hackery added by Jason Alderman in // Press UP and DOWN arrows to increase number of Braitenberg vehicles. // Press number keys 1-5 to change the number of sources on the sensory field. // Press SPACE to toggle the PImage ground visible or invisible. Vehicle[] robots; SensoryField lightsground; boolean mousedown; PImage ground; boolean bounded = true; // vehicles run into world boundary (if true), // wrap around (if false) int numoflights = 2; int numofrobots = 2; float move_speed = PI/6; boolean groundisdrawn; void setup() { size( 300, 300 ); framerate( 30 ); ellipsemode( CENTER ); rectmode( CENTER ); nostroke(); groundisdrawn = false; // Don't draw the sensoryfield grounds // on the background. ground = new PImage( width, height ); robots = new Vehicle[10]; // Create an array of Braitenberg // Vehicles. for (int i=0; i<robots.length; i++) { robots[i] = new Vehicle( random(width), random(height), 0, 10, i ); lightsground = new SensoryField( width, height, 5); // Create a SensoryField... // Now that SensoryField is a class, you can make as many different // types as you wish. for (int i=0; i<numoflights; i++) { lightsground.addsource( new Source( random(10,width-10), random(10,height-10), 1.0, 100, i)); println("adding source "+ i + " to lights at " + lightsground.getsource(i).getlocation()); println("the size of the lightsground arraylist is "+lightsground.sources.size()); smooth(); updateground(); void draw() { background( 0 ); if(groundisdrawn) image( ground, 0, 0 ); fill( 255 ); for (int i=0; i<numoflights; i++) { Page 1
2 lightsground.getsource(i).drawme(); for (int i=0; i<numofrobots; i++) { robots[i].moveme(); robots[i].drawme(); void keypressed() { if (key>='1' && key<='5') { numoflights = 5-('5'-key); updateground(); // updateground so that it adds or removes // the lights from the ArrayList! if (key==' '){ groundisdrawn= (!groundisdrawn); println("ground-drawn boolean is now: "+groundisdrawn); updateground(); // updateground so that it draws the PImage! // (or doesn't, when it shouldn't!) if (key==coded) { if (keycode==up) { numofrobots++; numofrobots = min( numofrobots, robots.length-1 ); else if (keycode==down) { numofrobots--; numofrobots = max( numofrobots, 1 ); void updateground() { float sum; int c; int px = 5; color cc; int temp; // if a keypress has changed the number of lights, then add or remove // sources from the arraylist of lightsground if(numoflights!=lightsground.sources.size()){ if(numoflights < lightsground.sources.size()){ // if the number of light sources has been decreased... temp = lightsground.sources.size() - numoflights; for(int i=0; i<temp; i++){ println("deleting source id "+(lightsground.sources.size()-1)); lightsground.deletesource(lightsground.sources.size()-1); else { // if the number of light sources has been increased... temp = numoflights - lightsground.sources.size(); for(int i=0; i<temp; i++){ println("adding source id "+lightsground.sources.size()); lightsground.addsource(new Source( random(10, width-10), random(10, height-10), 1.0, 100, lightsground.sources.size())); Page 2
3 lightsground.update(); if(groundisdrawn){ ground = new PImage( width, height); for (int i=0; i<width; i++ ) { for (int k=0; k<height; k++ ) { c = int(lightsground.get(i,k)); ground.set( i, k, color( c, min(200,c), c/8) ); // end for-loop (k) // end for-loop (i) // end if(groundisdrawn) // Vehicle class class Vehicle { float x, y, axle, half_axle, axlesq; float angle; // direction of the Vehicle float wheel_diff, wheel_average; // the difference and average of the wheels' rotating speed Wheel wa, wb; // two wheels Sensor sa, sb; // two sensors int id; Vehicle( float x, float y, float angle, float axle_length, int id ) { this.angle = angle; this.id = id; axle = axle_length; half_axle = axle/2; axlesq = axle*axle; ); ); wa = new Wheel( x+half_axle*cos(angle-half_pi), y+half_axle*sin(angle-half_pi), 10, 0 wb = new Wheel( x+half_axle*cos(angle+half_pi), y+half_axle*sin(angle+half_pi), 10, 0 sa = new Sensor( x+axle*cos(angle-half_pi/1.5), y+axle*sin(angle-half_pi/1.5) ); sb = new Sensor( x+axle*cos(angle+half_pi/1.5), y+axle*sin(angle+half_pi/1.5) ); void drawme() { fill(255,0,0); triangle( wa.x, wa.y, wb.x, wb.y, x+cos(angle)*axle*2.5, y+sin(angle)*axle*2.5 ); //fill(200,54,130); fill(102,102,51); wa.drawme(angle, 1); wb.drawme(angle-pi, -1); ellipse( x, y, axle*3, axle*3 ); Page 3
4 sa.drawme(); sb.drawme(); // Computes the sensory logic to set the wheel velocity. // Sensor output goes directly to wheel on same side void dosenselogic() { setaspeed(sa.getsense()); setbspeed(sb.getsense()); // Sensor output crossed to wheel on opposite side /* void dosenselogic() { setaspeed(sb.getsense()); setbspeed(sa.getsense()); */ // Each sensor goes to wheel on same side with an inhibitory connection /* void dosenselogic() { setaspeed(sa.getinversesense()); setbspeed(sb.getinversesense()); */ // Each sensor goes to wheel on opposite side with an inhibitory connection /* void dosenselogic() { setaspeed(sb.getinversesense()); setbspeed(sa.getinversesense()); */ // Sensors are hooked up to opposite motors, with threshhold sensing. /* void dosenselogic() { setaspeed(sb.getnonlinearsense()); setbspeed(sa.getnonlinearsense()); */ void moveme() { checkbounds(); dosenselogic(); // move wheel_diff = wa.d - wb.d; wheel_average = ( wa.d + wb.d ) / 2; angle += wheel_diff / axle; x += cos( angle ) * wheel_average; y += sin( angle ) * wheel_average; checkcollision(); // wheels move float ang = angle - HALF_PI; wa.x = x + half_axle * cos( ang ); wa.y = y + half_axle * sin( ang ); ang = angle + HALF_PI; wb.x = x + half_axle * cos( ang ); Page 4
5 wb.y = y + half_axle * sin( ang ); // sensors move ang = angle - HALF_PI/2; sa.x = x + axle * cos( ang ); sa.y = y + axle * sin( ang ); ang = angle + HALF_PI/2; sb.x = x + axle * cos( ang ); sb.y = y + axle * sin( ang ); void checkbounds() { if (bounded) { x = max( axle+5, min( width-axle-5, x ) ); y = max( axle+5, min( height-axle-5, y ) ); else { x = ( x<0 )? width+x : ((x>width)? x-width : x ); y = ( y<0 )? height+y : ((y>height)? y-height : y ); // If the above looks completely confusing to you, check out // void checkcollision() { float dx, dy, da; for (int i=0; i<numofrobots; i++) { if (i!=id) { // for all of the OTHER robots... // start calculating the distance between me and the other robot dx = x-robots[i].x; dy = y-robots[i].y; // if the distance sqrt(dx^2 + dy^2) is less than the axle size if (dx*dx + dy*dy<axlesq ) { da = atan2( dy, dx ); // calculate the angle from me to the other robot // then push me through t x = x + cos(da)*half_axle; y = y + sin(da)*half_axle; robots[i].x = robots[i].x + cos(da+pi)*half_axle; robots[i].y = robots[i].y + sin(da+pi)*half_axle; // void setaspeed( float ang_speed ) { wa.setspeed( ang_speed*move_speed ); void setbspeed( float ang_speed ) { wb.setspeed( ang_speed*move_speed ); void changeaspeed( float inc ) { wa.setspeedchange( inc ); void changebspeed( float inc ) { Page 5
6 wb.setspeedchange( inc ); class Wheel { float x, y; float ang_speed, radius; float angle; float d; Wheel( float x, float y, float radius, float ang_speed ) { this.radius = radius; this.ang_speed = ang_speed; angle = 0; d = ang_speed * radius; void setspeed( float ang_speed ) { this.ang_speed = ang_speed; d = ang_speed * radius; void setspeedchange( float inc ) { ang_speed += inc; d = ang_speed * radius; void drawme(float ainc, int dir) { angle += ang_speed; if (angle>two_pi) angle -= TWO_PI; float temp = sin(angle)*half_pi+ainc; ellipse( x+cos(temp)*10*dir, y+sin(temp)*10*dir, 20, 20 ); class Sensor { float x, y; float maxreading; float sense; Sensor( float x, float y ) { maxreading = 1; void setlocation( float x, float y ) { /* float getsense(boolean plus) { Page 6
7 float sum = red( ground.get( (int)x, (int)y ) )/255.0; sum = (plus)? sum : 1-sum; sense = (specialsense)? nonlinear( sum, maxreading ) : 1-sum; return sense; */ // This is an example of non-linear threshhold sensing. Returns 0 // until the normalized sensory value = 0.5, then returns a linear value // between 0.5 and 1. float getnonlinearsense() { // old code, reading from PImage ground, was: // float val = red( ground.get( (int)x, (int)y ) )/255.0; float val = lightsground.get( (int)x, (int)y )/255.0; if (val < 0.5) return 0; else return val; // Returns 0 when sensory value is maximum, 1 when it's minimum float getinversesense() { float val = lightsground.get( (int)x, (int)y )/255.0; sense = 1 - val; return sense; // Returns 1 when sensory value is maximum, 0 when it's minimum float getsense() { sense = lightsground.get( (int)x, (int)y )/255.0; return sense; void drawme() { fill(255); ellipse( x, y, 16, 16 ); fill(200*sense,0,0); ellipse( x, y, 7, 7 ); class Source { float x, y; float strength; // between 0 to 1 float max_radius; boolean dragging = true; int id; Source( float x, float y, float strength, float max_radius, int id ) { this.strength = strength; this.max_radius = max_radius; this.id = id; void setlocation( float x, float y ) { Page 7
8 String getlocation(){ return ""+this.x+","+this.y; void drawme() { checkcollision(); // dragging? if (mousedown && mousex>x-10 && mousex<x+10 && mousey>y-10 && mousey<y+10) { dragging = true; if (!mousedown) dragging = false; if (dragging) { x = mousex; y = mousey; ellipse(x, y, 10, 10 ); if(groundisdrawn == false){ //-- draw a circle of max radius around the source -- stroke(255,255,255,45); strokeweight(2); nofill(); ellipse(x, y, max_radius*2, max_radius*2); nostroke(); fill(255); //-- void checkcollision() { // see vehicle's checkcollision for an explanation of the math here... float dx, dy, da; //-- keep the Source on the screen if(x > width) x = width; if(x < 0) x = 0; if(y > height) y = height; if(y < 0) y = 0; //-- for (int i=0; i<numoflights; i++) { if (i!=id) { dx = x-lightsground.getsource(i).x; dy = y-lightsground.getsource(i).y; if (dx*dx + dy*dy<max_radius ) { da = atan2( dy, dx ); lightsground.getsource(i).x = lightsground.getsource(i).x + cos(da+pi)*5; lightsground.getsource(i).y = lightsground.getsource(i).y + sin(da+pi)*5; float getreading( float tx, float ty, boolean plus ) { Page 8
9 // This method calculates the field strength by measuring the distance of an arbitrary point from this source. float d = dist( tx, ty, x, y ); if (d >= max_radius) return ((plus)? 0 : 1); // Strength of source falls of linearly in distance (up to max_radius) from source // d = strength*(d/max_radius); // Strength of source falls off as a function of the cosine of distance (up to max_radius) from source d = 1-nonlinear( d, max_radius ); return ((plus)? 1-d : d ); // end Source // The function nonlinear(r, rmax) is used by several bits of code above, so it falls inside the main program. // Returns a value between 0 and 1 (assume r & rmax >= 0) // Returns 0 if r is >= rmax // Returns 1 if r = 0 float nonlinear(float r, float rmax) { float f = (rmax - Math.min(r, rmax)) / rmax; return *cos(f*PI); // SensoryField is a class that contains our 2D array of sensory values (instead of using a PImage). class SensoryField { float[][] field; // A 2D array of summed sensory values. The 2D array should be the same size as the processing window. int w; // The width of the field int h; // The height of the field ArrayList sources; // The list of sources that produce values for this SensoryField int pixelsize; // Determines the block size at which we sample the field. Change the value (in the constructor argument) // to increase the sample size. The bigger the value, the more pixelated the field, but the less // computational work it takes to update the field. SensoryField(int w, int h, int ps) { field = new float[w+100][h+100]; //...making a sensory field with 50 elements-worth // of buffer on each side, so that when a vehicle or source goes to the edge of the // screen, there aren't negative index values for the 2D array (something that // PImages don't care about, but arrays do!). this.w = w; this.h = h; sources = new ArrayList(); pixelsize = ps; // Get the sensory value at a specific point. float get(int x, int y){ return field[x+50][y+50]; // Add a source to the field. void addsource(source s) { sources.add(s); // Delete a source from the field. void deletesource(int j) { Page 9
10 sources.remove(j); // Get a source from the sources arraylist. Source getsource(int i){ return (Source)sources.get(i); // Update the field. For every point in the field, iterate over the sources to determine // the sensory value at each point. void update() { float sum; // We're going to iterate through the all of the elements of the sensory field, // but increment by the pixelsize in the both directions... for(int i = 0; i < w; i += pixelsize){ for(int k = 0; k < h; k += pixelsize){ // Now sum up the sensory readings for each source in the field... sum = 0; for(int m=0; m<sources.size(); m++){ sum += this.getsource(m).getreading(i,k,true); //...and now write that sum (or a maximum of 255) in each element of the field within each big "pixel." for(int p=0; p<pixelsize; p++) { for(int q=0; q<pixelsize; q++){ field[i+p+50][k+q+50] = min(sum*255, 255); // void mousepressed() { mousedown = true; void mousereleased() { mousedown = false; updateground(); Page 10
Watch the following for more announcements
Review "plain text file" loadstrings() split() splittokens() selectinput() println(), float(), int(), can take an array argument, will return an array easy way to convert an array of Strings to an array
More information1 Getting started with Processing
cisc3665, fall 2011, lab I.1 / prof sklar. 1 Getting started with Processing Processing is a sketch programming tool designed for use by non-technical people (e.g., artists, designers, musicians). For
More informationCS110 Introduction to Computing Fall 2016 Practice Exam 1 -- Solutions
CS110 Introduction to Computing Fall 2016 Practice Exam 1 -- Solutions The exam will be closed-note and closed-book; please consider this fact before using your notes on this practice version. Please see
More informationA B C D CS105 03a Interaction
Interaction Function Definition Events Built-in Variables CS105 03a Interaction 1 Which image is drawn by this code? strokeweight(10); stroke(0, 255, 0); // green line(99, 0, 0, 99); stroke(200, 0, 200);
More informationOld 257 Exam #2s for Practice
Old Exam #2s 257/757 Exploring Programming with Graphics Page 1 Old 257 Exam #2s for Practice Exams will be taken on Thursday March 27 in the cluster. You will have the entire class time to do the exam.
More informationVariables. location where in memory is the information stored type what sort of information is stored in that memory
Variables Processing, like many programming languages, uses variables to store information Variables are stored in computer memory with certain attributes location where in memory is the information stored
More informationFunctions. Functions. nofill(); point(20, 30); float angle = map(i, 0, 10, -2, 2); parameters return values
Functions parameters return values 06 Functions 1 Functions Code that is packaged so it can be run by name Often has parameters to change how the function works (but not always) Often performs some computation
More informationCISC 1600, Lab 2.3: Processing animation, objects, and arrays
CISC 1600, Lab 2.3: Processing animation, objects, and arrays Prof Michael Mandel 1 Getting set up For this lab, we will again be using Sketchpad. sketchpad.cc in your browser and log in. Go to http://cisc1600.
More informationIteration in Programming
Iteration in Programming for loops Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Topics list There are three types of loop in programming: While
More informationSolution Notes. COMP 151: Terms Test
Family Name:.............................. Other Names:............................. ID Number:............................... Signature.................................. Solution Notes COMP 151: Terms
More informationPick a number. Conditionals. Boolean Logic Relational Expressions Logical Operators Numerical Representation Binary. CS Conditionals 1
Conditionals Boolean Logic Relational Expressions Logical Operators Numerical Representation Binary CS105 04 Conditionals 1 Pick a number CS105 04 Conditionals 2 Boolean Expressions An expression that
More informationif / if else statements
if / if else statements December 1 2 3 4 5 Go over if notes and samples 8 9 10 11 12 Conditionals Quiz Conditionals TEST 15 16 17 18 19 1 7:30 8:21 2 8:27 9:18 3 9:24 10:14 1 CLASS 7:30 8:18 1 FINAL 8:24
More informationCS110 Introduction to Computing Fall 2016 Practice Exam 1
CS110 Introduction to Computing Fall 2016 Practice Exam 1 The exam will be closed-note and closed-book; please consider this fact before using your notes on this practice version. Please see the abbreviated
More information+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.
+ Inheritance + Inheritance Classes that we design in Java can be used to model some concept in our program. For example: Pokemon a = new Pokemon(); Pokemon b = new Pokemon() Sometimes we need to create
More informationKimberly Nguyen Professor Oliehoek Introduction to Programming 8 September 2013
1. A first program // Create 200x200 canvas // Print favorite quote size(200, 200); println("it is what it is"); // Draw rectangle and a line rect(100,100,50,50); line(0,0,50,50); // Save as.pde. Can be
More informationModule 01 Processing Recap. CS 106 Winter 2018
Module 01 Processing Recap CS 106 Winter 2018 Processing is a language a library an environment Variables A variable is a named value. It has a type (which can t change) and a current value (which can
More informationModule 01 Processing Recap
Module 01 Processing Recap Processing is a language a library an environment Variables A variable is a named value. It has a type (which can t change) and a current value (which can change). Variables
More informationCISC 1600 Lecture 3.1 Introduction to Processing
CISC 1600 Lecture 3.1 Introduction to Processing Topics: Example sketches Drawing functions in Processing Colors in Processing General Processing syntax Processing is for sketching Designed to allow artists
More informationEvaluating Logical Expressions
Review Hue-Saturation-Brightness vs. Red-Green-Blue color Decimal, Hex, Binary numbers and colors Variables and Data Types Other "things," including Strings and Images Operators: Mathematical, Relational
More informationmith College Computer Science CSC103 How Computers Work Week 7 Fall 2017 Dominique Thiébaut
mith College Computer Science CSC103 How Computers Work Week 7 Fall 2017 Dominique Thiébaut dthiebaut@smith.edu Important Review Does the animation leave a trace? Are the moving objects move without a
More information(Inter)Ac*ve Scripts. Sta*c Program Structure 1/26/15. Crea+ve Coding & Genera+ve Art in Processing 2 Ira Greenberg, Dianna Xu, Deepak Kumar
(Inter)Ac*ve Scripts Crea+ve Coding & Genera+ve Art in Processing 2 Ira Greenberg, Dianna Xu, Deepak Kumar Slides revised by Michael Goldwasser Sta*c Program Structure // Create and set canvas size(width,
More informationComputer Graphics. Interaction
Computer Graphics Interaction Jordi Linares i Pellicer Escola Politècnica Superior d Alcoi Dep. de Sistemes Informàtics i Computació jlinares@dsic.upv.es http://www.dsic.upv.es/~jlinares processing allows
More informationInteraction Design A.A. 2017/2018
Corso di Laurea Magistrale in Design, Comunicazione Visiva e Multimediale - Sapienza Università di Roma Interaction Design A.A. 2017/2018 7 Conditionals in Processing Francesco Leotta, Andrea Marrella
More information1 Getting started with Processing
cis3.5, spring 2009, lab II.1 / prof sklar. 1 Getting started with Processing Processing is a sketch programming tool designed for use by non-technical people (e.g., artists, designers, musicians). For
More informationLoops. Variable Scope Remapping Nested Loops. Donald Judd. CS Loops 1. CS Loops 2
Loops Variable Scope Remapping Nested Loops CS105 05 Loops 1 Donald Judd CS105 05 Loops 2 judd while (expression) { statements CS105 05 Loops 3 Four Loop Questions 1. What do I want to repeat? - a rect
More informationCISC 1600 Lecture 2.2 Interactivity&animation in Processing
CISC 1600 Lecture 2.2 Interactivity&animation in Processing Topics: Interactivity: keyboard and mouse variables Interactivity: keyboard and mouse listeners Animation: vector graphics Animation: bitmap
More informationThis unit introduces the basics of trigonometry and how to utilize it for generating form.
Math 3: Trigonometry This unit introduces the basics of trigonometry and how to utilize it for generating form. Syntax introduced: PI, QUARTER_PI, HALF_PI, TWO_PI, radians(), degrees() sin(), cos(), arc()
More information2D Shapes. Creative Coding & Generative Art in Processing 2 Ira Greenberg, Dianna Xu, Deepak Kumar
2D Shapes Creative Coding & Generative Art in Processing 2 Ira Greenberg, Dianna Xu, Deepak Kumar Did you do this? Read Chapter 2 (pages 33-50) Read and do the Coordinate Systems & Shapes and Color tutorials
More informationBasic Computer Programming (Processing)
Contents 1. Basic Concepts (Page 2) 2. Processing (Page 2) 3. Statements and Comments (Page 6) 4. Variables (Page 7) 5. Setup and Draw (Page 8) 6. Data Types (Page 9) 7. Mouse Function (Page 10) 8. Keyboard
More informationFinal Exam Winter 2013
Final Exam Winter 2013 1. Which modification to the following program makes it so that the display shows just a single circle at the location of the mouse. The circle should move to follow the mouse but
More informationINTRODUCTION TO PROCESSING. Alark Joshi, Amit Jain, Jyh-haw Yeh and Tim Andersen
INTRODUCTION TO PROCESSING Alark Joshi, Amit Jain, Jyh-haw Yeh and Tim Andersen What is Processing? Processing is a programming language designed to make programming easier Developers were frustrated with
More informationCISC 1600 Lecture 2.2 Interactivity&animation in Processing
CISC 1600 Lecture 2.2 Interactivity&animation in Processing Topics: Interactivity: keyboard and mouse variables Interactivity: keyboard and mouse listeners Animation: vector graphics Animation: bitmap
More informationCST112 Variables Page 1
CST112 Variables Page 1 1 3 4 5 6 7 8 Processing: Variables, Declarations and Types CST112 The Integer Types A whole positive or negative number with no decimal positions May include a sign, e.g. 10, 125,
More informationUsing Methods. Methods that handle events. Mairead Meagher Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics
Using Methods Methods that handle events Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Caveat The term function is used in Processing e.g. line(),
More informationArrays. Array an ordered collec3on of similar items. An array can be thought of as a type of container.
Chapter 9 Arrays Arrays Array an ordered collec3on of similar items Student test scores Mail boxes at your college A collec3on of books on a shelf Pixels in an image the posi3ons for many stars in a night
More informationCISC 1600, Lab 2.2: Interactivity in Processing
CISC 1600, Lab 2.2: Interactivity in Processing Prof Michael Mandel 1 Getting set up For this lab, we will again be using Sketchpad, a site for building processing sketches online using processing.js.
More informationCMPT-166: Sample Final Exam Answer Key
CMPT 166, Summer 2012, Surrey Sample Final Exam Answer Key Page 1 of 9 CMPT-166: Sample Final Exam Answer Key Last name exactly as it appears on your student card First name exactly as it appears on your
More informationNature of Code. Patrick Dwyer Fall 2005 Week 4 - September 27 th
(1 of 7) Nature of Code Patrick Dwyer Fall 2005 Week 4 - September 27 th Trigonometry Trigonometry is the study and utilization of the relationships between the sides and angles of triangles. We ll be
More informationWhat is a variable? a named location in the computer s memory. mousex mousey. width height. fontcolor. username
What is a variable? a named location in the computer s memory mousex mousey width height fontcolor username Variables store/remember values can be changed must be declared to store a particular kind of
More informationCISC 1600, Lab 3.2: Interactivity in Processing
CISC 1600, Lab 3.2: Interactivity in Processing Prof Michael Mandel 1 Getting set up For this lab, we will be using OpenProcessing, a site for building processing sketches online using processing.js. 1.1.
More informationTransform 1: Translate, Matrices
Transform 1: Translate, Matrices This unit introduces coordinate system transformations and explains how to control their scope. Syntax introduced: translate(), pushmatrix(), popmatrix() The coordinate
More informationIntroduction to Processing. Sally Kong
Introduction to Processing Sally Kong - Open Source Platform - Geared toward creating visual, interactive media - Created by Ben Fry and Casey Reas Basic Setup void setup() { size(800, 600); background(255);
More informationVariables and Control Structures. CS 110 Eric Eaton
Variables and Control Structures CS 110 Eric Eaton Review Random numbers mousex, mousey setup() & draw() framerate(), loop(), noloop() Mouse and Keyboard interaccon Arcs, curves, bézier curves, custom
More informationSimulation and User Interaction
Chapter 3 Simulation and User Interaction What is in This Chapter? This chapter explains the concepts behind very simple computer simulations. All examples are explained within a graphical context. The
More informationCPSC Fall L01 Final Exam
CPSC 601.36 - Fall 2009 - L01 Final Exam Copyright Jeffrey Boyd 2009 December 12, 2009 Time: 120 minutes General instructions: 1. This exam is open-book. You may use any reference material you require,
More informationInteraction Design A.A. 2017/2018
Corso di Laurea Magistrale in Design, Comunicazione Visiva e Multimediale - Sapienza Università di Roma Interaction Design A.A. 2017/2018 8 Loops and Arrays in Processing Francesco Leotta, Andrea Marrella
More informationQuestion 1 (10 points) Write the correct answer in each of the following: a) Write a Processing command to create a canvas of 400x300 pixels:
Question 1 (10 points) Write the correct answer in each of the following: a) Write a Processing command to create a canvas of 400x300 pixels: size(400, 300); b) After the above command is carried out,
More informationReview. Custom Objects. Comparing Declarations and Initializers Built PopGame. Classes Fields and Methods Instantiation using the "new" keyword
Review Custom Objects Classes Fields and Methods Instantiation using the "new" keyword Comparing Declarations and Initializers Built PopGame Top-down Design Graphics Our Toolkit A Review lines, shapes,
More informationThe Processing language
The Processing language Developed by Ben Fry and Casey Reas at MIT in 2001 Related to the languages Logo and Java Free, open-source software processing.org contains many programming resources www.openprocessing.org
More informationCISC 1600, Lab 3.1: Processing
CISC 1600, Lab 3.1: Processing Prof Michael Mandel 1 Getting set up For this lab, we will be using OpenProcessing, a site for building processing sketches online using processing.js. 1.1. Go to https://www.openprocessing.org/class/57767/
More informationChapter 5. Condi.onals
Chapter 5 Condi.onals Making Decisions If you wish to defrost, press the defrost bu=on; otherwise press the full power bu=on. Let the dough rise in a warm place un.l it has doubled in size. If the ball
More informationCISC 1600, Lab 2.1: Processing
CISC 1600, Lab 2.1: Processing Prof Michael Mandel 1 Getting set up For this lab, we will be using Sketchpad, a site for building processing sketches online using processing.js. 1.1. Go to http://cisc1600.sketchpad.cc
More information1. Complete these exercises to practice creating user functions in small sketches.
Lab 6 Due: Fri, Nov 4, 9 AM Consult the Standard Lab Instructions on LEARN for explanations of Lab Days ( D1, D2, D3 ), the Processing Language and IDE, and Saving and Submitting. Rules: Do not use the
More informationCOMP Summer 2015 (A01) Jim (James) Young jimyoung.ca
COMP 1010- Summer 2015 (A01) Jim (James) Young young@cs.umanitoba.ca jimyoung.ca final float MAX_SPEED = 10; final float BALL_SIZE = 5; void setup() { size(500, 500); void draw() { stroke(255); fill(255);
More informationCMPT-166: Sample Midterm
CMPT 166, Fall 2016, Surrey Sample Midterm 1 Page 1 of 11 CMPT-166: Sample Midterm Last name exactly as it appears on your student card First name exactly as it appears on your student card Student Number
More informationModule 05 User Interfaces. CS 106 Winter 2018
Module 05 User Interfaces CS 106 Winter 2018 UI is a big topic GBDA 103: User Experience Design UI is a big topic GBDA 103: User Experience Design CS 349: User Interfaces CS 449: Human-Computer Interaction
More informationAll program statements you write should be syntactically correct. Partial credit is not guaranteed with incorrect use of syntax.
With Solutions in Red CS110 Introduction to Computing Fall 2012 Section 2 Exam 1 This is an open notes exam. Computers are not permitted. Your work on this exam must be your own. Answer all questions in
More informationmith College Computer Science CSC103 How Computers Work Week 6 Fall 2017 Dominique Thiébaut
mith College Computer Science CSC103 How Computers Work Week 6 Fall 2017 Dominique Thiébaut dthiebaut@smith.edu Ben Fry on Processing... http://www.youtube.com/watch?&v=z-g-cwdnudu An Example Mouse 2D
More informationCSE120 Wi18 Final Review
CSE120 Wi18 Final Review Practice Question Solutions 1. True or false? Looping is necessary for complex programs. Briefly explain. False. Many loops can be explicitly written out as individual statements
More informationGRAPHICS PROGRAMMING. LAB #3 Starting a Simple Vector Animation
GRAPHICS PROGRAMMING LAB #3 Starting a Simple Vector Animation Introduction: In previous classes we have talked about the difference between vector and bitmap images and vector and bitmap animations. In
More informationIntroduction to Processing
Processing Introduction to Processing Processing is a programming environment that makes writing programs easier. It contains libraries and functions that make interacting with the program simple. The
More informationCS 106 Winter Lab 05: User Interfaces
CS 106 Winter 2018 Lab 05: User Interfaces Due: Wednesday, February 6th, 11:59pm This lab will allow you to practice User Interfaces using Direct Manipulation and ControlP5. Each question is on a separate
More informationCOMP Summer 2015 (A01) Jim (James) Young jimyoung.ca
COMP 1010- Summer 2015 (A01) Jim (James) Young young@cs.umanitoba.ca jimyoung.ca order of operations with the explicit cast! int integervariable = (int)0.5*3.0; Casts happen first! the cast converts the
More informationMethods (cont.) Chapter 7
Methods (cont.) Chapter 7 Defining Simple Methods ReturnType Iden&fier ( ParameterList ) { Body ReturnType is the type of value returned from the method/funcbon. IdenBfier is the name of the method/funcbon.
More informationRepetition is the reality and the seriousness of life. Soren Kierkegaard
6 Loops Loops 81 Repetition is the reality and the seriousness of life. Soren Kierkegaard What s the key to comedy? Repetition. What s the key to comedy? Repetition. Anonymous In this chapter: The concept
More informationpygame Lecture #2 (Examples: movingellipse, bouncingball, planets, bouncingballgravity)
pygame Lecture #2 (Examples: movingellipse, bouncingball, planets, bouncingballgravity) MOVEMENT IN PYGAME I. Realizing the screen is getting redrawn many times. Let's take a look at the key portion of
More informationReading on the Accumulation Buffer: Motion Blur, Anti-Aliasing, and Depth of Field
Reading on the Accumulation Buffer: Motion Blur, Anti-Aliasing, and Depth of Field 1 The Accumulation Buffer There are a number of effects that can be achieved if you can draw a scene more than once. You
More informationReview Cellular Automata The Game of Life. 2D arrays, 3D arrays. Review Array Problems Challenge
Review Cellular Automata The Game of Life 2D arrays, 3D arrays Review Array Problems Challenge example1.pde Up until now All movement and sizing of graphical objects have been accomplished by modifying
More informationName CMPS 5J Final March 17, 2010 This is a closed notes, closed book exam. Each problem is worth 1 point unless indicated otherwise.
Name CMPS 5J Final March 17, 2010 This is a closed notes, closed book exam. Each problem is worth 1 point unless indicated otherwise. There are 21 problems and 25 points total. There are multiple versions
More informationThe way I feel about music is that there is no right and wrong. Only true and false. Fiona Apple. true false false
5 Conditionals Conditionals 59 That language is an instrument of human reason, and not merely a medium for the expression of thought, is a truth generally admitted. George Boole The way I feel about music
More informationvoid mouseclicked() { // Called when the mouse is pressed and released // at the same mouse position }
Review Commenting your code Random numbers and printing messages mousex, mousey void setup() & void draw() framerate(), loop(), noloop() Arcs, curves, bézier curves, beginshape/endshape Example Sketches
More informationKhan Academy JavaScript Study Guide
Khan Academy JavaScript Study Guide Contents 1. Canvas graphics commands with processing.js 2. Coloring 3. Variables data types, assignments, increments 4. Animation with draw loop 5. Math expressions
More informationExploring Processing
Exploring Processing What is Processing? Easy-to-use programming environment Let s you edit, run, save, share all in one application Designed to support interactive, visual applications Something we ve
More informationCSC 220 Object-Oriented Multimedia Programming, Spring 2017
CSC 220 Object-Oriented Multimedia Programming, Spring 2017 Dr. Dale E. Parson, Assignment 2, Working with 3D shapes and geometric transforms. This assignment is due via D2L Dropbox Assignment 2 ShapePaint3DIntro
More information[ the academy_of_code] Senior Beginners
[ the academy_of_code] Senior Beginners 1 Drawing Circles First step open Processing Open Processing by clicking on the Processing icon (that s the white P on the blue background your teacher will tell
More informationReal Time Data Plotting
Real Time Data Plotting Introduction This lesson will show how to write a program plot data on a X-Y graph. On the Arduino, write a program to sample a sensor and print the voltage to the Serial interface.
More informationMiscellaneous Stuff That Might Be Important.
1 Miscellaneous Stuff That Might Be Important. Variable mousepressed VS function mousepressed( ) For much of the work in this class, it is usually safer to use the function form of mousepressed( ) instead
More informationPractice Written Examination, Fall 2016 Roger B. Dannenberg, instructor
15-104 Practice Written Examination, Fall 2016 Roger B. Dannenberg, instructor Possibly useful function signatures (italics mean an expression goes here ): createcanvas(w, h); width height key background(r,
More informationRecall that creating or declaring a variable can be done as follows:
Lesson 2: & Conditionals Recall that creating or declaring a variable can be done as follows:! float radius = 20;! int counter = 5;! string name = Mr. Nickel ;! boolean ispressed = true;! char grade =
More informationCS 106 Winter Lab 03: Input and Output
CS 106 Winter 2019 Lab 03: Input and Output Due: Wednesday, January 23th, 11:59pm Summary This lab will allow you to practice input and output. Each question is on a separate page. SAVE each sketch as
More informationWhat is a variable? A named locajon in the computer s memory. A variable stores values
Chapter 4 Summary/review coordinate system basic drawing commands and their parameters (rect, line, ellipse,background, stroke, fill) color model - RGB + alpha Processing IDE - entering/saving/running
More informationCS116X Midterm Review Winter 2015
CS116X Midterm Review Winter 2015 This review will most likely not cover everything that could possibly be on the exam. The following is intended to help you study but remember that you may be tested on
More informationEXAMINATIONS 2016 TRIMESTER 2
EXAMINATIONS 2016 TRIMESTER 2 CGRA 151 INTRODUCTION TO COMPUTER GRAPHICS Time Allowed: TWO HOURS CLOSED BOOK Permitted materials: Silent non-programmable calculators or silent programmable calculators
More informationThis Week Assignment 1 Arrays Time Casting Reading code Project 1
Computation as an Expressive Medium Lab 2: Kindergarten Cubbies, Back to the Future and Lego Mania Joshua Cuneo This Week Assignment 1 Arrays Time Casting Reading code Project 1 Assignment 1 A1-01: Draw
More informationWe will start our journey into Processing with creating static images using commands available in Processing:
Processing Notes Chapter 1: Starting Out We will start our journey into Processing with creating static images using commands available in Processing: rect( ) line ( ) ellipse() triangle() NOTE: to find
More informationBits and Bytes. How do computers compute?
Bits and Bytes How do computers compute? Representing Data All data can be represented with: 1s and 0s on/of true/false Numbers? Five volunteers... Binary Numbers Positional Notation Binary numbers use
More informationLCC 6310 The Computer as an Expressive Medium. Lecture 9
LCC 6310 The Computer as an Expressive Medium Lecture 9 Overview Course pace Programming questions related to project 2? (due Friday 5pm!) Programming concepts super and this Java SDK classes Lists Reading
More informationBasic Input and Output
Basic Input and Output CSE 120 Spring 2017 Instructor: Justin Hsia Teaching Assistants: Anupam Gupta, Braydon Hall, Eugene Oh, Savanna Yee Administrivia Assignments: Animal Functions due today (4/12) Reading
More informationCSC 120 Introduction to Creative Graphical Coding, Fall 2017
CSC 120 Introduction to Creative Graphical Coding, Fall 2017 Dr. Dale E. Parson, Assignment 1, Implementing and testing an automated avatar in Processing. This assignment is due via D2L Assignments Assignment
More informationConditional Events. Mouse events and Operators. Dr. Siobhán Drohan Mairead Meagher. Produced by:
Conditional Events Mouse events and Operators Produced by: Dr. Siobhán Drohan Mairead Meagher Department of Computing and Mathematics http://www.wit.ie/ Topics list Mouse Events Recap: Arithmetic Operators
More informationGetting Started in Java CIS 110
Getting Started in Java CIS 110 2 Your First Program Program name 3 Your First Program The 4 li es aside fro the System.out li e are o sidered the Scaffolding of the program. Section 1.1 4 Your First Program
More informationThis assignment was revised from the original PDF released to revise/add Parts D and E.
Behind the Digital Screen Assignment 5: Visualization Deadline: Monday, 4/11, 3pm (one hour before class begins) This assignment was revised from the original PDF released to revise/add Parts D and E.
More informationCMSC427 Interac/ve programs in Processing: Polyline editor
CMSC427 Interac/ve programs in Processing: Polyline editor Interactive programming Example: PaperSnowFlake hbp://rectangleworld.com/papersnowflake/ Big ideas today Event driven programming Object list
More informationThe Processing language. Arduino and Processing.
IAT267 Introduc/on to Technological Systems Lecture 8 The Processing language. Arduino and Processing. 1 Course Project All teams submibed very interes/ng proposals One requirement for the project is to
More informationThe Junior Woodchuck Manuel of Processing Programming for Android Devices
Page1of15 TheJuniorWoodchuck Manuel of ProcessingProgramming for AndroidDevices TheImage JuniorWoodchuckManuelforProcessingProgramming Version1 CopyrightDavidNassarandJimRoberts,December2011,PittsburghPA
More informationGraphics with Processing
Grahics with Processig 2018-05 htt://vilab.org 5.1 begishae( ) POINTS, LINES, TRIANGLES, TRIANGLE_FAN, TRIANGLE_STRIP, QUADS, QUAD_STRIP edshae() edshae(close): vertex(x, y) curvevertex(x, y) beziervertex(x1,
More informationExam I Review Questions Fall 2010
Exam I Review Questions Fall 2010 The following review questions are similar to the kinds of questions you will be expected to answer on Exam I (scheduled for Oct. 14), which will cover LCR, chs. 1 7,
More informationIf the ball goes off either the right or left edge, turn the ball around. If x is greater than width or if x is less than zero, reverse speed.
Conditionals 75 Reversing the Polarity of a Number When we want to reverse the polarity of a number, we mean that we want a positive number to become negative and a negative number to become positive.
More informationCS 101 Functions. Lecture 15
CS 101 Functions Lecture 15 1 Key Processing language features so-far Basic color/shapes drawing Variables For-loops If-statements 2 Functions In the next few days, we ll be talking about Functions A Function
More informationWhat can we do with Processing? Let s check. Natural Language and Dialogue Systems Lab Guest Image. Remember how colors work.
MIDTERM REVIEW: THURSDAY I KNOW WHAT I WANT TO REVIEW. BUT ALSO I WOULD LIKE YOU TO TELL ME WHAT YOU MOST NEED TO GO OVER FOR MIDTERM. BY EMAIL AFTER TODAY S CLASS. What can we do with Processing? Let
More information