CADjs Warnings, Errors, Comments and Variable Naming.

Slides:



Advertisements
Similar presentations
Bending Zen Intro Using Zen Themes functionality, but bending it into your own theme.
Advertisements

Matlab Intro Simple introduction to some basic Matlab syntax. Declaration of a variable [ ] Matrices or vectors Some special (useful) syntax. Control statements.
Detecting Bugs Using Assertions Ben Scribner. Defining the Problem  Bugs exist  Unexpected errors happen Hardware failures Loss of data Data may exist.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Images. PImage class PImage is a class for loading and displaying an image in Processing. Declare a PImage type: PImage img; Make a new instance by loading.
Introduction to HTML Lists, Images, and Links. Before We Begin Save another file in Notepad Save another file in Notepad Open your HTML, then do File>Save.
Chapter 8 and 9 Review: Logical Functions and Control Structures Introduction to MATLAB 7 Engineering 161.
Lesson 4: Basic Algorithm Tools If, While Do For Loop, Else, Switch Case.
CS 177 Recitation Week 8 – Methods. Questions? Announcements  Project 3 milestone due next Thursday 10/22 9pm  Turn in with: turnin –c cs177=xxxx –p.
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
Programming in MATLAB Week 14 – 4/28/09 Kate Musgrave
ENGR 111A - Spring MatLab – Palm Chapter 4, Part 4 Review and Debugging Class 12.1: Palm Chapters &
Internet Publishing / Dreamweaver Luke E. Reese CARRS
Chapter 5: Control Structures II (Repetition)
Information Technology Services North Dakota State University Lorna Olsen Get the Best Digital Images Possible What’s it all about anyway?
UV Mapping. Purpose UV mapping is a process of applying textures to an object by hand.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Control Structures, Operators, and Functions.
The switch StatementtMyn1 The switch Statement Sometimes there can be a multiple-choice situation, in which you need to execute a particular set of statements.
Unit E. Image Measurements The size of an image can be measured 2 ways: Dimensions: the height and width, measured in pixels. File Size: measured in Kilobytes.
Amber Annett David Bell October 13 th, What will happen What is this business about personal web pages? Designated location of your own web page.
Fall 2006AE6382 Design Computing1 OOP: Creating a Class More OOP concepts An example that creates a ASSET class and shows how it might be used Extend the.
General Programming Introduction to Computing Science and Programming I.
Images Inserting an image on a web page. chcslonline.org2 ITEMS REQUIRED Go to the course download page on the course website and download the 3 images.
Images in HTML PowerPoint How images are used in HTML.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 2 HTML TAGS G H E F.
Images, Links, and Multimedia. Directories and Pathnames.
Introduction to PHP – Chapter 8 Working with PHP.
Chapter 12 FRAMES. HOW FRAMES WORK When you view a framed page in a browser, you are actually looking at several HTML documents at once. The key to making.
Introduction to Applets CS 3505 Client Side Scripting with applets.
Multi-Part Requests/ Parent & Child Service Items.
Cascading Style Sheets: Got Branding?. What is CSS? CSS = Cascading Style Sheets Styles define how HTML (web) elements are displayed. One (or more) style.
A Basic Web Page. Chapter 2 Objectives HTML tags and elements Create a simple Web Page XHTML Line breaks and Paragraph divisions Basic HTML elements.
GUI development with Matlab: GUI Front Panel Components 1 GUI front panel components In this section, we will look at -GUI front panel components -Programming.
COIT29222 Structured Programming Slide 1 COIT29222-Structured Programming Lecture Week 06  Reading: Study Guide Book 2, Modules 9 & 10 Textbook (4 th.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 6 Functions.
1 Session 3: Flow Control & Functions iNET Academy Open Source Web Programming.
CMPS 1371 Introduction to Computing for Engineers MatLab.
HTML Table and PHP Array
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
Making Good Code AKA: So, You Wrote Some Code. Now What? Ray Haggerty July 23, 2015.
Peer Edit with Perfection! Tutorial. Peer Editing is Fun! Working with your classmates to help improve their writing can be lots of fun. But first, you.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)Graphics.
CST336, Spring 2015 Week 8: PHP File Upload. PHP provides specific functions to handle binary data such as uploading a file into the server, storing it.
GUI development with Matlab: GUI Front Panel Components GUI development with Matlab: Other GUI Components 1 Other GUI components In this section, we will.
From CADjs to 3-D Printing. Area & Volume g = cube(1); g.display(); Area? Volume? g = cube(1); g.display(); g.info();
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 6 Functions.
Starting Out with C++ Early Objects ~~ 7 th Edition by Tony Gaddis, Judy Walters, Godfrey Muganda Modified for CMPS 1044 Midwestern State University 6-1.
CreatingClasses-SlideShow-part41 Creating Classes part 4 Barb Ericson Georgia Institute of Technology Dec 2009.
Dreamweaver MX. 2 Tools for Code Editing (p. 366) n An HTML editor like Dreamweaver writes most of the code you need, but at times you will need to perform.
CADjs Primitives and Booleans. 3D Solids There are 6 primitives that CADjs supports That is all you will need to create complex shapes.
Internet Publishing / Dreamweaver Luke E. Reese Biosystems & Ag. Engr. / CARRS
Printable Programming. Instructors Krishnan Suresh Associate Professor Mechanical Engineering UW Madison Victor Markus Undergraduate Student (senior)
CADjs Cloning and for loops. wheel, hub and spoke assembly g1 = cube(5); g2=cylinder(1,20); g3=cylinder(1,20); g4=cylinder(20,2); g5=cylinder(10,2); g2.rotateX(90);
Matlab for Engineers Matlab Environment Chapter 2.
Creating FunctionstMyn1 Creating Functions Function can be divided into two groups: –Internal (built in) functions –User-defined functions.
WEB GRAPHICS EXPLORING COMPUTER SCIENCE - LESSON 3-4.
Program Flow Control Addis Ababa Institute of Technology Yared Semu April 2012.
Engr 0012 (04-1) LecNotes Engr 0012 (04-1) LecNotes Contrasting MATLAB with C MATLABC language Workspace - interactive computation No real.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Unit 7 How to Upload Files. A very useful aspect of PHP is its ability to manage file uploads to your server. Before you can use PHP to manage your uploads,
Flow Control. Comments u Comments: /* This is a comment */ –Use them! –Comments should explain: v special cases v the use of functions (parameters, return.
XHTML/CSS Week 2. This Week  Quiz to revise last week (XHTML and DW)  Lists - & tags  Images tag  Hyperlinks tag  Using CSS to define the appearance.
Week 3-4 Control flow (review) Function definition Program Structures
Images in HTML PowerPoint How images are used in HTML
From CADjs to 3-D Printing
MSIS 655 Advanced Business Applications Programming
Coding Concepts (Basics)
Adding Intelligence Check for the presence or absence of a condition in the environment Take the appropriate actions Involves making a choice (to do or.
Images in HTML PowerPoint How images are used in HTML
Presentation transcript:

CADjs Warnings, Errors, Comments and Variable Naming

CADjs Warnings Missing semi-colon Warning No warnings Missing “.” Missing “)”

CADjs Errors No warnings Misnamed function No warnings Bad choice for variable

Cluttered Code "w" => "[0-9]+%?", "h" => "[0-9]+%?", "x" => "[0-9]+", "y" => "[0-9]+", "t" => "jpg|png", "q" => "1?[0-9]{1,2}" ); // check tags and save correct values in array for ($i=0; $i if (isset($check[$matches[$i][2]])) { if (preg_match('/^('.$check[$matches[$i][2]].')$/', $matches[$i][3])) { $tags[$matches[$i][2]] = $matches[$i][3]; } } } function notfound() { header("HTTP/ Not Found"); exit; } // check that filename is given if (!isset($tags["f"])) { notfound(); } // check if file exists if (!file_exists($base_img_dir.$tags["f"])) { notfound(); } // retrieve file info $imginfo = getimagesize($base_img_dir.$tags["f"]); // load image switch ($imginfo[2]) { case 2: // jpg $img_in = imagecreatefromjpeg($base_img_dir.$tags["f"]) or notfound(); if (!isset($tags["t"])) { $tags["t"] = "jpg"; } break; case 3: // png $img_in = imagecreatefrompng($base_img_dir.$tags["f"]) or notfound(); if (!isset($tags["t"])) { $tags["t"] = "png"; } break; default: notfound(); } // check for maximum width and height if (isset($tags["x"])) { if ($tags["x"] < imagesx($img_in)) { $tags["w"] = $tags["x"]; } } if (isset($tags["y"])) { if ($tags["y"] < imagesy($img_in)) { $tags["h"] = $tags["y"]; } } // check for need to resize if (isset($tags["h"]) or isset($tags["w"])) { // convert relative to absolute if (isset($tags["w"])) { if (strstr($tags["w"], "%")) { $tags["w"] = (intval(substr($tags["w"], 0, -1)) / 100) * $imginfo[0]; } } if (isset($tags["h"])) { if (strstr($tags["h"], "%")) { $tags["h"] = (intval(substr($tags["h"], 0, -1)) / 100) * $imginfo[1]; } } // resize if (isset($tags["w"]) and isset($tags["h"])) { $out_w = $tags["w"]; $out_h = $tags["h"]; } elseif (isset($tags["w"]) and !isset($tags["h"])) { $out_w = $tags["w"]; $out_h = $imginfo[1] * ($tags["w"] / $imginfo[0]); } elseif (!isset($tags["w"]) and isset($tags["h"])) { $out_w = $imginfo[0] * ($tags["h"] / $imginfo[1]); $out_h = $tags["h"]; } else { $out_w = $tags["w"]; $out_h = $tags["h"]; } // new image in $img_out $img_out = imagecreate($out_w, $out_h); imagecopyresized($img_out, $img_in, 0, 0, 0, 0, imagesx($img_out), imagesy($img_out), imagesx($img_in), imagesy($img_in)); } else { // no resize needed $img_out = $img_in; } // check for a given jpeg-quality, otherwise set to default if (!isset($tags["q"])) { $tags["q"] = 75; } // returning the image switch ($tags["t"]) { case "jpg": header("Content-type: image/jpeg"); imagejpeg($img_out, "", $tags["q"]); exit; case "png": header("Content-type: image/png"); imagepng($img_out); exit; default: notfound(); Cluttered code got you down?

