mith College Computer Science CSC103 How Computers Work Week 7 Fall 2017 Dominique Thiébaut

Similar documents
mith College Computer Science CSC103 How Computers Work Week 6 Fall 2017 Dominique Thiébaut

Pick a number. Conditionals. Boolean Logic Relational Expressions Logical Operators Numerical Representation Binary. CS Conditionals 1

CISC 1600, Lab 2.1: Processing

CISC 1600, Lab 3.1: Processing

mith College Computer Science Week 10 CSC111 Spring 2015 Dominique Thiébaut

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

CMPT-166: Sample Midterm

CISC 1600 Lecture 3.1 Introduction to Processing

A B C D CS105 03a Interaction

Kimberly Nguyen Professor Oliehoek Introduction to Programming 8 September 2013

1. Complete these exercises to practice creating user functions in small sketches.

Using Methods. Methods that handle events. Mairead Meagher Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics

Interaction Design A.A. 2017/2018

To specify the dimensions of the drawing canvas use the size statement: ! size( 300, 400 );

Design Programming DECO2011

University of Cincinnati. P5.JS: Getting Started. p5.js

Processing & Arduino in Tandem. Creating Your Own Digital Art Tools

Class Notes CN19 Class PImage Page

Conditional Events. Mouse events and Operators. Dr. Siobhán Drohan Mairead Meagher. Produced by:

INTRODUCTION TO PROCESSING. Alark Joshi, Amit Jain, Jyh-haw Yeh and Tim Andersen

Processing Assignment Write- Ups

What is a variable? A named locajon in the computer s memory. A variable stores values

Basic Computer Programming (Processing)

Class #1. introduction, functions, variables, conditionals

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:

[ the academy_of_code] Senior Beginners

5.1. Examples: Going beyond Sequence

Solution Notes. COMP 151: Terms Test

An Introduction to Processing

CS110 Introduction to Computing Fall 2016 Practice Exam 1 -- Solutions

The Junior Woodchuck Manuel of Processing Programming for Android Devices

Interaction Design A.A. 2017/2018

We will start our journey into Processing with creating static images using commands available in Processing:

Variables and Control Structures. CS 110 Eric Eaton

1 Getting started with Processing

The Processing language. Arduino and Processing.

What can we do with Processing? Let s check. Natural Language and Dialogue Systems Lab Guest Image. Remember how colors work.

CS110 Introduction to Computing Fall 2016 Practice Exam 1

Iteration in Programming

Bits and Bytes. How do computers compute?

What is a variable? a named location in the computer s memory. mousex mousey. width height. fontcolor. username

THE JAVASCRIPT ARTIST 15/10/2016

Introduction to Processing. Sally Kong

CSE120 Wi18 Final Review

CST112 Variables Page 1

CS 101 Media (Images, Video, etc) Lecture 20

All program statements you write should be syntactically correct. Partial credit is not guaranteed with incorrect use of syntax.

CS 106 Winter Lab 03: Input and Output

CISC 1600, Lab 2.2: Interactivity in Processing

The way I feel about music is that there is no right and wrong. Only true and false. Fiona Apple. true false false

Introduction to Processing

EXAMINATIONS 2016 TRIMESTER 2

Repetition is the reality and the seriousness of life. Soren Kierkegaard

Functions. Functions. nofill(); point(20, 30); float angle = map(i, 0, 10, -2, 2); parameters return values

CISC 1600 Lecture 2.2 Interactivity&animation in Processing

Interaction Design A.A. 2017/2018

CISC 1600, Lab 3.2: Interactivity in Processing

Recall that creating or declaring a variable can be done as follows:

COMP Summer 2015 (A01) Jim (James) Young jimyoung.ca

Final Exam Winter 2013

Evaluating Logical Expressions

Watch the following for more announcements

CS 106 Winter Lab 05: User Interfaces

Name CMPS 5J Final March 17, 2010 This is a closed notes, closed book exam. Each problem is worth 1 point unless indicated otherwise.

CISC 1600 Lecture 2.2 Interactivity&animation in Processing

