def render_shape_to_graphics(self, shape):
        r = shape.getShapeRenderer()

        # Find the size that the shape will be rendered to at the specified scale and resolution.
        shapeSizeInPixels = r.getSizeInPixels(1.0, 96.0)

        # Rotating the shape may result in clipping as the image canvas is too small. Find the longest side
        # and make sure that the graphics canvas is large enough to compensate for this.
        maxSide = Math.max(shapeSizeInPixels.width, shapeSizeInPixels.height)

        image = BufferedImage(int(maxSide * 1.25), int(maxSide * 1.25), BufferedImage.TYPE_INT_ARGB)

        # Rendering to a graphics object means we can specify settings and transformations to be applied to
        # the shape that is rendered. In our case we will rotate the rendered shape.
        gr = image.getGraphics()

        # Clear the shape with the background color of the document.
        gr.setBackground(shape.getDocument().getPageColor())
        gr.clearRect(0, 0, image.getWidth(), image.getHeight())
        # Center the rotation using translation method below
        gr.translate(image.getWidth() / 8, image.getHeight() / 2)
        # Rotate the image by 45 degrees.
        gr.rotate(45 * Math.PI / 180)
        # Undo the translation.
        gr.translate(-image.getWidth() / 8, -image.getHeight() / 2)

        # Render the shape onto the graphics object.
        r.renderToSize(gr, 0, 0, shapeSizeInPixels.width, shapeSizeInPixels.height)

        ImageIO.write(image, "png", File(self.dataDir + "TestFile.RenderToGraphics.png"))

        gr.dispose()

        print "Shape rendered to Graphics successfully."
Exemple #2
0
 def setValue(self, value):
     if value == "":
         img = BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)
         g = img.getGraphics()
         g.setColor(Color.RED)
         g.fillOval(2, 2, 10, 10)
         self.setIcon(ImageIcon(img))
     else:
         self.setIcon(value)
Exemple #3
0
 def setValue(self, value):
     if value == "":
         img = BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)
         g = img.getGraphics()
         g.setColor(Color.RED)
         g.fillOval(2, 2, 10, 10)
         self.setIcon(ImageIcon(img))
     else:
         self.setIcon(value)
Exemple #4
0
 def getIcon(self):
     """Set the layer icon.
     """
     if self.iconf is not None:
         return self.iconf
     else:
         img = BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)
         g = img.getGraphics()
         g.setColor(Color.RED)
         g.fillOval(2, 2, 10, 10)
         return ImageIcon(img)
    def find_shape_sizes(self, shape):
        shapeSizeInDocument = shape.getShapeRenderer().getSizeInPoints()
        width = shapeSizeInDocument.x # The width of the shape.
        height = shapeSizeInDocument.y # The height of the shape.
        shapeRenderedSize = shape.getShapeRenderer().getSizeInPixels(1.0, 96.0)

        image = BufferedImage(shapeRenderedSize.width, shapeRenderedSize.height, BufferedImage.TYPE_INT_RGB)

        gr = image.getGraphics()

        # Render shape onto the graphics object using the RenderToScale or RenderToSize methods of ShapeRenderer class.

        gr.dispose()
    def find_shape_sizes(self, shape):
        shapeSizeInDocument = shape.getShapeRenderer().getSizeInPoints()
        width = shapeSizeInDocument.x  # The width of the shape.
        height = shapeSizeInDocument.y  # The height of the shape.
        shapeRenderedSize = shape.getShapeRenderer().getSizeInPixels(1.0, 96.0)

        image = BufferedImage(shapeRenderedSize.width,
                              shapeRenderedSize.height,
                              BufferedImage.TYPE_INT_RGB)

        gr = image.getGraphics()

        # Render shape onto the graphics object using the RenderToScale or RenderToSize methods of ShapeRenderer class.

        gr.dispose()
Exemple #7
0
class PanTool(Tool) :
	def __init__(self, clientState = None) :
		self.client_state = clientState
		self.start_point = None
		self.makeImage()
	def makeImage(self) :
		self.image = BufferedImage(32,32,BufferedImage.TYPE_INT_ARGB)
		g = self.image.getGraphics()
		g.setColor(Color(0,0,0))
		g.drawLine(16,0,16,32)
		g.drawLine(0,16,32,16)
		g.drawLine(16,0,10,6)
		g.drawLine(16,0,22,6)
		g.drawLine(0,16,6,10)
		g.drawLine(0,16,6,22)
		g.drawLine(16,32,10,26)
		g.drawLine(16,32,22,26)
		g.drawLine(32,16,26,10)
		g.drawLine(32,16,26,22)
	def mousePressed(self, locationOnScreen, g) :
		self.last_point = locationOnScreen
		return ""
	def mouseHovered(self, locationOnScreen, g) :
		return ""
	def mouseDragged(self, locationOnScreen, g) :
		dx = -(locationOnScreen.x - self.last_point.x)
		dy = -(locationOnScreen.y - self.last_point.y)
		self.last_point = locationOnScreen
		return "%d,%d" % (dx, dy)
	def mouseReleased(self, locationOnScreen, g) :
		dx = -(locationOnScreen.x - self.last_point.x)
		dy = -(locationOnScreen.y - self.last_point.y)
		self.last_point = None
		return "%d,%d" % (dx, dy)
	def draw(self, s, g) :
		return None
	def getIcon(self) :
		return self.image
	def getToolName(self) :
		return "Pan"
	def getTooltip(self) :
		return "move to a new section of the canvas defined by the starting point and the point at which the mouse was released"
	def getToolID(self) :
		return 'pan'
