|
Computer Science Classes at Marshfield High School |
For Assignment for REALBasic
One thing at which computers are perhaps better than people is repetitive tasks - doing something over, and over, and over.
- Create a New Folder on the H: Drive under your REALbasic Folder called Graphics
- Create four new projects and save them in your Graphics Folder.
- Drag a Canvas onto a Window
- Don't copy and paste, type in the following text, and get used to typing out for loop syntax.
Follow the instructions, implement and run the following four loops. Lastly, do the assignment to animate a ball moving! Keep each RealBasic projects separate leaving you with four distinct assignments.
Loop One)
For ... next loop
Dim i as integer
for i = 1 to 100
g.drawline (i * 5, 200, i* 5, 220)
next i
What does it do? What happens if you change the '5's to '10's?
Try a new random number generator.rnd gives a random number between zero and one. If you multiply it by 500 you get a random number between 0 and 499.
Loop Two)
Dim i as integer
for i = 1 to 100
g.drawline(rnd * 500, rnd * 500, rnd * 500, rnd * 500)
next i
Hints for the Extras
Use Canvas1.width to detect the end of the canvas and Canvas1.height to detect bottom of canvas
Loop 3)
Try this loop and comment each line of code to describe what it does
Dim i, x, y as integer
x= 100
y = 150
g.textSize =78
g.bold = true
for i = 1 to 5
g.forecolor = rgb(rnd *255,rnd *255,rnd *255)
g.DrawString (str(i), x, y,100 )
x = x + 40
msgbox "how many times through the loop " +str( I)
next iLoop 4)
Put this code in the action method of the Timer and describe why it looks like it is animated.
Dim i, x, y as integer
x= 100
y = 150
graphics.textSize =78
graphics.bold = true
for i = 1 to 5
graphics.forecolor = rgb(rnd *255,rnd *255,rnd *255)
graphics.DrawString (str(i), x, y,100 )
x = x + 40
next iNext draw an oval on a canvas in a loop in a timer. Make it move across the canvas.
Loop 5)ballX and ballY are both integer properties
When declaring them as properties initialize ballX to 10 and ballY to 0
dim i as integer
g.ForeColor =rgb(255,0,0)
ballY= (me.Height/2)-50
for i=0 to 50
g.drawOval(ballX,ballY, 50,50)
g.fillOval(ballX, ballY, 50,50)'Your assignment is to add code to move the ball horizontially
next iLoop 6)
- Add a Timer to your Window, and move the above code from the Canvas Paint method to the Timer Action method
- Now that you have changed your context from the Canvas class to the Timer class you need to Change g to graphics and change me to Canvas1
- Change your for loop to 0 to 5
- Clear the Canvas so the ball doesn't look like one big blob/ Look in Language reference for the correct command
- Once you have the ball moving horizontally now make the ball bounce around the canvas
**************************************************************************************************************************
Stick Figure Assignment
Name the REALbasic file YourfirstNameStick.rbp and firstNameStick.exe (REMEMBER NO SPACES)
Out of 100 point
Technical Accuracy - 50 points
- the files is in REALbasic/Graphics folder on the network (H) drive - 5 points
- the file names is as directed with no spaces - 5 points
- there are two files firstNameStick.rbp and firstNameStick.exe - 10 points
- at a mininum the parts of the body are clearly commented - 5 points
- Both your programs work - 10 points
- The legs, arms and legs are aligned properly -5 points
- Used a loop - 5 points
- Used a rnd - 5 points
Stick figure walks - 85 points
- Stick figure walks across the room - 20 points
- Stick figures arms and or legs move -15 points
Stick figure Extras up to 15 points
- Stick figure hits the wall and starts again or better yet turns around
- Good use of color
- Extra, Extra Points - If use sound code and the figure dances at least a little to the music
- Surprise me!
Thanks to Mark Sobkowicz at Lincoln Sudbury Regional High School