Top Banner
1 Media Software Design DIG 3134 Fall 2012 Lecture 15: Graphics J. Michael Moshell University of Central Florida Original image* by Moshell et al .
17

Media Software Design

Feb 07, 2016

Download

Documents

Rehan

Media Software Design. DIG 3134 Fall 2012 Lecture 15: Graphics J. Michael Moshell University of Central Florida. Original image* by Moshell et al. PHP Graphics. The Coordinate System (for our example). x 800 y 600. Excerpt from DA Text. PHP Graphics. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Media Software Design

1

Media Software Design

DIG 3134Fall 2012

Lecture 15: Graphics

J. Michael MoshellUniversity of Central Florida

Original image* by Moshell et al .

Page 2: Media Software Design

-2 -Excerpt from DA Text

PHP GraphicsThe Coordinate System (for our example)

x 800

y

600

Page 3: Media Software Design

-3 -

PHP GraphicsMotivation: the RSL Pickup Graph

Page 4: Media Software Design

-4 -Excerpt from DA Text

PHP GraphicsThe Coordinate System (for our example)

x 0 800y 0 600

600 0 yup = 600-y (so y=600 – yup)

Page 5: Media Software Design

-5 -Excerpt from DA Text

PHP Graphics: The GD Libraryhttp://php.net/manual/en/ref.image.phpBasic example:$Imagewidth=800;$Imageheight=600;$image=imagecreate($Imagewidth, $Imageheight);$colorWhite=imagecolorallocate($image, 255, 255, 255);$colorGreen=imagecolorallocate($image, 0, 200, 0);

// x1 y1 x2 y2imageline($image, 300, 200, 300,550, $coloGreen); imagepng($image,'graphout.png');imagedestroy($image);print '<img src="graphout.png?lastmod=1">';

Page 6: Media Software Design

-6 -Excerpt from DA Text

PHP Graphics: The GD Libraryhttp://php.net/manual/en/ref.image.phpBasic example:$Imagewidth=800;$Imageheight=600;$image=imagecreate($Imagewidth, $Imageheight);$colorWhite=imagecolorallocate($image, 255, 255, 255);$colorGreen=imagecolorallocate($image, 0, 200, 0);

// x1 y1 x2 y2imageline($image, 300, 200, 300,550, $coloGreen); imagepng($image,'graphout.png');imagedestroy($image);print '<img src="graphout.png?lastmod=1">';

Do this to forcethe browser not to cache

the png file.If it is cached, you

won't see changes ... frustrating.

Page 7: Media Software Design

-7 -Excerpt from DA Text

PHP Graphics: The GD Libraryhttp://php.net/manual/en/ref.image.phpBasic example:$Imagewidth=800;$Imageheight=600;$image=imagecreate($Imagewidth, $Imageheight);$colorWhite=imagecolorallocate($image, 255, 255, 255);$colorGreen=imagecolorallocate($image, 0, 200, 0);

// x1 y1 x2 y2imageline($image, 300, 200, 300,550, $coloGreen); imagepng($image,'graphout.png');imagedestroy($image);print '<img src="graphout.png?lastmod=1">';

Do this to forcethe browser not to cache

the png file.If it is cached, you

won't see changes ... frustrating.NOTE: This sometimes

sorta works

Page 8: Media Software Design

-8 -

markbeam.com

Project 4: Cowpies

Examine the cowpie1 prototype.

BehaviorCode

Examine the Requirements for Project 4

Page 9: Media Software Design

-9 -

Project 4: Cowpies

Requirements BEGIN with a database task:** remember previous moves and replay them.

So we will BEGIN (next week) with a tutorial database examplecalled "address book" to build up your database skills, andalso give you some code to steal / merge with cowpie1.php.

Let's look at one more graphical issue.

Can we write our .png DIRECTLY to browser?

Page 10: Media Software Design

-10 -Excerpt from DA Text

PHP Graphics: The GD LibraryCan we write the

image DIRECTLY tothe browser, instead ofinto a file? Docs saywe can, so we try it.

Page 11: Media Software Design

-11 -Excerpt from DA Text

PHP Graphics: The GD Libraryhttp://php.net/manual/en/ref.image.phpBasic example:$Imagewidth=800;$Imageheight=600;$image=imagecreate($Imagewidth, $Imageheight);$colorWhite=imagecolorallocate($image, 255, 255, 255);$colorGreen=imagecolorallocate($image, 0, 200, 0);

// x1 y1 x2 y2imageline($image, 300, 200, 300,550, $coloGreen); imagepng($image);imagedestroy($image);print '<img src="graphout.png?lastmod=1">';

Can we write theimage DIRECTLY tothe browser, instead ofinto a file? Docs saywe can, so we try it.

Page 12: Media Software Design

-12 -

GD direct to screen: ??

What's this?Any ideas?

Page 13: Media Software Design

-13 -

GD direct to screen: ??

What's this?Any ideas?

View Source

Page 14: Media Software Design

-14 -

GD direct to screen: ??

Once you've announced to the browser that HTML iscoming, it expects HTML.

So what if we tried a different header?

Page 15: Media Software Design

-15 -

So what if we tried a different header?PHP has a header function. We modify cowpie1.php:

function htmlheader(){

print "<html><body><form method='post'>";}//main program$angle=$_POST['angle']; $velocity=$_POST['velocity'];if (!$angle)

htmlheader(); //need HTML first time for formelse

header('Content-type: image/png');

Page 16: Media Software Design

-16 -

Result: yes, it "works" ... but now it's not an HTML formany more, so there are no inputs (controls). It's not interactive.

So ... we're better off embedding png in html.

Page 17: Media Software Design

-17 -

FOR THURSDAY:The usual shoot-out model:GET your Group's BEST GAME ready to play!

If you need help with Project 3, come SEE ME.