Exemple #8
0
 def image(self):
     w = self.getWidth();
     h = self.getHeight();
     non_black_withe_image = BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB)
     self.paint(non_black_withe_image.getGraphics())
     raster=non_black_withe_image.getRaster()
     bi = BufferedImage(w, h, BufferedImage.TYPE_BYTE_BINARY)
     write_raster = bi.getRaster()
     c = array.zeros('i', 4)
     on=wc = array.zeros('i', 1)
     off=array.zeros('i', 1)
     off[0]=1
     for x in range(w):
         for y in range(h):
             c = raster.getPixel(x,y,c)
             if sum(c)!=1020:
                 write_raster.setPixel(x,y, on)
             else:
                 write_raster.setPixel(x,y, off)
     return bi;
Exemple #9
0
 def image(self):
     w = self.getWidth()
     h = self.getHeight()
     non_black_withe_image = BufferedImage(w, h,
                                           BufferedImage.TYPE_INT_ARGB)
     self.paint(non_black_withe_image.getGraphics())
     raster = non_black_withe_image.getRaster()
     bi = BufferedImage(w, h, BufferedImage.TYPE_BYTE_BINARY)
     write_raster = bi.getRaster()
     c = array.zeros('i', 4)
     on = wc = array.zeros('i', 1)
     off = array.zeros('i', 1)
     off[0] = 1
     for x in range(w):
         for y in range(h):
             c = raster.getPixel(x, y, c)
             if sum(c) != 1020:
                 write_raster.setPixel(x, y, on)
             else:
                 write_raster.setPixel(x, y, off)
     return bi
Exemple #10
0
 def getListCellRendererComponent(self, list_, value, index, isSelected, cellHasFocus):
     """ generated source for method getListCellRendererComponent """
     setHorizontalAlignment(JLabel.LEFT)
     if isSelected:
         setBackground(list_.getSelectionBackground())
         setForeground(list_.getSelectionForeground())
     else:
         setBackground(list_.getBackground())
         setForeground(list_.getForeground())
     if value == None:
         return self
     presence = self.thePresenceManager.getPresence(value.__str__())
     status = presence.getStatus()
     if status != None:
         status = status.lower()
     iconSize = 20
     img = BufferedImage(iconSize, iconSize, BufferedImage.TYPE_INT_RGB)
     g = img.getGraphics()
     g.setColor(getBackground())
     g.fillRect(0, 0, iconSize, iconSize)
     if status == None:
         g.setColor(Color.GRAY)
     elif status == "available":
         g.setColor(Color.GREEN)
     elif status == "busy":
         g.setColor(Color.ORANGE)
     elif status == "error":
         g.setColor(Color.BLACK)
     else:
         g.setColor(Color.MAGENTA)
     g.fillOval(3, 3, iconSize - 6, iconSize - 6)
     textLabel = presence.getHost() + ":" + presence.getPort()
     if presence.__name__ != None:
         textLabel = presence.__name__ + " (" + textLabel + ")"
     if self.maxLabelLength > len(textLabel):
         textLabel = textLabel.substring(0, self.maxLabelLength - 3) + "..."
     setIcon(ImageIcon(img))
     setText(textLabel)
     setFont(list_.getFont())
     return self
    def render_shape_to_graphics(self, shape):
        r = shape.getShapeRenderer()

        # Find the size that the shape will be rendered to at the specified scale and resolution.
        shapeSizeInPixels = r.getSizeInPixels(1.0, 96.0)

        # Rotating the shape may result in clipping as the image canvas is too small. Find the longest side
        # and make sure that the graphics canvas is large enough to compensate for this.
        maxSide = Math.max(shapeSizeInPixels.width, shapeSizeInPixels.height)

        image = BufferedImage(int(maxSide * 1.25), int(maxSide * 1.25),
                              BufferedImage.TYPE_INT_ARGB)

        # Rendering to a graphics object means we can specify settings and transformations to be applied to
        # the shape that is rendered. In our case we will rotate the rendered shape.
        gr = image.getGraphics()

        # Clear the shape with the background color of the document.
        gr.setBackground(shape.getDocument().getPageColor())
        gr.clearRect(0, 0, image.getWidth(), image.getHeight())
        # Center the rotation using translation method below
        gr.translate(image.getWidth() / 8, image.getHeight() / 2)
        # Rotate the image by 45 degrees.
        gr.rotate(45 * Math.PI / 180)
        # Undo the translation.
        gr.translate(-image.getWidth() / 8, -image.getHeight() / 2)

        # Render the shape onto the graphics object.
        r.renderToSize(gr, 0, 0, shapeSizeInPixels.width,
                       shapeSizeInPixels.height)

        ImageIO.write(image, "png",
                      File(self.dataDir + "TestFile.RenderToGraphics.png"))

        gr.dispose()

        print "Shape rendered to Graphics successfully."
