代写 DrRacket math graph ;; The first three lines of this file were inserted by DrRacket. They record metadata

;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
readerlib 2019fallreader.rkt csc104modname A1.2019F compthinksettings hashprefixtypes? . f
; CSC 104 Fall 2019 Assignment 1

; Due: Wednesday October 16th at 6PM.
; Late Penalty: 15 if submitted by Thursday October 17th at 6PM.

; You may work by yourself, or with another student from any section of the course,
; or with two other students from any sections of the course.

; Read the comments and tests, IN ORDER, and fixcomplete the incomplete tests and
; function definitions, which are indicated with a . When you work on a function,
; uncomment its tests.

; Goals of the program.
; Provide a function to graph a list of numbers.
; This wont be used in the second part, but does give us the ability to see the behaviour
; of two functions that are used in the second part.
; Create some overlayed seqences of images for the frames of an animation, to produce
; and explore some generative art.
; If youre interested in math, you can also ponder how the functions produce the results
; and behaviours you see.

; The interactive animation code provided at the end of the program uses the functions
; that you are fixing, but you dont need to know about animation in order to write the tests
; and to design and implement the functions. We will discuss interactive animation later
; in the course.

; ONE member of your group will submit this file, electronically, with the changes, but
; everyone in your group must keep copies of your groups work. In particular, you must
; be able to submit the work even if your other group members drop the course or stop
; talking to you before the due date.

; Before you submit:
; You MUST click in the Definitions area and then click the Format button.
; You should do that frequently anyway, to doublecheck that the indentation formatting
; matches your mental model of the structure of your code.
; EVERY function definition MUST still be GRAMATICALLY syntactically correct.
; In particular, if a function you worked on is stopping the program from running then
; commentout its body and put the original body back in, or commentout the whole
; definition and put the original version back in.
; For each function that you fix completely, you MUST uncomment all its tests.
; For each function that you didnt fix completely, you MUST commentout all its failing tests.

; The functions to design and define

; bar : produce a filled black vertical bar with width 1 and a given height
same! bar 20 .
same! width bar 100 1
same! height bar 50 50

; Turn the following test into a Full Design.
; Replace the literal image with an expression that uses the example argument to compute the image.
same! bar 20 .

; AFTER completing that Full Design, fix the body of this function definition accordingly.
define bar n
.

; settingmessage : produce a message, from the name of a quantity and a numeric amount
; This will be used to show the value of a setting to the user of the interactive animation.
same! settingmessage rotation 10 rotation: 10
;same! settingmessage spacing 5 spacing: 5
;same! settingmessage size 100 size: 100

; Turn the following test into a Partial or Full Design.
; Replace the literal result with an expression that computes it in some way.
same! settingmessage rotation 10 rotation: 10

; Theres a unary function in our language to convert a number to a text representation, for example:
same! numbertext 123 123

; Turn the following test into a Full Design.
; Replace the literal result with an expression that computes it from the literals rotation and 10.
; If your earlier Design was already a Full Design you can just use that Design again here
same! settingmessage rotation 10 rotation: 10

; AFTER completing that Full Design, fix the body of the function definition accordingly.
define settingmessage name amount
rotation: 10

; barchart : produce a bar chart of a list of numbers
; Each number is represented by a bar with that height.

; Heres an example, with the result scaled up since for just four numbers the result is hard to see:
;same! scale barchart list 3 7 5 4 10 .

same! barchart list 10 25 20 15 30 .

; A Partial Design:
;same! barchart list 3 7 5 4 alignbottoms bar 3 bar 7 bar 5 bar 4

; Fix the following Design using an expression that still uses the literal list . . . . . .
;same! barchart list 10 25 20 15 30 list . . . . .

; Turn the following test into a Full Design.
same! barchart list 10 25 20 15 30 .

; AFTER completing the Full Design, fix the body of the definition accordingly.
define barchart alist
.

; Some more examples, which you might find interesting:
;same! barchart range 25 .
;same! barchart range 10 30 .
;same! barchart range 10 30 .5 .
;same! barchart map squareof range 0 5 .1 .
;same! barchart map inc map squareof range 0 5 .1 .

; oscillate : a numeric function that oscillates between 0 and 100 with a period of 360
; approach : a numeric function that is 0 at 0 and then increases but never quite reaches 60
; These are used later, but can be visualized using the function barchart you made.
;same! scale barchart map oscillate range 1000 .25
. ; Oscillating.
;same! scale barchart map approach range 1000 .25
. ; Increasing with a horizontal asymptote.

; The math in these implementations are outside the scope of the course, so these definitions are
; provided for you and dont need fixing. You arent required to understand the bodies.

define oscillate n
100 squareof sin n 360

require onlyin racket atan

define approach n
60 atan n 180

; s.1, s.2 , s.3 , s.4 , s.5

; Here are the five functions the user will be able to select from to produce sequences of images
; to animate. The mathematical details of these functions are also outside the scope of the course.

define s.1 n
S oscillate n
3.6 oscillate n 2

