def doInBackground(self, params): w, h, self.position = params bitmap = self.getSpriteBitmap() width = bitmap.getWidth() height = bitmap.getHeight() xscale = w / float(width) yscale = h / float(height) scale = Math.min(xscale, yscale) if 0 < scale < 1: sw = Math.max(1, scale * width) sh = Math.max(1, scale * height) bitmap = Bitmap.createScaledBitmap(bitmap, sw, sh, True) elif scale >= 2: s = Math.min(int(Math.floor(scale)), 3) sw = Math.max(1, s * width) sh = Math.max(1, s * height) bitmap = Bitmap.createScaledBitmap(bitmap, sw, sh, False) preview = self.emptyBitmap(w, h, True) canvas = Canvas(preview) canvas.drawBitmap(bitmap, (w - bitmap.getWidth()) / 2, (h - bitmap.getHeight()) / 2, self.paint) return preview
def tick(self): if self.t == 0: # Find totem totem = None totem_id = PersistentDataAPI.getInt(PersistentDataAPI.getData(self.player), 'totem', None) for e in self.player.getWorld().getEntities(): if e.getEntityId() == totem_id: totem = e if totem is None: PlayerAPI.sendWynnMessage(self.player, 'messages.totem_out') self.cancel() return vector = totem.getLocation().clone().subtract(self.player.getLocation()).add(0, 2, 0).toVector() vector = Vector(Math.max(Math.min(vector.getX(), 6), -6), Math.max(Math.min(vector.getY(), 2), -2), Math.max(Math.min(vector.getZ(), 6), -6)) self.player.setVelocity(vector.clone().multiply(0.5).setY(vector.getY()).multiply(0.5)); self.particle(self.player.getLocation(), Particle.CLOUD, 6, 1, 1, 1, 0.1) self.particle(self.player.getLocation(), Particle.SQUID_INK, 6, 1, 1, 1, 0.1) self.sound(Sound.ENTITY_PLAYER_ATTACK_KNOCKBACK, .4, .8) self.sound(Sound.ENTITY_BLAZE_SHOOT, 1, 1) self.sound(Sound.ENTITY_IRON_GOLEM_HURT, .8, .8) if self.clone: self.sound(Sound.ENTITY_BLAZE_AMBIENT, .1, .9) elif self.t > 10: if self.player.isOnGround(): self.particle(self.player.getLocation().clone().add(0, 1, 0), Particle.FIREWORKS_SPARK if self.clone else Particle.TOTEM, 5, 1, 2, 1, .2) self.particle(self.player.getLocation(), Particle.CLOUD, 6, 1, .2, 1, .1) self.particle(self.player.getLocation(), Particle.SQUID_INK, 6, 1, .2, 1, .1) if self.clone: self.particle(self.player.getLocation(), Particle.SPELL_MOB, 0, 1, 1, 1, 1) self.sound(Sound.BLOCK_STONE_STEP, 1, .9) self.sound(Sound.BLOCK_STONE_FALL, 1, .9) self.player.setVelocity(Vector(0, .5, 0)) self.cancel() else: for e in self.nearbyMobs(1, 1, 1): if e in self.hit: continue self.hit.add(e) self.damage(e, False, 1, .8, 0, .2, 0, 0, 0) PySpell.knockback(e, VectorUP, 2) e.addPotionEffect(PotionEffect(PotionEffectType.BLINDNESS, 100, 0, True, False))
def damageAndPull(self, l): for e in self.nearbyMobs(l, .5, 2, .5): pull_dir = self.totem.getLocation().clone().subtract( e.getLocation()).toVector() pull_dir = Vector(Math.max(Math.min(pull_dir.getX() / 5, 1), -1), 0.2, Math.max(Math.min(pull_dir.getZ() / 5, 1), -1)) e.setVelocity(pull_dir) if e in self.hit: continue self.hit.add(e) self.damage(e, False, 2, .7, 0, 0, .3, 0, 0)
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 p_addition(p): '''addition : term | term addOP addition''' from java.lang import Math import Addition if len(p) == 4 and isinstance( p[1], int ) and isinstance( p[3], int ): print "Calling java Math: ", Math.max(p[1], p[3]) print "Calling java Addition.add: ", Addition.add(p[1], p[3]) if len(p) == 4: p[0] = str(p[1]) + str(p[2]) + str(p[3]) else : p[0] = p[1]
phi = eval(self.poly_terms) return (i + LinAlg.dotProduct(phi,self.poly_x), j + LinAlg.dotProduct(phi,self.poly_y)) if __name__ == "__main__": #-------------------------------------- model = PolyUndistortionModel(sys.argv[1]) im = ImageIO.read(File(sys.argv[2])) undistorted = [] maxx, maxy, minx, miny = float('-Inf'), float('-Inf'), float('Inf'), float('Inf') for i in range(im.width): for j in range(im.height): ii, jj = model.undistort(i, j) undistorted.append([ii, jj, im.getRGB(i,j)]) maxx = Math.max(maxx, ii) minx = Math.min(minx, ii) maxy = Math.max(maxy, jj) miny = Math.min(miny, jj) rangex, rangey = maxx-minx, maxy-miny imout = BufferedImage(int(im.width*0.4), int(im.height*0.4), BufferedImage.TYPE_INT_ARGB) scale = imout.width/rangex for u in undistorted: x, y = int((u[0]-minx)*scale), int((u[1]-miny)*scale) if x < imout.width and y < imout.height: imout.setRGB(x, y, 0xFF000000 | u[2]) token = sys.argv[2].split('.')[0] ImageIO.write(imout, 'png', File(token + '.out.png'))
def test_java_stuff(self): from java.lang import Math maxval = Math.max(4, 7) self.assertEqual(7, maxval)
def monthlyTable(file, search, twstring): # Create Data Reference from Inputs g = opendss(file) from java.lang import System lineSeparator = System.getProperty( 'line.separator') # '\r\n' # '\n' on unix desiredSpaceCount = 6 g.filterBy(search) # Set time window and create a new ref with this window tw = timeWindow(twstring) ref = DataReference.create(g[0], tw) pref = PeriodAverageProxy( ref, DSSUtil.getTimeFactory().createTimeInterval('1month')) dsi = pref.getData().getIterator() tm = DSSUtil.getTimeFactory().getTimeInstance() tmf = DSSUtil.getTimeFactory().getTimeFormatInstance().create("MMM yyyy") tmf1 = DSSUtil.getTimeFactory().getTimeFormatInstance().create("MMM") tmf2 = DSSUtil.getTimeFactory().getTimeFormatInstance().create("yyyy") from java.lang import Float, Math from java.util import Date sys.add_package('java.text') from java.text import NumberFormat nf = NumberFormat.getInstance() nf.setGroupingUsed(0) nf.setMinimumFractionDigits(1) nf.setMinimumIntegerDigits(1) nf.setMaximumFractionDigits(1) fp = FieldPosition(nf.INTEGER_FIELD) lines = [] lines.append('STUDY: ' + ref.getPathname().getPart(Pathname.F_PART) + space(10) + 'FILE: ' + file + space(10) + Date().toString()) lines.append('') lines.append('Searched: ' + search) lines.append('Units: ' + ref.getData().getAttributes().getYUnits()) lines.append('Project: ' + ref.getPathname().toString()) lines.append('') desiredSpace = space(desiredSpaceCount + nf.getMinimumIntegerDigits() + nf.getMinimumFractionDigits() - 3) startSpace = desiredSpace + space(4) lines.append('YEAR' + desiredSpace + 'OCT' + desiredSpace + 'NOV' + desiredSpace + 'DEC' + desiredSpace + 'JAN' + desiredSpace + 'FEB' + desiredSpace + 'MAR' + desiredSpace + 'APR' + desiredSpace + 'MAY' + desiredSpace + 'JUN' + desiredSpace + 'JUL' + desiredSpace + 'AUG' + desiredSpace + 'SEP' + space(desiredSpaceCount - 3) + 'TOTAL') cl = '' gotOct = 0 yrsum = 0.0 allyrtot = 0.0 yravg = 0.0 totavg = 0.0 totmin = Float.MAX_VALUE totmax = Float.MIN_VALUE nsum = 0 nyears = 0 while not dsi.atEnd(): e = dsi.getElement() date = tm.create(Math.round(e.getX())).toString() mon = date[2:5] if mon == 'OCT': if nsum > 0: yravg = yrsum allyrtot = allyrtot + yrsum nyears = nyears + 1 totmin = Math.min(totmin, yrsum) totmax = Math.max(totmax, yrsum) if cl != '': strbuf = StringBuffer(10) nf.format(yravg, strbuf, fp) cl = cl + space(desiredSpaceCount - fp.getEndIndex()) + strbuf.toString() lines.append(cl) # yrsum = 0.0 nsum = 0 # water year cl = repr(int(tm.create(Math.round(e.getX())).format(tmf2)) + 1) gotOct = 1 # if gotOct: if (e.getY() == -901): strbuf = StringBuffer(10) nf.format(yravg, strbuf, fp) cl = cl + space(desiredSpaceCount) + \ space(nf.getMinimumIntegerDigits() + nf.getMinimumIntegerDigits()) else: strbuf = StringBuffer(10) nf.format(e.getY(), strbuf, fp) cl = cl + space(desiredSpaceCount - fp.getEndIndex()) + strbuf.toString() yrsum = yrsum + e.getY() nsum = nsum + 1 # print tm.create(Math.round(e.getX())).format(tmf), e.getY() # dsi.advance() # # Get average, min, max for each month totavg = allyrtot / nyears minV = Float.MAX_VALUE maxV = Float.MIN_VALUE monavg = { 'OCT': 0.0, 'NOV': 0.0, 'DEC': 0.0, 'JAN': 0.0, 'FEB': 0.0, 'MAR': 0.0, 'APR': 0.0, 'MAY': 0.0, 'JUN': 0.0, 'JUL': 0.0, 'AUG': 0.0, 'SEP': 0.0 } monmin = { 'OCT': minV, 'NOV': minV, 'DEC': minV, 'JAN': minV, 'FEB': minV, 'MAR': minV, 'APR': minV, 'MAY': minV, 'JUN': minV, 'JUL': minV, 'AUG': minV, 'SEP': minV } monmax = { 'OCT': maxV, 'NOV': maxV, 'DEC': maxV, 'JAN': maxV, 'FEB': maxV, 'MAR': maxV, 'APR': maxV, 'MAY': maxV, 'JUN': maxV, 'JUL': maxV, 'AUG': maxV, 'SEP': maxV } numavg = { 'OCT': 0, 'NOV': 0, 'DEC': 0, 'JAN': 0, 'FEB': 0, 'MAR': 0, 'APR': 0, 'MAY': 0, 'JUN': 0, 'JUL': 0, 'AUG': 0, 'SEP': 0 } gotOct = 0 dsi.resetIterator() while not dsi.atEnd(): e = dsi.getElement() date = tm.create(Math.round(e.getX())).toString() mon = date[2:5] if mon == 'OCT': gotOct = 1 if gotOct: if (e.getY() == -901): pass else: monmin[mon] = Math.min(monmin[mon], e.getY()) monmax[mon] = Math.max(monmax[mon], e.getY()) monavg[mon] = monavg[mon] + e.getY() numavg[mon] = numavg[mon] + 1 # # dsi.advance() # lines.append(' ') cl = 'AVG:' for val in monavg.keys(): monavg[val] = monavg[val] / numavg[val] strbuf = StringBuffer(10) nf.format(monavg[val], strbuf, fp) cl = cl + space(desiredSpaceCount - fp.getEndIndex()) + strbuf.toString() # strbuf = StringBuffer(10) nf.format(totavg, strbuf, fp) cl = cl + space(desiredSpaceCount - fp.getEndIndex()) + strbuf.toString() lines.append(cl) # cl = 'MIN:' for val in monmin.keys(): strbuf = StringBuffer(10) nf.format(monmin[val], strbuf, fp) cl = cl + space(desiredSpaceCount - fp.getEndIndex()) + strbuf.toString() # strbuf = StringBuffer(10) nf.format(totmin, strbuf, fp) cl = cl + space(desiredSpaceCount - fp.getEndIndex()) + strbuf.toString() lines.append(cl) # cl = 'MAX:' for val in monmax.keys(): strbuf = StringBuffer(10) nf.format(monmax[val], strbuf, fp) cl = cl + space(desiredSpaceCount - fp.getEndIndex()) + strbuf.toString() # strbuf = StringBuffer(10) nf.format(totmax, strbuf, fp) cl = cl + space(desiredSpaceCount - fp.getEndIndex()) + strbuf.toString() lines.append(cl) # # # f=open(search + '.txt','w') # for line in lines : # f.write(line + lineSeparator) # print line # # f.close() return lines