def _create_buffered_image(image):
    result = BufferedImage(image.getWidth(None),image.getHeight(None),BufferedImage.TYPE_INT_ARGB)
    result.getGraphics().drawImage(image,0,0,None)
    return result
Exemple #13
0
class FilledOvalTool(Tool) :
	def __init__(self, clientState = None) :
		self.client_state = clientState
		self.start_point = None
		self.makeImage()
	def makeImage(self) :
		self.image = BufferedImage(32,32,BufferedImage.TYPE_INT_ARGB)
		g = self.image.getGraphics()
		g.setColor(Color(0,0,0))
		g.fillOval(0,0,30,30)
	def mousePressed(self, locationOnScreen, g) :
		self.start_point = locationOnScreen
		return ""
	def mouseHovered(self, locationOnScreen, g) :
		return ""
	def mouseDragged(self, locationOnScreen, g) :
		x1 = min(self.start_point.x, locationOnScreen.x)
		y1 = min(self.start_point.y, locationOnScreen.y)
		x2 = max(self.start_point.x, locationOnScreen.x)
		y2 = max(self.start_point.y, locationOnScreen.y)
		g.setColor(self.client_state.selectedColor)		
		g.fillOval(x1, y1, x2 - x1, y2 - y1)
		return ""
	def mouseReleased(self, locationOnScreen, g) :
		x1 = min(self.start_point.x, locationOnScreen.x)
		y1 = min(self.start_point.y, locationOnScreen.y)
		x2 = max(self.start_point.x, locationOnScreen.x)
		y2 = max(self.start_point.y, locationOnScreen.y)
		return self._getmetadata() + "|" + "(%d,%d);(%d,%d) " % (x1, y1, x2 - x1, y2 - y1)		
	def _getmetadata(self) :
		return "%d" % self.client_state.selectedColor.getRGB()
	def draw(self, s, g) :
		if s == "" :
			return
		metadata, points = s.split('|')
		points = points.split(';')
		g.setColor(Color(int(metadata)))
		match = point_re.match(points[0])
		if match is None:
			return
		x1, y1 = match.groups()
		x1, y1 = int(x1), int(y1)
		match = point_re.match(points[1])
		if match is None:
			return
		x2, y2 = match.groups()
		x2, y2 = int(x2), int(y2)
		g.fillOval(x1, y1, x2, y2)
	def getAffectedArea(self, phrase) :
		points = phrase.split('|')[1].split(';')
		match = point_re.match(points[0])
		if match is None:
			return
		x1, y1 = match.groups()
		x1, y1 = int(x1), int(y1)
		match = point_re.match(points[1])
		if match is None:
			return
		x2, y2 = match.groups()
		x2, y2 = int(x2), int(y2)
		ax1 = min(x1, x2)
		ay1 = min(y1, y2)
		ax2 = max(x1, x2)
		ay2 = max(y1, y2)
		return [ax1, ay1, ax2 - ax1, ay2 - ay1]
	def getIcon(self) :
		return self.image
	def getToolName(self) :
		return "FilledOval"
	def getTooltip(self) :
		return "draw a Filled Oval inscribed in the imaginary rectagle with one corner\nwhere you click and another\ncorner where you release the mouse"
	def getToolID(self) :
		return 'filledoval'	
Exemple #14
0
class PencilTool(Tool) :
	def __init__(self, clientState=None) :
		self.client_state = clientState
		self.prev_point_draw = None
		self.makeImage()
	def makeImage(self) :
		self.image = BufferedImage(32,32,BufferedImage.TYPE_INT_ARGB)
		g = self.image.getGraphics()
		g.setColor(Color(209,149,12))
		g.drawLine(20,0,0,25)
		g.drawLine(25,0,5,25)
		g.drawLine(25,0,27,5)
		g.drawLine(20,0,25,0)
		g.drawLine(27,5,8,27)
		g.setColor(Color(0,0,0))
		g.drawLine(0,25,5,32)
		g.drawLine(5,25,5,32)
		g.drawLine(5,25,0,25)
		g.drawLine(8,27,0,25)
		g.drawLine(8,27,5,32)
	def __repr__(self) :
		return self.getToolName()
	def mousePressed(self, locationOnScreen, g) :
		self.prev_point = locationOnScreen
		self.points = [(locationOnScreen.x, locationOnScreen.y)]
		return ""
	def mouseDragged(self, locationOnScreen, g) :
		x0,y0 = self.prev_point.x, self.prev_point.y
		x1,y1 = locationOnScreen.x, locationOnScreen.y
		self.prev_point = locationOnScreen
		return self._getmetadata() + "|" + "(%d,%d);(%d,%d) " % (x0,y0,x1,y1)
	def _getmetadata(self) :
		return "%s" % self.client_state.selectedColor.getRGB()
	def mouseReleased(self, locationOnScreen, g) :
		self.mouseDragged(locationOnScreen, g)
		self.prev_point = None
		return ""
	def draw(self, s, g) :
		if  s == "":
			return
		try :
			metadata, points = s.split('|')
		except ValueError :
			#no metadata given. This is a problem
			return
		points = points.split(';')
		
		#process metadata
		color = int(metadata)
		
		prev_point = None
		
		print "have points"
		g.setColor(Color(color)) 
		for point in points :
			point_match = point_re.match(point)
			if not point_match :
					#this is an error, shouldn't happen. Figure out what to do
					#we were sent bad data
				print "no match"
				return
			x,y = point_match.groups()
			x,y = int(x), int(y)
			if prev_point :
				print "drawing line"
				g.drawLine(prev_point[0], prev_point[1], x, y)
			prev_point = (x,y)
	def getIcon(self) :
		return self.image
	def getToolName(self) :
		return "Pencil"
	def getTooltip(self) :
		return "Draw wherever the mouse goes"
	def getToolID(self) :
		return "pencil"
	def getAffectedArea(self, phrase) :
		points = phrase.split('|')[1].split(';')
		match = point_re.match(points[0])
		if match is None:
			print "match is none. should not happen. ever."
			return
		x1, y1 = match.groups()
		x1, y1 = int(x1), int(y1)
		match = point_re.match(points[1])
		if match is None:
			print "match is none. should not happen. ever."
			return
		x2, y2 = match.groups()
		x2, y2 = int(x2), int(y2)
		ax1 = min(x1, x2)
		ay1 = min(y1, y2)
		ax2 = max(x1, x2)
		ay2 = max(y1, y2)
		return [ax1, ay1 - 1, ax2 - ax1, ay2 - ay1 + 2]
