Download presentation
Presentation is loading. Please wait.
Published byCameron Short Modified over 9 years ago
1
Loop Pictures Pepper
2
Show a picture in your program Add the picture drawing knowledge – import javalib.worldimages.*; – import java.awt.Color; Create the picture pieces as objects: – Make your shape: WorldImage myCircle = AImage.makeCircle(50,Color.blue, Mode.filled); – Make your background: WorldImage myWorld = AImage.makeRectangle(500,500,Color.yellow, Mode.filled);
3
Simple picture placement Create a new myWorld that is the old myWorld with a picture placed on it given picture, x and y: (get 2 circles on the rectangle with these commands) myWorld = myWorld.place(myCircle, 30,30); myWorld = myWorld.place(myCircle, 100,100);
4
Show method to see the picture See the picture using myWorld.show(); Opens a canvas the size of the picture. Every.show will open a new canvas, so build the picture first, then show once.
5
Looping Use the counting loop to repeatedly place your shape on your background: for (int c = 1; c< 10; c++){ myWorld = myWorld.place(myCircle, c*50,c*50);} Pass c x y 1 1 50 50 2 2 100 100 3 3 150 150 4 4 200 200 5 5 250 250.. 9 9 450 450
6
Make an X In every loop, you want to add: Pass c x y 1 1 450 50 2 2 400 100 3 3 350 150 4 4 300 200 5 5 250 250.. 9 9 50 450 What formula would work for x? What formula would work for y?
7
Make an X for (int x = 1; x< 10; x++){ myWorld = myWorld.place(myCircle, x*50,x*50); myWorld = myWorld.place(myCircle, 500-x*50, x*50); }
8
Adding any image you download To create an image from a file: Download a file into any folder Tell Aimage to use its makeFromFile method to create an image from the path you give it. WorldImage myCircle = AImage.makeFromFile ("C:/Program Files/BlueJ/lib/images/bluej-icon-32.png");
9
File Image Example WorldImage myCircle = AImage.makeFromFile ("C:/Program Files/BlueJ/lib/images/bluej-icon-32.png"); WorldImage myWorld = AImage.makeRectangle(500,500,Color.yellow, Mode.filled); for (int x = 1; x< 10; x++){ myWorld = myWorld.place(myCircle, x*50,x*50); myWorld = myWorld.place(myCircle, 500-x*50, x*50); } myWorld.show(); YOU TRY: Draw a checkerboard of your shapes
10
You now know How to import knowledge into your program – Lib with picture knowledge: javalib.worldimages.* – Lib with color knowledge: java.awt.Color; One way to make shapes show on the screen – Tell Aimage to make a shape – Put it into WorldImage – Place shapes on top of one another – Show them on the screen How to determine a loop pattern in a shape – Analyze the pattern of centers – Determine a formula that fits and uses the counter How to code a loop pattern – For (int c = 1; c <= 9; c++){} How to make a picture you download show on the screen – Tell Aimage to makefromfile
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.