CRE Programming Club - Class 5 Robert Eckstein and Robert Heard.

Slides:



Advertisements
Similar presentations
Microsoft® Small Basic
Advertisements

Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Microsoft® Small Basic
Laboratory Study II October, Java Programming Assignment  Write a program to calculate and output the distance traveled by a car on a tank of.
RAPTOR Syntax and Semantics By Lt Col Schorsch
PHY-102 SAPIntroductory GraphicsSlide 1 Introductory Graphics In this section we will learn how about how to draw graphics on the screen in Java:  Drawing.
Microsoft® Small Basic
Four simple expressions in meta. Data objects Pieces of data in a computer are called objects Today, we’ll talk about four kinds of objects Numbers Pictures.
Copyright 2008 by Pearson Education Building Java Programs Graphics Reading: Supplement 3G.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Four simple expressions in meta. Data objects Pieces of data in a computer are called objects Today, we’ll talk about four kinds of objects Numbers Pictures.
Back to Table of Contents Advanced PowerPoint Techniques Prepared by Pat Samuel WS 445/545 - Feb
Graphics Images – PictureBox control Drawing graphics - Graphics object Multimedia controls PictureBox control Image property – select image Choose how.
Microsoft® Small Basic The Controls Object Estimated time to complete this lesson: 1 hour.
2 What is pyGame? A set of Python modules to make it easier to write games. –home page: –documentation:
CRE Programming Club - Class 7 Robert Eckstein and Robert Heard.
Graphics A graphics program allows you to combine pictures and text in many different ways. Features – General Level Draw graphics Enter Text Common Tools.
Microsoft® Small Basic
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
Hello, little turtles. Hello, little turtles! There are many modules in Python that provide very powerful feature that we can use in our own program.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
CRE Programming Club - Class 4 Robert Eckstein and Robert Heard.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
Lesson 10 Using AutoShapes, WordArt, and Comments Lesson 10 Using AutoShapes, WordArt, and Comments.
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
Loops & Graphics IP 10 Mr. Mellesmoen Recall Earlier we wrote a program listing numbers from 1 – 24 i=1 start: TextWindow.WriteLine(i) i=i+1 If.
1 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold,
Microsoft® Small Basic
CSC 1010 Programming for All Lecture 7 Input, Output & Graphics.
CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)
CRE Programming Club Class #9 Robert Eckstein and Robert Heard.
Lawrence Snyder University of Washington, Seattle © Lawrence Snyder 2004 Drawing pictures … It’s not art, it’s fun.
Microsoft® Small Basic Exploring Shapes Estimated time to complete this lesson: 1 hour.
Introduction to Graphics. Graphical objects To draw pictures, we will use three classes of objects: –DrawingPanel : A window on the screen. –Graphics.
CRE Programming Club - Class 4 Robert Eckstein and Robert Heard.
Paint Tutorial Created February 2006 Start Paint: Start>Programs>Accessories>Paint.
+ This step by step tutorial demonstrates drawing a keyboard illustration using rectangles, grids, move and transform effects.
PyGame - Unit 1 PyGame Unit – – Introduction to PyGame.
3. Drawing Let’s Learn Saengthong School, June – August 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
Topic one text Topic two text Topic three text Topic four text
MOM! Phineas and Ferb are … Aims:
Pixels, Colors and Shapes
Adapted from slides by Marty Stepp and Stuart Reges
Building Java Programs
Building Java Programs
Building Java Programs
9. Drawing Let's Learn Python and Pygame
Microsoft® Small Basic
CSc 110, Spring 2017 Lecture 6: Parameters (cont.) and Graphics
A Tiny Look at the Graphics Window
Basic Graphics Drawing Shapes 1.
Smart Graphic Layout TOPIC statement
Topic one text Topic two text Topic three text Topic four text
Order of Operations Problems
Microsoft® Small Basic
CSc 110, Spring 2018 Lecture 9: Parameters, Graphics and Random
Order of Operations Problems
Microsoft® Small Basic
Warm up: What is your favorite book, movie, or T. V. (Netflix) series
Pictures in 3-D flip book (Intermediate)
Empower Support Freedom Inspire Together
Building Java Programs
Building Java Programs
A Tiny Look at the Graphics Window
Smart Graphic Layout TOPIC statement
Building Java Programs
Building Java Programs
Graphics Reading: Supplement 3G
Presentation transcript:

CRE Programming Club - Class 5 Robert Eckstein and Robert Heard

Subroutines When we write programs, we often want the computer to run certain statements more than once. You can avoid writing the same statements over and over if you use subroutines in your programs. To create a subroutine, you use the Sub keyword, and then you give the subroutine a specific name. You end the subroutine by using the EndSub keyword.

Subroutines Look at the following subroutine named PrintCurrentTime. What does it do? Why would we want to create a subroutine out of it? How can we make this subroutine better (Hint: what if Clock.Minute is less than 10)? Sub PrintCurrentTime TextWindow.WriteLine(Clock.Hour + ”:” + Clock.Minute) EndSub

Subroutines Let’s gain a better understanding of subroutines by writing a couple of them… Sub CalculateArea Answer = Radius * Radius * Math.PI EndSub Sub CalculateCircumference Answer = 2 * Math.PI * Radius EndSub

Import HVW825 While (i < 5) TextWindow.WriteLine("Enter Radius: ") Radius = TextWindow.Read() CalculateArea() TextWindow.WriteLine("Area: " + Answer) CalculateCircumference() TextWindow.WriteLine("Circumference: " + Answer) i = i + 1 EndWhile

Subroutines In this program, we use the CalculateArea() and CalculateCircumference() statements to run (or “call”) the subroutines from any location within the program. If you use subroutines, your programs will be easier to read and understand than if you use Goto statements. In this program, you write the subroutines once, but you can run them from anywhere in the program--as many times as you want!

Subroutines When you instruct the computer to run a subroutine, you use a statement that contains the name of the subroutine followed by a set of open and close parentheses. When you use this type of statement, you are calling the subroutine.

Subroutines and Events - Import XZN263 GraphicsWindow.MouseMove = handleMouseMovement Sub handleMouseMovement TextWindow.writeLine("Mouse is at " + GraphicsWindow.MouseX + "," + GraphicsWindow.MouseY) EndSub

Subroutines and Events This tells the GraphicsWindow object to call the handleMouseMovement() subroutine every time there is a movement of the mouse! You can use this to record the current position of the mouse on the screen, or perhaps to control a character in a game. Note that when you assign a subroutine to an event, you don’t use ()s after the name.

Learning GraphicsWindow Just like we had TextWindow that allowed us to work with text and numbers, Small Basic also provides a GraphicsWindow that we can use to draw things. Let’s begin by displaying the window. GraphicsWindow.Show() When you run this program, you’ll notice that instead of the usual black text window, you get a white window.

GraphicsWindow The GraphicsWindow object allows you to customize its appearance. For example, you can change the title, the background, and the size like this.... GraphicsWindow.BackgroundColor = "SteelBlue" GraphicsWindow.Title = "My Graphics Window" GraphicsWindow.Width = 320 GraphicsWindow.Height = 200 GraphicsWindow.Show()

Drawing Lines - HTZ844 Once we have the GraphicsWindow up, we can draw shapes, text and even pictures on it. Let’s start by drawing some simple shapes. Here’s a program that draws a couple lines on the GraphicsWindow. GraphicsWindow.DrawLine(10, 10, 100, 100) GraphicsWindow.DrawLine(10, 100, 100, 10)

Drawing Lines The first two lines of the program setup the window and the next two lines draw the crisscross lines. The first two numbers that follow DrawLine specify the starting x and y co-ordinates and the other two specify the ending x and y co-ordinates. The co-ordinates (0, 0) start at the top left corner of the window, and increase down and to the right.

Drawing Lines Small Basic allows you to modify the properties of the line, such as the color and its thickness. First, let’s modify the color of the lines...

