raspberry pi gaming 4 kids

43
Raspberry Pi Gaming 4 Kids Stephen Chin (@steveonjava)

Upload: stephen-chin

Post on 15-Jan-2015

10.677 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Raspberry pi gaming 4 kids

Raspberry Pi Gaming 4 KidsStephen Chin (@steveonjava)

Page 2: Raspberry pi gaming 4 kids

What Runs Java?

Page 3: Raspberry pi gaming 4 kids

What Runs Java?

Page 4: Raspberry pi gaming 4 kids

Java and 3G in a Tiny Package

> Cinterion EHS5

Page 5: Raspberry pi gaming 4 kids

Really Tiny…

27.6mm

18.8

mm

Page 6: Raspberry pi gaming 4 kids

http://upload.wikimedia.org/wikipedia/commons/3/3d/Cloud_forest_Ecuador.jpg

Page 7: Raspberry pi gaming 4 kids

=

Have Java With Your DessertRaspberry Pi

Page 8: Raspberry pi gaming 4 kids

Pis are Affordable

$35

Page 9: Raspberry pi gaming 4 kids

Pis are Affordable

$35 1 Box of Diapers

Bicycle(but just 1 wheel)

A Cake

Page 10: Raspberry pi gaming 4 kids

Chalkboard Electronics Touchscreen

10" or 7" Form Factor

Connects via HDMI/USB

Tested with JavaFX 8

10% Exclusive Discount:

G1F0U796Z083

Page 11: Raspberry pi gaming 4 kids

How to Setup Your Pi

> Step 1: Install Linux

> Step 2: Download/Copy Java 8 for ARM EA

> Step 3: Deploy and Run JVM Language Apps

http://steveonjava.com/javafx-on-raspberry-pi-3-easy-steps/

Page 12: Raspberry pi gaming 4 kids

What Comes in Your Lab Kit

1. Touch Screen2. SD Card3. Keyboard4. Yellow Box:

Power Adapter LVDS Cable/Board Raspberry Pi Model B Mini-USB Cable (power) Micro-USB Cable (keyboard)

Please Save All the Packaging for Later

Page 13: Raspberry pi gaming 4 kids

Electronic Safety!

> Unplug from wall before wiring

> Get rid of static by touching a metal surface

> Don't touch exposed wires/metal

> Never remove/insert SD Card while power is on

13

Page 14: Raspberry pi gaming 4 kids

Hooking Up the Pi (Part A)

1. Insert the SD Card in to the Pi Will appear upside down when looking at the top

of your Pi

2. Insert the HDMI board into the Pi's HDMI jack

3. Connect the Pi power to the HDMI board Use the Micro USB Cable (short one)

14

Important: Connect everything before plugging into the wall

Page 15: Raspberry pi gaming 4 kids

Hooking Up the Pi (Part B)

4. Slide the LCD cable into the back of the display Side with gold connectors goes up Be careful, the connector is fragile!

5. Connect the USB end to one of the Pi's USB host ports

This provides touch input6. Hook up the USB keyboard

1. Use the Mini USB cable (long one)

15

Verify connections and plug into power now

Page 16: Raspberry pi gaming 4 kids

Is it Working?

> Should get a bunch of flashing LEDs to indicate booting Boot takes approx 30 seconds

> The LCD screen should light up Might be dim if the light sensor is obstructed

> And you will should see a Linux boot screen with lots of text

Hacking Time!

Page 17: Raspberry pi gaming 4 kids

Logging In

At the login prompt type your username:> piAnd enter the password:> raspberry

Page 18: Raspberry pi gaming 4 kids

Running Your First Application

Change directory to the project folder> cd MaryHadALittleLambdaRun the build script> ant

Page 19: Raspberry pi gaming 4 kids

19

Page 20: Raspberry pi gaming 4 kids

Hacking the Code

Run the nano text editor:> nano src/sample/MapObject.javaSave your changes:> Control-O EnterExit Nano:> Control-XCompile/Run:> ant

Page 21: Raspberry pi gaming 4 kids

Mary Had a Little Lambda

Mary had a little lambdaWhose fleece was white as snowAnd everywhere that Mary wentLambda was sure to go!

https://github.com/steveonjava/MaryHadALittleLambda

Page 22: Raspberry pi gaming 4 kids

Generating Streams

