Linux

Solution : CS 341: Project 3—Go Interfaces two interfaces, geometry and screen, and a color map



For Source Code Contact Me On WhatsApp Or Email
WhatsApp : +923054957063
Email: bilalansar079@gmail.com
Solution
Problem
2.1 Description
You are to create two interfaces, geometry and screen, and a color map. Your program will draw
the geometry (either Rectangle, Circle, or Triangle) on the screen (implemented as a logical
device of type Display).
2.2 Color map
The color map, cmap, maps from Colors (ints) to r,g,b. Note that cmap need not be implemented
as a Go map. The cmap should have colors for red, green, blue, yellow, orange, purple, brown,
black, white.
Use the following colors:
color
R G B
red
green
blue
yellow
255
0
0
0 255 0
0
0 255
255 255
orange 255 164
purple 128
0
0
0 128
brown 165 42 42
black
0
white
0
0
255 255 255
2.3 Geometry
There are three object types which fit the geometry interface are:
1
Rectangle specified by a
• ll lower-left hand corner
• ur upper-right hand corner
• c the color
Circle specified by a
• cp center point
• r radius
• c color
Triangle triangle specified by three points (corners)
• pt1, pt2, pt3 the three points of the triangle
• c the color
Associated with the geometry interface are the methods:
• draw(scn screen) (err error) draw the filled-in shape on the screen
• shape() (s string) print the type of the object
2.4 Screen
Associated with each screen interface is
• initialize(maxX, maxY int) initialize a screen of maxX times maxY. Called before any other
method in screen interface. Clears the screen so that it is all white background.
• getMaxXY() (maxX, maxY int) get the maxX, maxY dimensions of the screen
• drawPixel(x, y int, c Color) (err error) Draw the pixel with color c at location x,y
• getPixel(x, y int) (c Color, err error) Get the color of the pixel at location x,y
• clearScreen() clear the whole screen by setting each pixel to white
• screenShot(f string) (err error) dump the screen as a f.ppm as in project 2. Note that
you must reproduce the form exactly; code was provided in project 2, so you can use that to
generate a sample output. You can then view the graphics output with an image viewer (I
used eog on Linux). Error if the file cannot be written.
2
2.5 Display
A screen is an interface. The underlying type could be a logical device (i.e. data structure) or a
physical display (such as a monitor). We describe here a logical device, which is initialized with
the dimensions of the display and a matrix created with a slice of slices which contains the current
color at each pixel in the display. The Display’s pixels are initialized to be white.
struct Display {
maxX, maxY int
matrix [][]Color
}
The members maxX (respectively maxY) is the size of the screen. For example, a 1024×1024 has valid
x (resp. y) between 0 and 1023.
3 Goprogramming issues
3.1 packages
Use
only
the
pack
ages
fmt,
math,er
rors
3.2 geometry code
andos.

[ad_2]

source

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button