Exemple #15
0
class Simbicon(java, applet, Applet, MouseListener, MouseMotionListener,
               KeyListener):
    """ generated source for class Simbicon """
    bip7 = Bip7()
    gnd = Ground()
    Dt = 0.00005
    DtDisp = 0.0054
    timeEllapsed = 0

    # we'll use this buffered image to reduce flickering
    tempBuffer = BufferedImage()
    timer = Timer()

    # and the controller
    con = Controller()
    Md = float()
    Mdd = float()
    DesVel = 0

    # if this variable is set to true, the simulation will be running, otherwise it won't
    simFlag = False
    simButton = javax.swing.JButton()
    reset = javax.swing.JButton()
    panel = javax.swing.JPanel()
    speedSlider = javax.swing.JSlider()
    label = javax.swing.JLabel()
    shouldPanY = False

    def init(self):
        """ generated source for method init """
        setSize(500, 500)
        addMouseListener(self)
        addMouseMotionListener(self)
        # initialize the biped to a valid state:
        state = [
            0.463, 0.98, 0.898, -0.229, 0.051, 0.276, -0.221, -1.430, -0.217,
            0.086, 0.298, -3.268, -0.601, 3.167, 0.360, 0.697, 0.241, 3.532
        ]
        self.bip7.setState(state)
        delay = 1
        # milliseconds
        taskPerformer = ActionListener()
        self.timer = Timer(delay, taskPerformer)
        self.timer.start()
        self.tempBuffer = BufferedImage(500, 500, BufferedImage.TYPE_INT_RGB)
        initComponents()
        self.con = Controller()
        self.con.addWalkingController()
        self.con.addRunningController()
        self.con.addCrouchWalkController()
        self.addKeyListener(self)
        self.requestFocus()

    def boundRange(self, value, min, max):
        """ generated source for method boundRange """
        if value < min:
            value = min
        if value > max:
            value = max
        return value

    # ////////////////////////////////////////////////////////
    #   PROC: wPDtorq()
    #   DOES: computes requires torque to move a joint wrt world frame
    # ////////////////////////////////////////////////////////
    def wPDtorq(self, torq, joint, dposn, kp, kd, world):
        """ generated source for method wPDtorq """
        joint_posn = self.bip7.State[4 + joint * 2]
        joint_vel = self.bip7.State[4 + joint * 2 + 1]
        if world:
            #  control wrt world frame? (virtual)
            joint_posn += self.bip7.State[4]
            #  add body tilt
            joint_vel += self.bip7.State[5]
            #  add body angular velocity
        torq[joint] = kp * (dposn - joint_posn) - kd * joint_vel

    # ////////////////////////////////////////////////////////
    #  PROC:  jointLimit()
    #  DOES:  enforces joint limits
    # ////////////////////////////////////////////////////////
    def jointLimit(self, torq, joint):
        """ generated source for method jointLimit """
        kpL = 800
        kdL = 80
        minAngle = self.con.jointLimit[0][joint]
        maxAngle = self.con.jointLimit[1][joint]
        currAngle = self.bip7.State[4 + joint * 2]
        currOmega = self.bip7.State[4 + joint * 2 + 1]
        if currAngle < minAngle:
            torq = kpL * (minAngle - currAngle) - kdL * currOmega
        elif currAngle > maxAngle:
            torq = kpL * (maxAngle - currAngle) - kdL * currOmega
        return torq

    def bip7WalkFsm(self, torq):
        """ generated source for method bip7WalkFsm """
        torsoIndex = 0
        rhipIndex = 1
        rkneeIndex = 2
        lhipIndex = 3
        lkneeIndex = 4
        rankleIndex = 5
        lankleIndex = 6
        worldFrame = [False, True, False, True, False, False, False]
        self.con.stateTime += self.Dt
        s = self.con.state[self.con.fsmState]
        computeMdMdd()
        n = 0
        while n < 7:
            target = self.boundRange(target, self.con.targetLimit[0][n],
                                     self.con.targetLimit[1][n])
            self.wPDtorq(torq, n, target, self.con.kp[n], self.con.kd[n],
                         worldFrame[n])
            n += 1
        self.con.advance(self.bip7)

    def bip7Control(self, torq):
        """ generated source for method bip7Control """
        body = 0
        stanceHip = int()
        swingHip = int()
        fallAngle = 60
        n = 0
        while n < 7:
            torq[n] = 0
            n += 1
        if not self.bip7.lostControl:
            self.bip7WalkFsm(torq)
        if self.con.state[self.con.fsmState].leftStance:
            stanceHip = 3
            swingHip = 1
        else:
            stanceHip = 1
            swingHip = 3
        if not self.con.state[self.con.fsmState].poseStance:
            torq[stanceHip] = -torq[body] - torq[swingHip]
        torq[0] = 0
        n = 1
        while n < 7:
            torq[n] = self.boundRange(torq[n], self.con.torqLimit[0][n],
                                      self.con.torqLimit[1][n])
            self.jointLimit(torq[n], n)
            n += 1

    def computeMdMdd(self):
        """ generated source for method computeMdMdd """
        stanceFootX = self.bip7.getStanceFootXPos(self.con)
        self.Mdd = self.bip7.State[1] - self.DesVel
        self.Md = self.bip7.State[0] - stanceFootX

    def initComponents(self):
        """ generated source for method initComponents """
        self.simButton = javax.swing.JButton()
        self.reset = javax.swing.JButton()
        self.panel = javax.swing.JPanel()
        self.label = javax.swing.JLabel()
        self.label.setText("Speed: ")
        self.speedSlider = javax.swing.JSlider()
        self.speedSlider.setMaximum(100)
        self.speedSlider.setMinimum(0)
        self.speedSlider.setToolTipText(
            "Adjust the speed of the simulation by adjusting this slider.")
        setLayout(BorderLayout())
        self.panel.setLayout(FlowLayout())
        add(self.panel, BorderLayout.NORTH)
        self.panel.add(self.label)
        self.panel.add(self.speedSlider)
        self.panel.add(self.simButton)
        self.panel.add(self.reset)
        self.speedSlider.addMouseListener(java.awt.event.MouseAdapter())
        self.simButton.setText("  Start  ")
        self.reset.setText("Reset")
        self.simButton.addActionListener(java.awt.event.ActionListener())
        self.reset.addActionListener(java.awt.event.ActionListener())

    def resetSimulation(self):
        """ generated source for method resetSimulation """
        self.bip7.resetBiped()
        self.con.stateTime = 0
        self.con.fsmState = 0
        self.con.currentGroupNumber = 0
        self.con.desiredGroupNumber = 0
        repaint()

    def runLoop(self):
        """ generated source for method runLoop """
        if self.simFlag == False:
            return
        self.timer.stop()
        i = 0
        while i < 200:
            self.bip7.computeGroundForces(self.gnd)
            self.bip7Control(self.bip7.t)
            self.bip7.runSimulationStep(self.Dt)
            self.timeEllapsed += self.Dt
            if self.timeEllapsed > self.DtDisp:
                self.update(self.getGraphics())
                self.timeEllapsed = 0
            i += 1
        self.timer.start()

    def update(self, g):
        """ generated source for method update """
        if g == None:
            return
        g2 = self.tempBuffer.getGraphics()
        g2.setColor(Color(255, 255, 255))
        g2.fillRect(0, 0, getSize().width - 1, getSize().height - 1)
        m = Matrix3x3.getTranslationMatrix(0, -300)
        m = m.multiplyBy(Matrix3x3.getScalingMatrix(float(100)))
        panX = self.bip7.State[0]
        panY = self.bip7.State[2]
        if self.shouldPanY == False:
            panY = 0
        m = m.multiplyBy(
            Matrix3x3.getTranslationMatrix(-panX + 1.5, -panY + 0.5))
        self.bip7.drawBiped(g2, m)
        self.gnd.draw(g2, m)
        g.drawImage(self.tempBuffer, 0, self.panel.getHeight(), self)
        self.panel.repaint()

    def paint(self, g):
        """ generated source for method paint """
        self.update(g)
        self.panel.repaint()

    def keyReleased(self, e):
        """ generated source for method keyReleased """

    def keyPressed(self, e):
        """ generated source for method keyPressed """
        if e.getKeyCode() == e.VK_LEFT:
            self.bip7.PushTime = 0.2
            self.bip7.PushForce = -60
        if e.getKeyCode() == e.VK_RIGHT:
            self.bip7.PushTime = 0.2
            self.bip7.PushForce = 60
        if e.getKeyChar() == 'r' or e.getKeyChar() == 'R':
            self.con.desiredGroupNumber = 1
        if e.getKeyChar() == 'w' or e.getKeyChar() == 'W':
            self.con.desiredGroupNumber = 0
        if e.getKeyChar() == 'c' or e.getKeyChar() == 'C':
            self.con.desiredGroupNumber = 2
        if e.getKeyChar() == '1':
            self.gnd.getFlatGround()
            self.resetSimulation()
        if e.getKeyChar() == '2':
            self.gnd.getComplexTerrain()
            self.resetSimulation()

    def keyTyped(self, e):
        """ generated source for method keyTyped """

    def mouseDragged(self, e):
        """ generated source for method mouseDragged """

    def mouseMoved(self, e):
        """ generated source for method mouseMoved """

    def mousePressed(self, e):
        """ generated source for method mousePressed """
        self.requestFocus()

    def mouseReleased(self, e):
        """ generated source for method mouseReleased """

    def mouseEntered(self, e):
        """ generated source for method mouseEntered """

    def mouseExited(self, e):
        """ generated source for method mouseExited """

    def mouseClicked(self, e):
        """ generated source for method mouseClicked """

    def destroy(self):
        """ generated source for method destroy """
        removeMouseListener(self)
        removeMouseMotionListener(self)

    def getAppletInfo(self):
        """ generated source for method getAppletInfo """
        return "Title: Simbicon\n" + "Author: Stelian Coros, Michiel van de Panne."
