Coder Social home page Coder Social logo

ant-pizza's Introduction

image

This application demonstrates the use of the Triangle Class.

It's designed based on the Circle and Rectangle Classes that were introduced, created, and used in Chapter 6.6. of Kenneth Lambert's book, Fundamentals of Java: AP Computer Science Essentials. The following entry from the book explains why I created the Triangle Class:

"Graphics examples in earlier chapters displayed geometric shapes such as rectangles and ovals by running the corresponding drawing or filling methods of the Graphics class. There are several reasons why it will now be useful to implement each shape as a distinct object with its own methods:

  1. A shape has its own attributes, such as a color, a position, and a size. Defining a class for a shape allows a user to manipulate it by changing its color, position, or size.
  2. Defining shape classes allows us to program with more specific shapes than those implied by the drawing methods of the Graphics class. For example, a circle is a specific type of oval, but we usually think of a circle in terms of its center point and radius rather than a corner point, width, and height. Similar remarks also hold true for triangles and other more complex shapes.
  3. If a shape already knows about its own attributes, it just needs a graphics context in order to display itself. Users can then more easily display shapes by asking them to display them- selves, using a single draw(aGraphicsObject) or fill(aGraphicsObject) method.
  4. Programs that use multiple shapes in complex arrangements can more easily compose these and manipulate them by using instances of shape classes."

image

But the truth is that I wanted to be able to do justice (pun intended) to Superman's cape and logo. Instead of using rectangles, I could then draw movable triangle objects.

Design

The Triangle Class is more complicated to implement than both the Rectangle and Circle Classes. Checking to determine if a point clicked is within the shape of the triangle involves the following -- Starting at the point clicked, move right. If you encounter one side of the triangle, then you're inside of it. Zero or more indicates that you're outside of its area. Sounds simple enough, right? Please check out the code.


This was created for College of the Sequoias' (Tulare, CA) COMP 008 - Programming Concepts.

ant-pizza's People

Contributors

racca3141 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.