예제 #1
0
    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
예제 #2
0
파일: haul.py 프로젝트: WynnLab/WynnLab
    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))
예제 #3
0
파일: aura.py 프로젝트: WynnLab/WynnLab
    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)
예제 #4
0
    def tick(self):
        if self.t == 0:
            if not self.player.getWorld().getBlockAt(
                    self.player.getLocation().clone().subtract(
                        0, 1,
                        0)).isEmpty() or not self.player.getWorld().getBlockAt(
                            self.player.getLocation().clone().subtract(
                                0, 2, 0)).isEmpty():
                #self.player.addScoreboardTag('escape')
                eye_dir = self.player.getEyeLocation().getDirection()
                self.player.setVelocity(
                    eye_dir.setY(Math.min(-.4 * Math.abs(eye_dir.getY()),
                                          -.4)).multiply(-4))

                self.sound(self.player.getLocation(), Sound.ENTITY_BLAZE_SHOOT,
                           1, 1.2)
                self.particle(
                    self.player.getLocation().clone().add(0, 1, 0),
                    Particle.VILLAGER_HAPPY if self.clone else
                    Particle.SQUID_INK, 10 if self.clone else 5, .3, 2, .3, .2)
                if self.clone:
                    self.particle(
                        self.player.getLocation().clone().add(0, 1, 0),
                        Particle.CLOUD, 5, .3, 2, .3, .1)
            else:
                self.cancel()
            return

        if not self.player.isOnGround():
            self.delay()

            if self.player.isSneaking():
                self.player.setVelocity(
                    self.player.getVelocity().clone().subtract(Vector(0, 1,
                                                                      0)))
            elif self.player.getVelocity().getY() <= -.5:
                self.player.getVelocity().setY(-.5)
        else:
            if self.player.isSneaking():
                for i in range(0, 360, 60):
                    for j in range(9):
                        l = self.player.getLocation().clone().add(
                            Math.sin(i * DEG2RAD) * j, 0,
                            Math.cos(i * DEG2RAD) * j)
                        self.particle(l, Particle.SQUID_INK, 2, 0, 0, 0, .2)
                        self.particle(l, Particle.CLOUD, 2, 0, 0, 0, .2)
                        self.particle(l, Particle.CRIT, 2, 0, 0, 0, .3)

                self.sound(Sound.ENTITY_GENERIC_EXPLODE, .5, 1.2)
                self.sound(Sound.ENTITY_IRON_GOLEM_DEATH, 1, 1)

                for e in self.nearbyMobs(8, 10, 8):
                    self.damage(e, 4)

            self.player.addPotionEffect(
                PotionEffect(PotionEffectType.SPEED, 3600, 2, True, False,
                             True))
예제 #5
0
def build_exceedance_array(ref1, ref2, end_of_sept=True, tw=None):
    from java.lang import Math
    x1=sort(ref1, end_of_sept, tw)
    x2=sort(ref2, end_of_sept, tw)
    darray=[]
    i=0
    n=int(Math.min(len(x1),len(x2)))
    while i < n:
        darray.append((100.0-100.0*float(i)/(n+1),x1[i],x2[i]))
        i=i+1
    return darray
예제 #6
0
파일: heal.py 프로젝트: a7m444d/WynnLab
    def tick(self):
        if self.t % 20 > 0:
            return

        self.particle(self.player.getLocation().clone().add(0, .5, 0), Particle.PORTAL, 144, 4, 0, 4, .1)
        self.particle(self.player.getLocation().clone().add(0, .3, 0), Particle.CRIT_MAGIC, 144, 4, 0, 4, .1)
        self.particle(self.player.getLocation().clone().add(0, 1, 0), Particle.FIREWORKS_SPARK, 16, .3, 1, .3, .05)
        self.sound(Sound.ENTITY_EVOKER_CAST_SPELL, .5, 1.5)
        self.sound(Sound.BLOCK_LAVA_EXTINGUISH, 1, 1)

        self.player.setHealth(Math.min(self.player.getHealth() + 50, self.player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()))

        for p in self.player.getNearbyEntities(4, 4, 4):
            if not isinstance(p, Player):
                continue

            p.setHealth(Math.min(p.getHealth() + 50, p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()))
            Bukkit.getPluginManager().callEvent(EntityRegainHealthEvent(p, 50, EntityRegainHealthEvent.RegainReason.CUSTOM))

            self.particle(p.getLocation().clone().add(0, 1, 0), Particle.FIREWORKS_SPARK, 16, .3, 1, .3, .05)
예제 #7
0
def build_exceedance_array(ref1, ref2, end_of_sept=True, tw=None):
    from java.lang import Math
    x1=sort(ref1, end_of_sept, tw)
    x2=sort(ref2, end_of_sept, tw)
    darray=[]
    i=0
    n=int(Math.min(len(x1),len(x2)))
    while i < n:
        darray.append((100.0-100.0*float(i)/(n+1),x1[i],x2[i]))
        i=i+1
    return darray
        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'))
예제 #9
0
import java.lang.Math as math
import java.lang.System.out.println as println
number_1 = 545
number_2 = 50
number = math.min(number_1, number_2)

println(number)
예제 #10
0
 def exp(self, x):
     import java.lang.Math as Math
     max_exp = 1e19
     return Math.min(max_exp, Math.exp(x))
예제 #11
0
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
예제 #12
0
import java.lang.Math as math
import java.lang.System.out.println as println

number_1 = 545
number_2 = 50
number = math.min(number_1, number_2)

println(number)