CS-257L Nonimperative Programming: Scheme!

Similar documents
CS 351: Design of Large Programs.

Fun with Fractals and Functions. CHAMP at University of Houston March 2, 2015 Houston, Texas

Parameters and Objects

Symmetric Fractals. Seeking Sangaku Ramanujan, Hardy, and Ono

Helpful Hint When you are given a frieze pattern, you may assume that the pattern continues forever in both directions Notes: Tessellations

Computer and Programming: Lab 1

CS 105: Introduction to Computer Programming (using JavaScript) Quiz: Khan Academy: Intro to While Loop

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

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

CISC 1600, Lab 3.1: Processing

Graphics: Legacy Library

The Many Lessons in Fractals

7) Are HD and HA the same line?

FRACTALS AND THE SIERPINSKI TRIANGLE

CISC 1600, Lab 2.1: Processing

Review Interior Angle Sum New: Exterior Angle Sum

Grade 6 Math Circles. Shapeshifting

Creating. an Illustration. Illustrator 9.0. Objectives

CHAOS Chaos Chaos Iterate

In this lesson, students build fractals and track the growth of fractal measurements using tables and equations. Enduring Understanding

About Finish Line Mathematics 5

EASY INTERACTIVE WHITEBOARD

MAKE GEOMETRIC CONSTRUCTIONS

CS-259 Computer Programming Fundamentals Arrays

Discovering. Algebra. An Investigative Approach. Condensed Lessons for Make-up Work

What is a tessellation???? Give an example... Daily Do from last class Homework Answers 10 7 These are similar: What does y =? x =?

Circles and Polygons Long-Term Memory Review Review 1 (Note: Figures are not drawn to scale.)

THE JAVASCRIPT ARTIST 15/10/2016

2.) From the set {A, B, C, D, E, F, G, H}, produce all of the four character combinations. Be sure that they are in lexicographic order.

Note: For all questions, answer (E) NOTA means none of the above answers is correct. Unless otherwise specified, all angles are measured in degrees.

INSTRUCTIONS FOR THE USE OF THE SUPER RULE TM

2D Drawing Primitives

acute angle An angle with a measure less than that of a right angle. Houghton Mifflin Co. 2 Grade 5 Unit 6

2013 Four-by-Four Competition Thursday, January 31st, Round Four-by-Four Competition Thursday, January 31st, 2013.

PYP 5C s Maths Daily Lesson Plan 2012/2013 Strand: Space and Shape (2-D and 3-D shapes)

: Intro Programming for Scientists and Engineers Assignment 1: Turtle Graphics

Constructions Quiz Review November 29, 2017

Special Lines and Constructions of Regular Polygons

2nd Grade. 2D Shapes - Part 1 Angles and Sides. Slide 1 / 117 Slide 2 / 117. Slide 3 / 117. Slide 4 / 117. Slide 6 / 117.

2017 SOLUTIONS (PRELIMINARY VERSION)

PLC Papers Created For:

Construction Instructions. Construct the perpendicular bisector of a line segment. Or, construct the midpoint of a line segment.

12-6 Exercises KEYWORD: MG7 12-6

Unit 10 Study Guide: Plane Figures

The University of British Columbia Final Examination - December 02, 2014 Mathematics 308. Closed book examination. No calculators.

Geometry 10 and 11 Notes

Beaumont Middle School Design Project April May 2014 Carl Lee and Craig Schroeder

CSE 167: Lecture #17: Procedural Modeling. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Instant Insanity Instructor s Guide Make-it and Take-it Kit for AMTNYS 2006

1 Getting started with Processing

EEN118 LAB TWO. 1. A Five-Pointed Star.

Math 366 Lecture Notes Section 11.4 Geometry in Three Dimensions

Warm-up for Integrated Geometry and Algebra II

Polycom VisualBoard Technology Application

INTERACTIVE WHITEBOARDS: SMART Board Overview

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

3 Dimensional Solids. Table of Contents. 3 Dimensional Solids Nets Volume Prisms and Cylinders Pyramids, Cones & Spheres

NUMERICAL INTEGRATION AND FUNCTION FUNCTIONS

Euclid s Muse Directions

2. A straightedge can create straight line, but can't measure. A ruler can create straight lines and measure distances.

NUMB3RS Activity: I It Itera Iteration. Episode: Rampage

Mathematics 350 Section 6.3 Introduction to Fractals

Google SketchUp Design Exercise 1

In this lecture we will briefly examine a few new controls, introduce the concept of scope, random numbers, and drawing simple graphics.

Go to Grade 5 Everyday Mathematics Sample Lesson

Fun with Fractals Saturday Morning Math Group

Using Google SketchUp

Chapter 2 QUIZ. Section 2.1 The Parallel Postulate and Special Angles

