1. Modify the draw() function in the Creature class so that instead of being displayed as a square, the creature is displayed as a triangle.
## A creature draws itself using the colour specified as part of
its dna
## the size of the grid squares, and the position of the top-left
pixel are provided as input
def draw(self, grid_size, top_left_x, top_left_y):
## Compute the position of the top left hand corner of the cell
this creature is in
x = top_left_x + (self.col-1)*grid_size
y = top_left_y - (self.row-1)*grid_size
turtle.color(self.dna[0].split(":")[1])
## Draw the creature
turtle.goto(x, y)
turtle.pendown()
turtle.begin_fill()
turtle.goto(x + grid_size, y)
turtle.goto(x + grid_size, y - grid_size)
turtle.goto(x, y - grid_size)
turtle.goto(x, y)
turtle.end_fill()
turtle.penup()
turtle.color("black")
#code screenshot
#output Screenshot
#code to copy
import turtle def draw(self, grid_size, top_left_x, top_left_y): ## Compute the position of the top left hand corner of the cell this creature is in x = top_left_x y = top_left_y ## Draw the creature self.penup() self.goto(x, y) self.pendown() self.begin_fill() self.left(45) #for triangle move left to 45 self.goto(x + grid_size, y) self.right(45) self.goto(x, y - grid_size) #self.goto(x, y - grid_size) self.right(45) self.goto(x, y) self.end_fill() self.penup() self.color("black") def main(): temp=turtle.Turtle() #myTurle.speed(0) draw(temp,50,10,5) turtle.done() if __name__ == '__main__': main()
1. Modify the draw() function in the Creature class so that instead of being displayed as...
Please write a code in python! Define and test a function named posterize. This function expects an image and a tuple of RGB values as arguments. The function modifies the image like the blackAndWhite function, but it uses the given RGB values instead of black. images.py import tkinter import os, os.path tk = tkinter _root = None class ImageView(tk.Canvas): def __init__(self, image, title = "New Image", autoflush=False): master = tk.Toplevel(_root) master.protocol("WM_DELETE_WINDOW", self.close) tk.Canvas.__init__(self, master, width = image.getWidth(), height = image.getHeight())...
import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.geom.Ellipse2D; public class RedGamePiece extends GamePiece { public RedGamePiece (int row, int col) { super (row, col, Player.RED); } public RedGamePiece (Position pos) { this (pos.r, pos.c); } protected boolean validNonJump (int dr, int dc, GameSquares squares) { if ((dr == -1) && ( (dc == -1) || (dc == 1) )) { if (squares.getSquare(pos.r + dr, pos.c + dc).getPiece() == null) return true; } return false; } protected boolean validJump (int dr,...
python
1
import matplotlib.pyplot as plt
2
import numpy as np
3
4
abscissa = np.arange(20)
5
plt.gca().set_prop_cycle(
’
color
’
, [
’
red
’
,
’
green
’
,
’
blue
’
,
’
black
’
])
6
7
class MyLine:
8
9
def __init__(self,
*
args,
**
options):
10
#TO DO: IMPLEMENT FUNCTION
11
pass
12
13
def draw(self):
14
plt.plot(abscissa,self.line(abscissa))
15
16
def get_line(self):
17
return "y = {0:.2f}x + {1:.2f}".format(self.slope,
self.intercept)
18
19
def __str__(self):...
In traditional Tic Tac Toe game, two players take turns to mark grids with noughts and crosses on the 3 x 3 game board. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row in the game board wins the game. Super Tic Tac Toe game also has a 3 x 3 game board with super grid. Each super grid itself is a traditional Tic Tac Toe board. Winning a game of Tic...
Modify the NervousShapes program so that it displays equilateral
triangles as well as circles and rectangles. You will need to
define a Triangle class containing a single instance variable,
representing the length of one of the triangle’s sides. Have the
program create circles, rectangles, and triangles with equal
probability. Circle and Rectangle is done, please comment on your
methods so i can understand
*/
package NervousShapes;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.swing.*;
import javax.swing.event.*;
public class...
Answer all of these, please
Using Aplia graphs me questions will ask you to interpret a given oraph, and others will require you to manipulate the objects on the graph or even add new required objects,. Each manipulable oblect will be shown in the area to the right of the praph (the palette) and referred to by ts color, object type, and shape of the control points, for example, black point (plus symbol). To place an object on the graph,...
Using Aplia graphs Some questions will ask you to interpret a given graph, and others will require you to manipulate the objects on the graph or even add new required objects. Each manipulable object will be shown in the area to the right of the graph (the palette) and referred to by its color, object type, and shape of the control points, for example, black point (plus symbol). To place an object on the graph, select it from the palette...
import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow for simple graphical drawing on a canvas. * This is a modification of the general purpose Canvas, specially made for * the BlueJ "shapes" example. * * @author: Bruce Quig * @author: Michael Kolling (mik) * Minor changes to canvas dimensions by William Smith 6/4/2012 * * @version: 1.6 (shapes) */ public class Canvas { // Note: The implementation of this class (specifically the...
import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow for simple graphical drawing on a canvas. * This is a modification of the general purpose Canvas, specially made for * the BlueJ "shapes" example. * * @author: Bruce Quig * @author: Michael Kolling (mik) * Minor changes to canvas dimensions by William Smith 6/4/2012 * * @version: 1.6 (shapes) */ public class Canvas { // Note: The implementation of this class (specifically the...
What is the role of polymorphism? Question options: Polymorphism allows a programmer to manipulate objects that share a set of tasks, even though the tasks are executed in different ways. Polymorphism allows a programmer to use a subclass object in place of a superclass object. Polymorphism allows a subclass to override a superclass method by providing a completely new implementation. Polymorphism allows a subclass to extend a superclass method by performing the superclass task plus some additional work. Assume that...