Download Slides (.ppt) - Duke Computer Science

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Solar System Model
This is an modification of the July 2012 solar
system tutorial by Michael Marion
By Natalie Huffman
Under the direction of Susan Rodger
Duke University
June 2017
Pictures to download
• This tutorial comes with three images that will
allow you to make blank spheres look like
planets
• They are called “Sun”, “Earth”, and “Jupiter”
• Download them now and store them in an
accessible location on your computer
Create a new Alice world
• Select “moon” as your environment
• Go to setup scene
• Click on the “shapes/text” tab at the bottom
Add objects
• Click on new Sphere()
– Do not drag into the scene!
• Set the name as “sun”
Get rid of the ground
• There’s no ground in space!
• Select this.ground from
the menu on the far
left
• Set the “opacity”
property to
0.0
Your scene should look like this
• Add a camera marker
from the Camera Marker
tab on the bottom right
• Name the camera
“sunCam”
Camera Markers in Alice 3
• Camera markers let you save a viewpoint
• Above the scene buttons are two positioning
buttons
• The black camera represents your current point
of view
• The first button moves your
point of view to the red
camera (scene1)
• In order to move to scene2,
you would click on the scene2
button and then on the left top
button
• Note: this picture is from a different tutorial
Camera markers, cont.
• The second button, if clicked,
would reset the scene1 view
to the current view
• Do not click this button!
• Once we set a camera view,
we will likely not want to
change it
Change
current view
Change scene1
camera
This doesn’t look much like a sun
• We can change the “paint”
property to make it look
more like a sun
• Click the “Import Image”
button and select the
sun picture you
downloaded at the
beginning of this
tutorial
Now it looks more like a sun
• Repeat this process twice
more
• Note that there is no need
to add additional camera markers
• Call the spheres “earth” and “jupiter”
respectively
• Use the “Earth” and “Jupiter” pictures to make
the spheres look more like those planets
Our planets are all on top of each
other
• Alice creates objects in the same place, so all
of our planets are on top of each other
• You can fix this by moving them
• Right click on this.earth in the left-hand
menuproceduresthis.earth
moveLEFTCustom DecimalNumber
• Enter “4” for the custom number
• Repeat this for Jupiter, but move it 10 spaces
instead of 4
• Your planets probably look a little weird
• Almost like there’s a line
down the front of them
• This is because you’re seeing
the line where Alice joins
together the top and bottom
of the picture
• We don’t want to see that seam, so we’ll turn
our planets so it’s facing away from the
camera
• Right click on the sunproceduresthis.sun
turnBACKWARDS.25
• Repeat this for the Earth and for Jupiter
• The planets and the sun should look more
normal now
Size
• We want our spheres to be different sizes, to
reflect the way the sun, the Earth, and Jupiter
are all different sizes
• Click on the sun in the left menu and change
the radius to 2.0
• We want the Earth’s
radius to stay the same (0.5)
• Change Jupiter’s radius to
0.8
Reposition your window using the
arrows until you can see all three
spheres
• Try to get the sun in the middle of the screen,
since the two planets will eventually orbit it
• You can add a camera marker here as well so
you don’t lose your place
Time for the code!
• Click on the “edit code” button
• Create a new Scene procedure by clicking on
the dropdown menuSceneAdd Scene
Procedure
• Name it “rotate”
Add a parameter
• A parameter is an input to our procedure
• For example, when we use the “move”
procedure, we have to provide a parameter—
how far we want to move
• The parameter value is set in the method that
uses the procedure, so it can be changed
easily
Parameters
• Set the value type to DecimalNumber
• Set the name to “year”
• This parameter will control how long our
planet’s orbits are
• Drag a while loop into the method and select
“true”
• Drag a do together block into the while loop
• Now select this.earth from the lower left-hand
menu
• Drag in a turn statement, and select LEFT and
1.0
• This statement will make the earth turn in a
circle, but we want it to turn around the sun
• Click on the dropdown arrow and select
asSeenBythis.sun
• Click on the dropdown arrow again and select
durationyear (the parameter we created)
• This will make one full turn last for a year
• Finally, click on the dropdown arrow and
select
animationStyleBegin_And_End_Abruptly
• This will stop there from being a pause
between one orbit and the next
Jupiter
• Right click on the turn statement and select
“copy to clipboard”
• Click and drag from the clipboard into the do
together block
• Click on this.earth and change it to this.jupiter
• Click on 1.0 and change it to 0.25
• This means that jupiter’s orbit will complete
.25 of an orbit in one year
Go back to myFirstMethod
• Drag in rotate and select 1.0
• This means that a year (one rotation of Earth)
lasts one second
• Feel free to play with this value to make the
planets spin slower and faster
Run your code!
• If all three planets are not in your view, you
can go back to scene setup and edit the
camera view
• However, there is an easier way
• What if we let the arrow keys control the
camera?
Click on the initializeEventListener tab
• Click on Add Event ListenerKeyboard
addArrowKeyPressListener
• Click on this.camera in the lower left menu
and drag in a move statement
• Select any direction and amount
• Click on getMoveDirection (in the header) and
drag it onto LEFT
• Select FORWARD_BACKWARD_LEFT_RIGHT
• Change the number to 2.0
Run your code!
• You should now be able to use the arrow keys
to move the camera for a better view