Exemple #16
0
class PasteTool(Tool) :
	def __init__(self, clientState = None) :
		self.client_state = clientState
		self.start_point = None
		self._image = None
		self.makeImage()
	

	def makeImage(self) :
		#Draw something to indicate copy tool.
		#Currently drawing an X
		self.image = BufferedImage(32,32,BufferedImage.TYPE_INT_ARGB)
		g = self.image.getGraphics()
		g.setColor(Color(0,0,0))
		g.drawLine(3,3,30,3)
		g.drawLine(30,3,30,16)
		g.drawLine(3,3,3,29)
		g.drawLine(3,16,30,16)


	def mousePressed(self, locationOnScreen, g) :
		return ""


	def mouseHovered(self, locationOnScreen, g) :
		return ""


	def mouseDragged(self, locationOnScreen, g) :
		return ""


	def mouseReleased(self, locationOnScreen, g) :
		return ""

	def mouseClicked(self, locationOnScreen, g) :
		if self.client_state.clipboard :
			self._image = ImageData(locationOnScreen.x, locationOnScreen.y, self.client_state.clipboard)
		return ""

	def getLastImage(self) :
		if self._image :
			image = self._image
			self._image = None
			return image
		return None

	def getAffectedArea(self, phrase) :
		# important! 
		return None


	def getIcon(self) :
		return self.image


	def getToolName(self) :
		return "Paste"


	def getTooltip(self) :
		return "Paste the Image stored in memory to the area of the screen clicked on by the mouse."


	def getToolID(self) :
		return 'paste'