Drawing Lines - CTB959 GraphicsWindow.PenColor = "Green" GraphicsWindow.DrawLine(10, 10, 100, 100) GraphicsWindow.PenColor = "Gold" GraphicsWindow.DrawLine(10, 100, 100, 10)

Drawing Lines Now, let’s modify the size of the lines too... GraphicsWindow.PenWidth = 10 # Add this line GraphicsWindow.PenColor = "Green" GraphicsWindow.DrawLine(10, 10, 100, 100) GraphicsWindow.PenColor = "Gold" GraphicsWindow.DrawLine(10, 100, 100, 10)

Drawing Lines PenWidth and PenColor modify the pen with which these lines are drawn. They not only affect lines but also any shape that is drawn after the properties are updated. By using the looping statements we learned, we can easily write a program that draws multiple lines with increasing pen thickness.

Drawing Lines - MSC750 GraphicsWindow.BackgroundColor = "Black" GraphicsWindow.Width = 200 GraphicsWindow.Height = 160 GraphicsWindow.PenColor = "Blue" For i = 1 To 10 GraphicsWindow.PenWidth = i GraphicsWindow.DrawLine(20, i*15, 180, i*15) EndFor

Draw and Fill Operations When it comes to drawing shapes, there are usually two types of operations for every shape: draw operations and fill operations. Draw operations draw the outline of the shape using a pen. Fill operations fill in the shape using a brush.

Drawing and Filling - ZJG878 Enter this program and watch what it does... GraphicsWindow.Width = 400 GraphicsWindow.Height = 300 GraphicsWindow.PenColor = "Red" GraphicsWindow.DrawRectangle(20, 20, 90, 60) GraphicsWindow.BrushColor = "Green" GraphicsWindow.FillRectangle(60, 100, 300, 60)

Rectangles To draw or fill a rectangle, you need four numbers. The first two numbers represent the X and Y coordinates for the top left corner of the rectangle. The third number specifies the width of the rectangle. The fourth specifies its height. In fact, the same applies for drawing and filling ellipses....

Drawing Ellipses - HGD349 GraphicsWindow.Width = 400 GraphicsWindow.Height = 300 GraphicsWindow.PenColor = "Red" GraphicsWindow.DrawEllipse(20, 20, 300, 60) GraphicsWindow.BrushColor = "Green" GraphicsWindow.FillEllipse(60, 100, 300, 60)

Ellipses (and Circles) Ellipses are just a general case of circles. If you want to draw circles, you would have to specify the same width and height. It’s helpful to think that there is a box that encloses the circle or the ellipse that defines its shape. The circle/ellipse will expand as much as possible to fill the box.

Drawing Circles GraphicsWindow.Width = 400 GraphicsWindow.Height = 300 GraphicsWindow.PenColor = "Red" GraphicsWindow.DrawEllipse(20, 20, 100, 100) GraphicsWindow.BrushColor = "Green" GraphicsWindow.FillEllipse(100, 100, 100, 100)

Fun with Shapes - CVB460 This program draws 20 rectangles in a loop, with increasing size. GraphicsWindow.BackgroundColor = "Black" GraphicsWindow.PenColor = "LightBlue" GraphicsWindow.Width = 200 GraphicsWindow.Height = 200 For i = 1 To 100 Step 5 GraphicsWindow.DrawRectangle(100-i, 100-i, i*2, i*2) EndFor

Fun with Shapes This next program uses the operation GraphicsWindow.GetRandomColor to set random colors for the brush and then uses Math.GetRandomNumber to set the x and y coordinates for the circles.

Fun with Shapes - ZHN117 GraphicsWindow.BackgroundColor = "Black" For i = 1 To 1000 GraphicsWindow.BrushColor = GraphicsWindow.GetRandomColor() x = Math.GetRandomNumber(640) y = Math.GetRandomNumber(480) GraphicsWindow.FillEllipse(x, y, 10, 10) EndFor

Next Time... We’re going to start learning about arrays and learn more about the GraphicsWindow.