define s.2 n
S approach n
2 n

define s.3 n
S 100
.9 oscillate n

define s.4 n
S approach n
approach n

define s.5 n
S approach n
1.8 oscillate n

; reset : replace the first number in a list of three elements, with zero
same! reset list 1 20 meow list 0 20 meow
;same! reset list 700 60 woof list 0 60 woof

; Here are examples of two functions useful for the Full Design:
same! second list argon boron carbon deuterium boron
same! third list argon boron carbon deuterium carbon

; Turn the following test into a Full Design.
same! reset list 1 20 meow list 0 20 meow

; AFTER completing the Full Design, fix the body of the definition accordingly.
define reset state
list 0 20 meow

; update : replace the first number in a list of three elements, with the sum of the first two
same! update list 700 60 woof list 760 60 woof
;same! update list 1 20 meow list 21 20 meow

; Turn the following test into a Design.
; Replace the literal result with an expression that computes the 760 in some way.
same! update list 700 60 woof list 760 60 woof

; Turn the following test into a Full Design.
same! update list 700 60 woof list 760 60 woof

; AFTER completing the Full Design, fix the body of the definition accordingly.
define update state
list 760 60 woof

; adjustspacing
; For a threeelement list and a number, change the first element to zero, and add the number
; to the second element and force that to be is at least one.
same! adjustspacing list 12 34 meow 5 list 0 39 meow
;same! adjustspacing list 12 34 meow 5 list 0 29 meow
;same! adjustspacing list 12 34 meow 50 list 0 1 meow

; Here are examples demonstrating a function that is useful for the Full Design:
same! maximum 14 32 50 32
same! maximum 1 23 23
same! maximum 1 23 1

; Turn the following two tests into Designs.
;same! adjustspacing list 12 34 meow 5 list 0 29 meow
;same! adjustspacing list 12 34 meow 50 list 0 1 meow

; Turn the following two tests into Full Designs.
;same! adjustspacing list 12 34 meow 5 list 0 29 meow
;same! adjustspacing list 12 34 meow 50 list 0 1 meow

; AFTER completing the Full Designs, fix the body of the definition accordingly.
define adjustspacing state amount
list 0 39 meow

; S : from a sizepercentage and angle, produce a resized rotated oval
same! S 10 50 .
;same! S 20 50 .
;same! S 30 50 .

; Write another test for S , that uses an angle different from 50.

; Turn the following two tests into Designs.
same! S 10 50 .
;same! S 20 50 .

; Turn the following test into a Full Design.
same! S 10 50 .

; AFTER completing the Full Design, fix the body of the definition accordingly.
define S offullsize angle
.

; sketch
; For a unary function that takes a number and produces an image, overlay the images
; that the function produces, for a range of numbers.
; The function accepts three arguments: the second argument is the upper bound for the range
; of numbers, and the third argument is the space between the numbers.

; The following defines an example function that is used in some of the tests.
define r n
rotate rectangle 10 30
25 n

same! sketch r 3 1 .
;same! sketch r 5 2 .
;same! sketch r 3 1 overlay r 0 r 1 r 2
;same! sketch r 10 2 overlay r 0 r 2 r 4 r 6 r 8

; Write another test for sketch , that does not use the function r as the first argument.

; Turn the following test into a Full Design.
same! sketch r 3 1 overlay r 0 r 1 r 2

; AFTER completing the Full Designs, fix the body of the definition accordingly.
define sketch f n spacing
.

; The Program
; The program is now ready to run!
; Uncomment the definition of changeorreset and the bigbang expression at the end of the file.
; Then Run!

; We discuss the the bigbang animation and interaction framework later in the course.
; The code below presents the images …
;sketch s.1 3 3 ;sketch s.1 6 3 ;sketch s.1 9 3 ;etc
; … in succession, as frames of an animation, using your function update to produce
; the arguments 3, 6, 9, etc by adding 3 each time.

; Press the up or down arrow keys to adjust the spacing between images.
; Try a spacing of 7: that behaves noticeably different than for 3, 4, 5, and 6.
; Press the space bar to switch to the next function in the cycle s.1 s.2 s.3 s.4 s.5 s.1 s.2 ….
; Press any other key to restart the animation without changing the function nor spacing.

; A function to present the image sketch f n spacing and the current settings.
define draw f n spacing
above overlay sketch f n spacing
blank 1.25 400
above textimage settingmessage spacing spacing 16
textimage textjoin function functionname f 16
textimage Press up or down arrow key , or space bar. 16

define unpackfordraw state draw first third state first state second state

define cyclefunctions state
list 0
second state
append rest third state first third state

require onlyin racketbase objectname symbolstring
define functionname f symbolstring objectname f

;define changeorreset state key
if same? key up adjustspacing state 1
same? key down adjustspacing state 1
same? key cyclefunctions state
else reset state

;bigbang list 0 3 list s.1 s.2 s.3 s.4 s.5
ontick update
onkey changeorreset
todraw unpackfordraw 1.25 400 1.25 400 4 16