Exemple #17
0
class RectangleTool(Tool) :
	ICON_SIZE = 32
	ZERO = 0
	THIRTY_ONE = 31
	serialVersionUID = 123456789
	def __init__(self, clientState = None) :
		print type(clientState)
		self.client_state = clientState
		self.start_point = None
		self.makeImage()
	def makeImage(self) :
		self.image = BufferedImage(self.ICON_SIZE,self.ICON_SIZE,BufferedImage.TYPE_INT_ARGB)
		g = self.image.getGraphics()
		g.setColor(Color(self.ZERO,self.ZERO,self.ZERO))
		g.drawRect(self.ZERO,self.ZERO,self.THIRTY_ONE,self.THIRTY_ONE)
	def mousePressed(self, locationOnScreen, g) :
		self.start_point = locationOnScreen
		return ""
	def mouseHovered(self, locationOnScreen, g) :
		return ""
	def mouseDragged(self, locationOnScreen, g) :
		x1 = min(self.start_point.x, locationOnScreen.x)
		y1 = min(self.start_point.y, locationOnScreen.y)
		x2 = max(self.start_point.x, locationOnScreen.x)
		y2 = max(self.start_point.y, locationOnScreen.y)
		g.setColor(self.client_state.selectedColor)
		g.drawRect(x1, y1, x2 - x1, y2 - y1)
		return ""
	def mouseReleased(self, locationOnScreen, g) :
		x1 = min(self.start_point.x, locationOnScreen.x)
		y1 = min(self.start_point.y, locationOnScreen.y)
		x2 = max(self.start_point.x, locationOnScreen.x)
		y2 = max(self.start_point.y, locationOnScreen.y)
		return self._getmetadata() + "|" + "(%d,%d);(%d,%d) " % (x1, y1, x2 - x1, y2 - y1)
	def _getmetadata(self) :
		return "%d" % self.client_state.selectedColor.getRGB()
	def draw(self, s, g) :
		if s == "" :
			return
		metadata, points = s.split('|')
		points = points.split(';')
		g.setColor(Color(int(metadata)))
		match = point_re.match(points[0])
		if match is None:
			return
		x1, y1 = match.groups()
		x1, y1 = int(x1), int(y1)
		match = point_re.match(points[1])
		if match is None:
			return
		x2, y2 = match.groups()
		x2, y2 = int(x2), int(y2)
		g.drawRect(x1, y1, x2, y2)
	def getAffectedArea(self, phrase) :
		points = phrase.split('|')[1].split(';')
		match = point_re.match(points[0])
		if match is None:
			return
		x1, y1 = match.groups()
		x1, y1 = int(x1), int(y1)
		match = point_re.match(points[1])
		if match is None:
			return
		x2, y2 = match.groups()
		x2, y2 = int(x2), int(y2)
		ax1 = min(x1, x2)
		ay1 = min(y1, y2)
		ax2 = max(x1, x2)
		ay2 = max(y1, y2)
		return [ax1, ay1, ax2 - ax1, ay2 - ay1]
	def getIcon(self) :
		return self.image
	def getToolName(self) :
		return "Rectangle"
	def getTooltip(self) :
		return "draw a rectangle with one corner\nwhere you click and the opposite\ncorner where you release the mouse"
	def getToolID(self) :
		return 'rect'   
