def create(self): w = Gdx.graphics.getWidth() h = Gdx.graphics.getHeight() self.camera = OrthographicCamera() self.camera.setToOrtho(False, (w / h) * 320, 320) self.camera.update() self.cameraController = OrthoCamController(self.camera) Gdx.input.setInputProcessor(self.cameraController) self.font = BitmapFont() self.batch = SpriteBatch() self.tiles = Texture( Gdx.files.internal('../../data/maps/tiled/tiles.png')) splitTiles = TextureRegion.split(self.tiles, 32, 32) self.map = TiledMap() layers = self.map.getLayers() for l in range(20): layer = TiledMapTileLayer(150, 100, 32, 32) for x in range(150): for y in range(100): ty = int(Math.random() * len(splitTiles)) tx = int(Math.random() * len(splitTiles[ty])) cell = Cell() cell.setTile(StaticTiledMapTile(splitTiles[ty][tx])) layer.setCell(x, y, cell) layers.add(layer) self.renderer = OrthogonalTiledMapRenderer(self.map)
def gemm(self, n): import time #from no.uib.cipr.matrix.nni import BLAS,LAPACK; from jarray import array, zeros from java.lang import Math, System import no.uib.cipr.matrix as matrix if n < 100: r = 100 else: r = 10 t = time.time() #A = zeros(n*n,'d') #B = zeros(n*n,'d') #C = zeros(n*n,'d') pin = range(n*n) #for i in pin: # A[i] = Math.random(); # B[i] = Math.random(); # C[i] = Math.random(); A = matrix.Matrices.random(n,n); B = matrix.Matrices.random(n,n); C = matrix.Matrices.random(n,n); alpha = Math.random() beta = Math.random() print "Random numbers time: "+str((time.time() - t)) for i in range(10): #BLAS.gemm(BLAS.ColMajor, BLAS.NoTrans, BLAS.NoTrans, n, n, n, alpha, A, n, B, n, beta, C, n) A.multAdd(alpha,B, C) C.scale(beta); #E=D.mult(C, C.copy()) t = time.time() for i in range(r): #BLAS.gemm(BLAS.ColMajor, BLAS.NoTrans, BLAS.NoTrans, n, n, n, alpha, A, n, B, n, beta, C, n) #D=A.mult(B, B.copy()); E=D.mult(C, C.copy()); A.multAdd(alpha,B, C) C.scale(beta); s = (time.time() - t) print s f = 2 * (n + 1) * n * n mfs = (f / (s * 1000000.0)) * r print str(mfs)
def generateData(self, channel, numofpoints): if self.useGaussian: for i in range(numofpoints): self.resetGaussian(i) baseValue = self.gaussian.yAtX(i + 1) # print channel, baseValue, i self.data.append( self.round( (baseValue + channel) * (1.0 + self.noiseLevel * (2.0 * Math.random() - 1.0)))) else: for i in range(numofpoints): self.data.append( self.round(int(Math.random() * 10.0) * (i + 1))) # print channel, self.data return self.data
def randomString(length, type): INTEGERS = '0123456789' #ALPHA = 'abcdefghijklmnopqrstuvwxyz' ALPHANUM = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789' VALUES = None if (type == "integer"): VALUES = INTEGERS else: VALUES = ALPHANUM str = "" for i in range(length): pos = (int)(Math.random() * len(VALUES)) str += VALUES[pos] if (type is "upper"): return str.upper() return str
from org.csstudio.opibuilder.scriptUtil import PVUtil from org.csstudio.opibuilder.scriptUtil import ColorFontUtil from org.eclipse.jface.dialogs import MessageDialog from java.lang import Math if Math.random() > 0.5: color = ColorFontUtil.getColorFromRGB(0,160,0) colorName = "green" else: color = ColorFontUtil.RED colorName = "red" import WidgetUtil WidgetUtil.setBackColor(display, "myIndicator", color) WidgetUtil.setMyForeColor(widget, color) MessageDialog.openInformation( None, "Dialog from Python Script", "Python says: my color is " + colorName);
def nextInt(self): return Math.random() * self.multiplier
def createValueList(d, d1, i): arraylist = ArrayList() for j in range(0, i):#Generate 20 values for each serie d2 = d + Math.random() * (d1 - d) arraylist.add(Double(d2)) return arraylist
from org.csstudio.opibuilder.scriptUtil import PVUtil from org.csstudio.opibuilder.scriptUtil import ColorFontUtil from org.eclipse.jface.dialogs import MessageDialog from java.lang import Math if Math.random() > 0.5: color = ColorFontUtil.getColorFromRGB(0, 160, 0) colorName = "green" else: color = ColorFontUtil.RED colorName = "red" import WidgetUtil WidgetUtil.setBackColor(display, "myIndicator", color) WidgetUtil.setMyForeColor(widget, color) MessageDialog.openInformation(None, "Dialog from Python Script", "Python says: my color is " + colorName)