YEAR 9 MATHS. Monday Wednesday Thursday - - Friday Introduce: 10A Distance between two points 10A.1. WEEK 3 Coordinate Geometry.

Unit 8 Syllabus: Surface Area & Volume

Lecture 1. Course Overview Types & Expressions

Sketching graphs of polynomials

Grade 8 Math WORKBOOK UNIT 1 : POLYGONS. Are these polygons? Justify your answer by explaining WHY or WHY NOT???

Version 5.0. Alexander Friedman and Jamie Raymond. June 6, 2010

Rhombic Hexacontahedron in Google SketchUp

Common Core State Standards High School Geometry Constructions

Puzzle page. Mathematical Misfits three dimensional. Dual polygons. Puzzle page

Finding Perimeters and Areas of Regular Polygons

krl gl drlrpcj cpr ougei tm arjgrvr tfct wfgef tfry wgqf tm ar tpur.

Exam 1 Format, Concepts, What you should be able to do, and Sample Problems

Excel Formulas & Functions I CS101

Using Google SketchUp

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

Draw beautiful and intricate patterns with Python Turtle, while learning how to code with Python.

CONSTRUCTING CONGRUENT LINE SEGMENTS

Polygons and Angles: Student Guide

Applications. segment CD. 1. Find the area of every square that can be drawn by connecting dots on a 3 dot-by-3 dot grid.

Quadratic: the time that it takes to sort an array is proportional to the. square of the number of elements.

Control Flow: Loop Statements

Day 1: Introduction to MATLAB and Colorizing Images CURIE Academy 2015: Computational Photography Sign-Off Sheet

COS226 - Spring 2018 Class Meeting # 13 March 26, 2018 Inheritance & Polymorphism

n! = 1 * 2 * 3 * 4 * * (n-1) * n

University of Massachusetts Lowell : Organization of Programming Languages Spring 2004 Problem Set 4. Henderson Picture Language

(the bubble footer is automatically inserted in this space)

Shape & Space Part C: Transformations

This guide will help you with many of the basics of operation for your Epson 485wi BrightLink Projector with interactive functionality.

USING THE TIERED CLASSROOM MULTIMEDIA EQUIPMENT Rooms

Computer Science AP/X CSCI-140/242 Polygons Lab 2 8/30/2018

The area of this square is 9 square units. This array has 2 rows and 5 columns. So, 2 5 = 10. The gas container has a capacity of 5 gallons.

CS324e -Elements of Graphics and Visualization. Fractals and 3D Landscapes

Transcription:

CS-257L Nonimperative Programming: Scheme! Instructor: Joel Castellanos e-mail: joel@unm.edu Web: http://cs.unm.edu/~joel/ Office: Farris Engineering Center (FEC room 321 Scheme Vectors Vectors applied in the Chaos Game Vectors to define Matrix Quiz Friday Bring to class a short (2 to 5 minute demo of a cool / novel / artistic l- system drawn by your l-system scheme code. Content: May show off whatever extra credit you did. May be a new l-system that you make up. May be an l-system you find on the Internet or in a book and draw with your Scheme software. Content format: May be a JPEG or PNG image. May be a few PowerPoint slides. May be running scheme code. Media: Your laptop connected to the projector USB drive. 2 1