void mouseclicked() { // Called when the mouse is pressed and released // at the same mouse position }

Variables. location where in memory is the information stored type what sort of information is stored in that memory

Exploring Processing

SFPL Reference Manual

float[][] myfloats = new float[10][20]; All elements of a 2D array can be accessed using nested loops

Variables One More (but not the last) Time with feeling

CISC 1600, Lab 2.3: Processing animation, objects, and arrays

Old 257 Exam #2s for Practice

PyGame Unit ?

Name CMPS 5J Final March 17, 2009 This is a closed notes, closed book exam.

if / if else statements

mith College Computer Science Digitizing Smith A Liberal Arts Module Week 11 CSC111 - Fall 2015 Dominique Thiébaut

CST112 Looping Statements Page 1

Loops. Variable Scope Remapping Nested Loops. Donald Judd. CS Loops 1. CS Loops 2

In this chapter: What is an array? Declaring an array. Initialization. Array operations using the for loop with an array. Arrays of objects.

Chapter 5. Condi.onals

COMP Summer 2015 (A01) Jim (James) Young jimyoung.ca

CS 101 Functions. Lecture 15

Module 01 Processing Recap. CS 106 Winter 2018

Sten-SLATE ESP. Graphical Interface

Graphics: Legacy Library

Graphics Overview ECE2893. Lecture 19. ECE2893 Graphics Overview Spring / 15

mith College Computer Science Lecture Notes CSC111 Week 7 Spring 2018 Dominique Thiébaut

EXAMINATIONS 2017 TRIMESTER 2

Module 01 Processing Recap

IMAGE PROCESSING OVERVIEW

1 Getting started with Processing

2D Shapes. Creative Coding & Generative Art in Processing 2 Ira Greenberg, Dianna Xu, Deepak Kumar

If 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.

The Processing language

CPSC Fall L01 Final Exam

PLT Miscellaneous Libraries: Reference Manual

CSC 120 Introduction to Creative Graphical Coding, Fall 2015

Methods (cont.) Chapter 7

EP486 Microcontroller Applications

Transcription:

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 trace? Are objects appearing in fixed position? Learn how to guesstimate positions in the window (see next slide)

Guess where the blue squares are located 500x500

Exercise replace the circles by squares

Exercise Mix circles and squares. Circles only move horizontally with the mouse.

Exercise Circles move horizontally with the mouse, and squares move vertically.

Using Random Numbers

The random() function https://processing.org/reference/random_.html

Printing random()

Exercise Replace mousex and mousey by calls to random(500)

Understanding Colors

Understanding Colors

Understanding Colors

Understanding Colors

Understanding Colors Pixel

Understanding Colors { 23 Pixel 13 19

Understanding Colors { 23 red Pixel 13 green 19 blue

RGB System Each pixel corresponds to 3 numbers 1st number = shade of red in the color of the pixel 2nd number = shade of green in the color of the pixel 3rd number = shade of blue in the color of the pixel Red-Green-Blue = RGB Each shade is represented by 8 bits

RGB System 0,0,0 is black 255,255,255 is white 100,100,100 is grey and so is 200,200,200 and so is 50,50,50 How many shades of grey?

1 bit 0 1 2 bits 00 01 10 11 3 bits 000 001 010 011 100 101 110 111 4 bits 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 RGB System 8 bits 0000000 0000001 0000010 0000011 1111100 1111101 1111110 1111111

Color Selector

Hue, Saturation, Brightness Color Selector

Good Reference on Color Dan Shiffman's page: https://processing.org/tutorials/color/

https://www.reddit.com/r/dataisbeautiful/comments/7584no/3d_rgb_scatterplots_of_colours_used_in_famous/

Example Make the circles blue, and the squares red.

Exercise Emulate this graphic output

Exercise Emulate this graphic output Note that some ellipses are flat, others are tall and skinny

Variables

Variables They contain data Real numbers, integer numbers, characters, or Strings Variables have a name Names always start with a letter or an underscore, and can contain letters or digits: x, y, i, alpha, r2d2, c3po, x1, pi

Variables CamelCase https://upload.wikimedia.org/wikipedia/commons/thumb/e/ef/camelcase.svg/1200px-camelcase.svg.png

Example

Example float x = 3.5; float y = 5.2; float sum; sum = x + y; println( "sum = " + sum );

Variable Types float int String (see https://processing.org/reference/string.html) boolean

// define geometry of rectangle float w = random(100, 300); float h = random(100, 300); float x = random( 500 ); float y = random( 500 ); Example // draw a transparent grey version of it // at 5,5, offset from mouse cursor nostroke(); fill( 200, 200, 200, 100 ); rect( x+5, y+5, w, h ); // draw a randomly colored rectangle at mouse // cursor float red = random( 255 ); float green = random( 255 ); float blue = random( 255 ); fill ( red, green, blue ); rect( x, y, w, h );

We stopped here last time

Loops (See https://processing.org/reference/for.html)

Example 1 for ( int i=0; i <= 10; i=i+1 ) { } println( i );

Example 1 for ( int i=0; i <= 10; i=i+1 ) { } println( i ); i++

Example 1 for ( int i=0; i <= 10; i++ ) { } println( i );

Example 2 int sum = 0; for ( int counter=0; counter <= 10; counter++ ) { sum = sum + counter; } println( "sum = ", sum );

Example 3 void draw() { fill( 200, 100, 0 ); } for ( int x=50; x<500; x = x + 100 ) { ellipse( x, 100, 40, 40 ); }

Example 4 void draw() { fill( 200, 100, 0 ); } for ( int y=50; y<500; y = y + 100 ) { ellipse( 100, y, 40, 40 ); }

Example 5 void draw() { fill( 200, 100, 0 ); for ( int x=50; x<500; x = x + 100 ) { for ( int y=50; y<500; y = y + 100 ) { ellipse( x, y, 40, 40 ); } } }

The if statement: Testing conditions

Example Color circles red on left side of window, and blue and right side. red > fill( 242, 66, 213 ); blue > fill( 49, 132, 245 );

void draw() { if ( ) { // set fill color to red fill( 242, 66, 213 ); } else { // set fill color to blue fill( 49, 132, 245 ); } ellipse( mousex, mousey, 80, 80 ); }

The If-Statement if ( boolean expression ) { statement; statement; } else { statement; statement; }

The If-Statement if ( boolean expression ) { statement; statement; } else { statement; statement; } xxx < yyy xxx <= yyy xxx > yyy xxx >= yyy xxx == yyy xxx!= yyy

Example Draw circles only if the mouse button is pressed

Lab Time! https://www.mmcsd.org/cms/lib/ny01922981/centricity/domain/70/banner_computers2.gif

Animation with Processing

Reference Page http://www.science.smith.edu/dftwiki/index.php/ Processing_Tutorial_--_Showing_Animated_Gifs

#1: Create the Skeleton Sketch // aquarium0 void setup() { size( 1000, 600 ); smooth(); } void draw() { }

#2: Create Data Directory

#3a: Find an animated gif fish with transparent background https://www.google.com/search?q=animated+gif+fish+transparent

#3b: Save the Fish to Data

#4: Find image of a Fish Tank

#5b: Save tank to Data

#6: Display Fish and Tank // aquiarium00 PImage fish; PImage tank; void setup() { size( 900, 500 ); smooth(); fish = loadimage( "fish.gif" ); tank = loadimage( "tank.jpg" ); } void draw() { image( tank, 0, 0, width, height ); image( fish, 100, 100 ); }

#6: Display Fish and Tank // aquiarium0 PImage fish; PImage tank; void setup() { size( 900, 500 ); smooth(); fish = loadimage( "fish.gif" ); tank = loadimage( "tank.jpg" ); } void draw() { image( tank, 0, 0, width, height ); image( fish, 100, 100 ); }

#7a: Break up Fish into Frames https://ezgif.com/split

#7b: Store Frames into Data

// aquiarium0 #8: Update Sketch PImage[] fish = new PImage[8]; PImage tank; void setup() { size( 900, 500 ); smooth(); fish[0] = loadimage( "fish0.gif" ); fish[1] = loadimage( "fish1.gif" ); fish[2] = loadimage( "fish2.gif" ); fish[3] = loadimage( "fish3.gif" ); fish[4] = loadimage( "fish4.gif" ); fish[5] = loadimage( "fish5.gif" ); fish[6] = loadimage( "fish6.gif" ); fish[7] = loadimage( "fish7.gif" ); tank = loadimage( "tank.jpg" ); } void draw() { image( tank, 0, 0, width, height ); image( fish[framecount % 8], 100, 100 ); }

# 9: Make the Fish Move Forward PImage[] fish = new PImage[8]; PImage tank; int x = 0; int y = 100; void setup() { size( 900, 500 ); smooth(); fish[0] = loadimage( "fish0.gif" ); fish[1] = loadimage( "fish1.gif" ); fish[2] = loadimage( "fish2.gif" ); fish[3] = loadimage( "fish3.gif" ); fish[4] = loadimage( "fish4.gif" ); fish[5] = loadimage( "fish5.gif" ); fish[6] = loadimage( "fish6.gif" ); fish[7] = loadimage( "fish7.gif" ); tank = loadimage( "tank.jpg" ); void draw() { image( tank, 0, 0, width, height ); image( fish[framecount % 8], x, y ); x = x + 5; if ( x > width ) { x = -300; } } } framerate( 10 );

#10: Fancier Tank http://www.science.smith.edu/dftwiki/index.php/processing_tutorial_--_showing_animated_gifs,_part_2