Motivation Comments and good variable names can:  Make your code easier to follow  Allow you to more easily edit your code

Variable Names Example: Simple Cylinder g = cylinder(1,2,32); g.display(); This code works perfectly well BUT numbers like 1,2 and 32 have no meaning.

Variable Names To give the numbers meaning, we will name them “radius,” “height” and “quality” Example: Simple Cylinder Cont. radius = 1; height = 2; quality = 32 g = cylinder(radius,height,quality); g.display();

Variable Names Good Variable Name Practice  Name all variables  Create variable names which make sense to you and those reading your code  Create number specific names such as cube1, cube2, etc.  Avoid using function names like cube, cylinder, sphere etc.

Comments Purpose of Comments  Adds clarity to your code  Allows you to look up lines of code easily To add a comment:  Simply add // after your code  Follow this by your comment  Comments do not affect the actual code

Comments Example: Simple Cylinder radius = 1.0; //radius of cylinder height = 2.0; //height of cylinder g = cylinder(radius,height,32); //creates cylinder g g.display(); //displays cube Good Comment Practice Keep your comments short and to the point Comment any line which needs clarity

Exercise 1: Mug

Try and remake the following code but replace all of the numbers with variable names and add comments where you feel necessary. cylinder1 = cylinder(1,2,32); cylinder2 = cylinder(0.9,2,32).translateY(0.2); cube1 = cube(0.2,1.5,0.2).translateX(2); cube2 = cube(1,0.2,0.2).translate(1.5,0.65,0); cube3 = cube(1,0.2,0.2).translate(1.5,-0.65,0); cylinder1.difference(cylinder2).display(); cube1.display(); cube2.display(); cube3.display(); Exercise 1: Mug

Exercise 2: Frosty the Snowman

Try and remake the following code but replace all of the numbers with variable names and add comments where you feel necessary. cube1 = cube(5,0.1,5); sphere1 = sphere(1).translateY(1); sphere2 = sphere(0.75).translateY(2.5); sphere3 = sphere(0.5).translateY(3.6); cube2 = cube(3,0.1,0.1).translateY(2.5); cylinder1 = cylinder(0.4,0.7).translateY(4.4); cylinder2 = cylinder(0.5,0.1).translateY(4); cube1.display(); cube2.display(); sphere1.display(); sphere2.display(); sphere3.display(); cylinder1.display(); cylinder2.display(); Exercise 2: Frosty the Snowman