Scheme Vectors 5 6 7 8 5 6 7 8 9 (define x 5 6 7 8 9 -ref x 2 -set! x 2 33 x #4(5 6 7 8 #5(5 6 7 8 9 7 #5(5 6 33 8 9 3 Vectors of Objects: Pens (define penvector (instantiate pen% ("RoyalBlue" 4 'solid (instantiate pen% ("DarkOrchid" 4 'solid (instantiate pen% ("MediumSeaGreen" 4 'solid (instantiate pen% ("Crimson" 4 'solid (instantiate pen% ("OrangeRed" 4 'solid (define getpen (lambda (idx -ref penvector idx 4 2

Vectors of Objects: Vertices ;Vertices of equilateral triangle (ChaosGame 0.0 1.0 1.0 1.0 0.5 (- 1.0 (sin (/ pi 3.0 (define getx (lambda (idx -ref -ref vertexvector idx 0 (define gety (lambda (idx -ref -ref vertexvector idx 1 5 Sierpiński Triangle via Chaos Game 1. Define the vertices of an equilateral triangle inscribed in a unit square. 2. Choose a random point, p 0, within the unit square. 3. Choose a random vertex v i of the equilateral triangle. 4. Iteratively define p i to be the midpoint of the line segment with endpoints p i-1 and v i. 5. Excepting the first few points, the set {p i, p i+1,... p n } form the Sierpiński Triangle. 6 3

Sierpiński Triangle: World to Screen ;Since the triangle is inscribed in a unit square, ;The only offset needed is the border. (set! scale (- (- (min drawwidth drawheight border border (define getscreenx (lambda (x (+ (floor (* x scale border (define getscreeny (lambda (y (+ (floor (* y scale border 7 Sierpiński Triangle: plot-ball (define plot-ball (lambda (dc x y idx (send dc set-pen (getpen idx (send dc draw-ellipse (- (getscreenx x 3 (- (getscreeny y 3 7 7 8 4

Sierpiński Triangle: DrawVertexies (define DrawVertexies (lambda (dc (do ((i 0 (+ i 1 ((>= i vertexcount (plot-ball dc (getx i (gety i i (send dc set-pen pen-black (let ((ii (modulo (+ i 1 vertexcount (plot-line dc (getx i (gety i (getx ii (gety ii 9 Sierpiński Triangle: Main Loop (do ((i 0 (+ i 1 ((> i 10000000 (sleep.001 (set! idx (inexact->exact (floor (* (random vertexcount (set! x (/ (+ x (getx idx 2 (set! y (/ (+ y (gety idx 2 (plot dc x y 10 5

Chaos Game First 10 Points (ChaosGame ;Vertices of ;Equilateral Triangle 0.0 1.0 1.0 1.0 0.5 (- 1.0 (sin (/ pi 3.0 10 ;points 0 Points are colored green blue or violet to match the color of the next randomly chosen vertex. 11 Chaos Game Equilateral Triangle (ChaosGame ;Vertices of ;Equilateral Triangle 0.0 1.0 1.0 1.0 0.5 (- 1.0 (sin (/ pi 3.0 500000 ;points 12 6

Chaos Game Regular Pentagon (ChaosGame ;Vertices of ;regular pentagon 0.5 0.951056516 0.0 0.587785252 0.190983006 0.0 0.809016994 0.0 1.0 0.587785252 500000 ;points 13 Lists as Function Arguments (define faa (lambda ( (define mylist '("Abby" "Bill" "Carl" (baa mylist (display mylist (newline (define baa (lambda (locallist (set! locallist '("Abby" "ZZZZZ" "Carl" (display locallist (newline (faa (Abby ZZZZZ Carl (Abby Bill Carl 14 7

Vectors as Function Arguments (define foo (lambda ( (define myvector "Abby" "Bill" "Carl" (boo myvector (display myvector (newline (define boo (lambda (localvector -set! localvector 1 "XXXXX" (display localvector (newline (foo #(Abby XXXXX Carl #(Abby XXXXX Carl 15 Vector - Copy by Reference (define fun (lambda (myvector1 (define myvector2 myvector1 -set! myvector2 1 "YYYYY" (display myvector1 (newline (display myvector2 (newline (fun "Abby" "Bill" "Carl" #(Abby YYYYY Carl #(Abby YYYYY Carl 16 8

Vector - Copy by Value (define fun (lambda (myvector1 (define myvector2 (apply vector ->list myvector1 -set! myvector2 1 "YYYYY" (display myvector1 (newline (display myvector2 (newline (fun "Abby" "Bill" "Carl" #(Abby Bill Carl #(Abby YYYYY Carl 17 Nested Vectors (define f1 (lambda (myvector1 (define myvector2 (apply vector ->list myvector1 (define myvector3 (apply vector ->list myvector1 -set! myvector2 0 77 88 -set! -ref myvector3 1 0 333 (display myvector1 (newline (display myvector2 (newline (display myvector3 (newline (f1 1 2 7 8 11 12 #(#(1 2 #(333 8 #(11 12 (apply uses #(#(77 88 #(333 8 #(11 12 Flat Recursion not #(#(1 2 #(333 8 #(11 12 Deep Recursion 18 9

copyvectoroforderedpairsbyvalue (define copyvectoroforderedpairsbyvalue (lambda (source sink (define x 0 (define y 0 (do ((i 0 (+ i 1 ((>= i -length source (set! x -ref -ref source i 0 (set! y -ref -ref source i 1 -set! -ref sink i 0 x -set! -ref sink i 1 y (define v1 1 2 7 8 (define v2 0 0 0 0 (copyvectoroforderedpairsbyvalue v1 v2 -set! -ref v2 0 0 333 (display v1 (newline (display v2 (newline #(#(1 2 #(7 8 #(#(333 2 #(7 8 What are possible errors? 19 Matrix ;Defines a 2D Matrix class. (define matrix (lambda (columns rows (define myvector (make-vector (+ 1 (* rows columns 0 ;Save the number of rows in myvector[0] ;This is needed for referencing elements. -set! myvector 0 rows myvector 20 10

Matrix Setting an Element ;Use analogous syntax to -set!... (define matrix-set! (lambda (myvector x y value (define rows -ref myvector 0 -set! myvector (+ (+ (* rows x y 1 value 21 Matrix Reading an Element ;Use analogous syntax to -ref... (define matrix-ref (lambda (myvector x y (define rows -ref myvector 0 -ref myvector (+ (+ (* rows x y 1 22 11