Exemple #18
0
class RoundedRectangleTool(Tool):
    def __init__(self, clientState=None):
        self.client_state = clientState
        self.start_point = None
        self.makeImage()

    def makeImage(self):
        self.image = BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB)
        g = self.image.getGraphics()
        g.setColor(Color(0, 0, 0))
        g.drawRoundRect(0, 0, 31, 31, 10, 10)

    def mousePressed(self, locationOnScreen, g):
        self.start_point = locationOnScreen
        return ""

    def mouseHovered(self, locationOnScreen, g):
        return ""

    def mouseDragged(self, locationOnScreen, g):
        x1 = min(self.start_point.x, locationOnScreen.x)
        y1 = min(self.start_point.y, locationOnScreen.y)
        x2 = max(self.start_point.x, locationOnScreen.x)
        y2 = max(self.start_point.y, locationOnScreen.y)
        g.setColor(self.client_state.selectedColor)
        g.drawRoundRect(x1, y1, x2 - x1, y2 - y1, 20, 20)
        return ""

    def mouseReleased(self, locationOnScreen, g):
        x1 = min(self.start_point.x, locationOnScreen.x)
        y1 = min(self.start_point.y, locationOnScreen.y)
        x2 = max(self.start_point.x, locationOnScreen.x)
        y2 = max(self.start_point.y, locationOnScreen.y)
        return self._getmetadata() + "|" + "(%d,%d);(%d,%d) " % (x1, y1, x2 - x1, y2 - y1)

    def _getmetadata(self):
        return "%d" % self.client_state.selectedColor.getRGB()

    def draw(self, s, g):
        if s == "":
            return
        metadata, points = s.split("|")
        points = points.split(";")
        g.setColor(Color(int(metadata)))
        match = point_re.match(points[0])
        if match is None:
            return
        x1, y1 = match.groups()
        x1, y1 = int(x1), int(y1)
        match = point_re.match(points[1])
        if match is None:
            return
        x2, y2 = match.groups()
        x2, y2 = int(x2), int(y2)
        g.drawRoundRect(x1, y1, x2, y2, 20, 20)

    def getAffectedArea(self, phrase):
        points = phrase.split("|")[1].split(";")
        match = point_re.match(points[0])
        if match is None:
            return
        x1, y1 = match.groups()
        x1, y1 = int(x1), int(y1)
        match = point_re.match(points[1])
        if match is None:
            return
        x2, y2 = match.groups()
        x2, y2 = int(x2), int(y2)
        ax1 = min(x1, x2)
        ay1 = min(y1, y2)
        ax2 = max(x1, x2)
        ay2 = max(y1, y2)
        return [ax1, ay1, ax2 - ax1, ay2 - ay1]

    def getIcon(self):
        return self.image

    def getToolName(self):
        return "Rounded Rectangle"

    def getTooltip(self):
        return "draw a rounded rectangle with one corner\nwhere you click and the opposite\ncorner where you release the mouse"

    def getToolID(self):
        return "roundrect"