From a collection:> anyCollection.stream();Known set of objects:> Stream.of("bananas", "oranges", "apples");Numeric range:> IntStream.range(0, 50)Iteratively:> Stream.iterate(Color.RED, > c -> Color.hsb(c.getHue() + .1, c.getSaturation(), > c.getBrightness())); 22

Page 23: Raspberry pi gaming 4 kids

Let's Create Some Barn Animals!

SpriteView tail = s.getAnimals().isEmpty() ? s : s.getAnimals().get(s.getAnimals().size() - 1);

Stream.iterate(tail, SpriteView.Lamb::new) .substream(1, 8) .forEach(s.getAnimals()::add);

23

Page 24: Raspberry pi gaming 4 kids

24

Page 25: Raspberry pi gaming 4 kids

Filtering Streams

Predicate Expression> public interface Predicate<T> {> public boolean test(T t);> }

Filter out minors> adults = attendees.filter(a -> a.getAge() >= 1.8)

25

Page 26: Raspberry pi gaming 4 kids

Rainbow-colored Lambs!

s.getAnimals().stream() .filter(a -> a.getNumber() % 4 == 2) .forEach(a -> a.setColor(Color.YELLOW));s.getAnimals().stream() .filter(a -> a.getNumber() % 4 == 3) .forEach(a -> a.setColor(Color.CYAN));s.getAnimals().stream() .filter(a -> a.getNumber() % 4 == 0) .forEach(a -> a.setColor(Color.GREEN));

26

Page 27: Raspberry pi gaming 4 kids

27

Page 28: Raspberry pi gaming 4 kids

Filtering Collections

Collection.removeIf> Removes all elements that match the predicateList.replaceAll> In-place filtering and replacement using an unary operator

ObservableCollection.filtered> Returns a list filtered by a predicate this is also Observable

28

Page 29: Raspberry pi gaming 4 kids

Picky Eaters…

Predicate<SpriteView> pure = a -> a.getColor() == null;

mealsServed.set(mealsServed.get() + s.getAnimals().filtered(pure).size());

s.getAnimals().removeIf(pure);

29

Page 30: Raspberry pi gaming 4 kids

30

Page 31: Raspberry pi gaming 4 kids

Mapping Streams

Applies a Map Function to each element:> Function<? super T, ? extends R>

Result: List is the same size, but may be a different type.

31

Page 32: Raspberry pi gaming 4 kids

Single Map

s.getAnimals().setAll(s.getAnimals() .stream() .map(sv -> new Eggs(sv.getFollowing()) .collect(Collectors.toList()));

32

Page 33: Raspberry pi gaming 4 kids

Or a Double Map!

s.getAnimals().setAll(s.getAnimals() .stream() .map(SpriteView::getFollowing) .map(Eggs::new) .collect(Collectors.toList()));

33

Page 34: Raspberry pi gaming 4 kids

34

Page 35: Raspberry pi gaming 4 kids

Flat Map

Applies a One-to-Many Map Function to each element:> Function<? super T, ? extends Stream<? extends R>>And then flattens the result into a single stream.

Result: The list may get longer and the type may be different.

35

Page 36: Raspberry pi gaming 4 kids

Hatching Eggs

s.getAnimals().setAll(s.getAnimals() .stream() .flatMap(SpriteView.Eggs::hatch) .collect(Collectors.toList()));

36

Page 37: Raspberry pi gaming 4 kids

37

Page 38: Raspberry pi gaming 4 kids

Reduce

Reduces a list to a single element given:> Identity: T> Accumulator: BinaryOperator<T>

Result: List of the same type, but only 1 element left.

38

Page 39: Raspberry pi gaming 4 kids

And the (formerly little) Fox ate them all!

Double mealSize = shepherd.getAnimals() .stream() .map(SpriteView::getScaleX) .reduce(0.0, Double::sum);

setScaleX(getScaleX() + mealSize * .2);setScaleY(getScaleY() + mealSize * .2);shepherd.getAnimals().clear();

39

Page 40: Raspberry pi gaming 4 kids

40

Page 41: Raspberry pi gaming 4 kids

Mary Had a Little Lambda Project

> Open-source project to demonstrate lambda features> Visual representation of streams, filters, and maps

41

https://github.com/steveonjava/MaryHadALittleLambda

Page 42: Raspberry pi gaming 4 kids

Stephen Chin (@steveonjava)http://steveonjava.com/

nighthacking.com

Real GeeksLive Hacking

NightHacking Tour

Page 43: Raspberry pi gaming 4 kids

Safe Harbor Statement

The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.