Exemple #19
0
class LineTool(Tool) :
	def __init__(self, clientState = None) :
		self.client_state = clientState
		self.start_point = None
		self.makeImage()
	def makeImage(self) :
		self.image = BufferedImage(32,32,BufferedImage.TYPE_INT_ARGB)
		g = self.image.getGraphics()
		g.setColor(Color(0,0,0))
		g.drawLine(0,0,32,32)
	def mousePressed(self, locationOnScreen, g) :
		self.start_point = locationOnScreen
		return ""
	def mouseHovered(self, locationOnScreen, g) :
		return ""
	def mouseDragged(self, locationOnScreen, g) :
		x1 = self.start_point.x
		y1 = self.start_point.y
		x2 = locationOnScreen.x
		y2 = locationOnScreen.y
		g.setColor(self.client_state.selectedColor)
		g.drawLine(x1, y1, x2, y2)
		return ""
	def _getmetadata(self) :
		''' gets the color and the thickness (currently hardcoded to 1 since
		that isn't implemented yet'''
		return "%d;%d" % (self.client_state.selectedColor.getRGB(), 1)
	def mouseReleased(self, locationOnScreen, g) :
		x1 = self.start_point.x
		y1 = self.start_point.y
		x2 = locationOnScreen.x
		y2 = locationOnScreen.y
		return self._getmetadata() + "|" + "(%d,%d);(%d,%d) " % (x1, y1, x2, y2)
	def draw(self, s, g) :
		if s == "" :
			return
		metadata, points = s.split('|')
		color, size = metadata.split(';')
		color, size = int(color), int(size)
		points = points.split(';')
		match = point_re.match(points[0])
		if match is None:
			return
		x1, y1 = match.groups()
		x1, y1 = int(x1), int(y1)
		match = point_re.match(points[1])
		if match is None:
			return
		x2, y2 = match.groups()
		x2, y2 = int(x2), int(y2)
		g.setColor(Color(color))
		g.drawLine(x1, y1, x2, y2)
	def getAffectedArea(self, phrase) :
		points = phrase.split('|')[1].split(';')
		match = point_re.match(points[0])
		if match is None:
			return
		x1, y1 = match.groups()
		x1, y1 = int(x1), int(y1)
		match = point_re.match(points[1])
		if match is None:
			return
		x2, y2 = match.groups()
		x2, y2 = int(x2), int(y2)
		ax1 = min(x1, x2)
		ay1 = min(y1, y2)
		ax2 = max(x1, x2)
		ay2 = max(y1, y2)
		return [ax1, ay1, ax2 - ax1, ay2 - ay1]
	def getIcon(self) :
		return self.image
	def getToolName(self) :
		return "Line"
	def getTooltip(self) :
		return "draw a line from the point where you click to the point where\n you release the mouse"
	def getToolID(self) :
		return 'line'	
Exemple #20
0
def _create_buffered_image(image):
    result = BufferedImage(image.getWidth(None), image.getHeight(None),
                           BufferedImage.TYPE_INT_ARGB)
    result.getGraphics().drawImage(image, 0, 0, None)
    return result
Exemple #21
0
class CopyTool(Tool) :
	def __init__(self, clientState = None) :
		self.client_state = clientState
		if self.client_state is not None :
			self.canvas_image = self.client_state.canvas.getCanvasImage()
		self.start_point = None
		self.makeImage()	
	

	def makeImage(self) :
		#Draw something to indicate copy tool.
		#Currently drawing an X
		self.image = BufferedImage(32,32,BufferedImage.TYPE_INT_ARGB)
		g = self.image.getGraphics()
		g.setColor(Color(0,0,0))
		g.drawLine(7,6,10,3)
		g.drawLine(10,3,22,3)
		g.drawLine(22,3,25,6)
		g.drawLine(7,6,7,26)
		g.drawLine(7,26,10,30)
		g.drawLine(10,30,22,30)
		g.drawLine(22,30,25,27)
		#clear g?


	def mousePressed(self, locationOnScreen, g) :
		self.start_point = locationOnScreen
		return ""


	def mouseHovered(self, locationOnScreen, g) :
		return ""


	def mouseDragged(self, locationOnScreen, g) :
		x1 = self.start_point.x
		y1 = self.start_point.y
		x2 = locationOnScreen.x
		y2 = locationOnScreen.y
		#g.setColor(self.client_state.selectedColor)
		#g.scale(10, 10)
		#g.setStroke(BasicStroke(1.5))
		g.drawRect(x1, y1, x2 - x1, y2 - y1)	#TODO: Ensure this draws to the artifact layer...
		return ""


	def _getmetadata(self) :
		return ""


	def mouseReleased(self, locationOnScreen, g) :
		x1 = self.start_point.x
		y1 = self.start_point.y
		x2 = locationOnScreen.x
		y2 = locationOnScreen.y

		#Save the Image to clipboard.
		dx1 = min(x1, x2)
		dy1 = min(y1, y2)
		dx2 = max(x1, x2)
		dy2 = max(y1, y2)
		img = self.client_state.canvas.getCanvasImage()
		xoff = (img.getWidth(self.client_state.canvas) - self.client_state.canvas.getWidth()) / 2
		yoff = (img.getHeight(self.client_state.canvas) - self.client_state.canvas.getHeight()) / 2
		self.client_state.clipboard = img.getSubimage(dx1+xoff, dy1+yoff, dx2-dx1, dy2-dy1)
		
		return ""


	def draw(self, s, g) :
		if s == "" :
			return
		metadata, points = s.split('|')
		color, size = metadata.split(';')
		color, size = int(color), int(size)
		points = points.split(';')
		match = point_re.match(points[0])
		if match is None:
			return
		x1, y1 = match.groups()
		x1, y1 = int(x1), int(y1)
		match = point_re.match(points[1])
		if match is None:
			return
		x2, y2 = match.groups()
		x2, y2 = int(x2), int(y2)
		g.setColor(Color(color))
		g.drawLine(x1, y1, x2, y2)


	def getAffectedArea(self, phrase) :		#TODO: Determine if this method is necessary
		return None


	def getIcon(self) :
		return self.image


	def getToolName(self) :
		return "Copy"


	def getTooltip(self) :
		return "Copy the selected area into a clipboard for future use."


	def getToolID(self) :
		return 'copy'