Search Results

Search found 7897 results on 316 pages for 'generate'.

Page 31/316 | < Previous Page | 27 28 29 30 31 32 33 34 35 36 37 38  | Next Page >

  • Generate custom marker (icon) out of two images in Leaflet

    - by Rmatt
    In Javascript/CoffeeScript, using Leaflet to display a map, I would like to have custom markers out of a two custom images, and also featuring a shadow for the pin : I want to have a "background" image with a color (or shape) to identify the category On top, I want to have inside this image a specific image (logo) for each pin I didn't find out how I could do that... Setting one image is quite easy but I don't know how to overlay them. I could also consider using a tool to superpose/group/overlay these images (locally ?) before in order to send only one to the Icon Leaflet Class, but also there, I wouldn't know which tool to use. Nevertheless, I still think that a double overlay would be more efficient and that my case could be useful for several people.

    Read the article

  • Generate a valid array key from an URL string in PHP

    - by John Riche
    I have a PHP array with some predefined values: $aArray = array( 0 => 'value0', 1 => 'value1' ); I need to create a function where the string input will always return the same, valid, array key so that when I call: GiveMeAKey('http://www.google.com'); // May return 0 or 1 I receive always the same key (I don't care which one) from the array. Obvisously I can't store the relationship in a database and the string passed to the GiveMeAKey method can be any URL. I wonder if there is a way of doing that ?

    Read the article

  • Why does coffeescript generate classes like this?

    - by ryeguy
    Given the following coffeescript code: class Animal constructor: (@name) -> speak: (things) -> "My name is #{@name} and I like #{things}" This is generated: var Animal = (function() { function Animal(name) { this.name = name; } Animal.prototype.speak = function(things) { return "My name is " + this.name + " and I like " + things; }; return Animal; })(); But why isn't this more idiomatic code generated? var Animal = function Animal(name) { this.name = name; }; Animal.prototype.speak = function(things) { return "My name is " + this.name + " and I like " + things; }; I know that coffeescript wraps a lot of stuff in anonymous functions to control scope leak, but what could leak here?

    Read the article

  • Generate form based on selection

    - by Jay
    I'm looking to build a web application that allows a person to select a plan and fill out an application for that plan. There are multiple plans and each plan generates a different application. Some of the questions are identical such as fields related to personal information. I'm thinking of using ASP.NET MVC to build this web application. When generating the multi page application would it be best to Create partial views (sections of applications) and combine them when generating the form. OR Build some type of dynamic form generator

    Read the article

  • generate random characters in c

    - by Nick
    I'm new to programming in C and have been given the task of creating a 2D array that stores random letters from A-Z using the random () function. I know how to do random numbers. nextvalue = random ( ) % 10001; but am unsure on how exactly to create a random character. I know that you can use ASCII to create a random character using the range 65 - 90 in the ASCII table. Can anyone help me come up with a solution? I would greatly appreciate it.

    Read the article

  • Dynamically Generate Multi-Dimensional Array in Ruby

    - by user335729
    Hi, I'm trying to build a multidimensional array dynamically. What I want is basically this (written out for simplicity): b = 0 test = [[]] test[b] << ["a", "b", "c"] b += 1 test[b] << ["d", "e", "f"] b += 1 test[b] << ["g", "h", "i"] This gives me the error: NoMethodError: undefined method `<<' for nil:NilClass. I can make it work by setting up the array like test = [[], [], []] and it works fine, but in my actual usage, I won't know how many arrays will be needed beforehand. Is there a better way to do this? Thanks

    Read the article

  • Generate 3 random number that sum to 1 in R

    - by user1034797
    I am hoping to create 3 (non-negative) quasi-random numbers that sum to one, and repeat over and over. Basically I am trying to partition something into three random parts over many trials. While I am aware of a= runif(3,0,1) I was thinking that I could use 1-a as the max in the next run if, but it seems messy. But these of course don't sum to one. Any thoughts, oh wise stackoverflow-ers?

    Read the article

  • how to generate XML (in String representation) in java

    - by flyingfromchina
    I have defined a java class, but only need to output some of the fields of this class into an XML. The returned type must be a String. I first opted for the easiest way using a StringBuffer. However, when I tried to process the output String represenation, it failed. I think it is mostly likely because there are some characters that are not encoded in the UTF-8 in the input. Could someone tell me what is the best way to handle this? Thanks.

    Read the article

  • how to generate random bubbles from array of sprites in cocos2d?

    - by prakash s
    I am devoloping the bubble shooter game in cocos2d how to generate random bubbles from array of sprites here is my code (void)addTarget { CGSize winSize = [[CCDirector sharedDirector] winSize]; //CCSprite *target = [CCSprite spriteWithFile:@"3.png" rect:CGRectMake(0, 0, 256, 256)]; NSMutableArray * movableSprites = [[NSMutableArray alloc] init]; NSArray *images = [NSArray arrayWithObjects:@"1.png", @"2.png", @"3.png", @"4.png",@"5.png",@"1.png",@"5.png", @"3.png", nil]; for(int i = 0; i < images.count; ++i) { NSString *image = [images objectAtIndex:i]; // generate random number based on size of array (array size is larger than 10) CCSprite*target = [CCSprite spriteWithFile:image]; float offsetFraction = ((float)(i+1))/(images.count+1); target.position = ccp(winSize.width*offsetFraction, winSize.height/2); target.position = ccp(350*offsetFraction, 460); [self addChild:target]; [movableSprites addObject:target]; //[target runAction:]; id actionMove = [CCMoveTo actionWithDuration:10 position:ccp(winSize.width/2,winSize. height/2)]; This code generating bubbles with *.png colour bubbles but i want to generate randomly because for shooting the bubbles by shooter class help me please id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)]; [target runAction:[CCSequence actions:actionMove, actionMoveDone, nil]]; } }

    Read the article

  • SQL Server: How do I generate the table schema and populate it with inserts in a script?

    - by Paula DiTallo
    Originally posted on: http://geekswithblogs.net/AskPaula/archive/2014/05/20/156469.aspx In SSMS, there's a Generate Script utility (read:  only available under version 2008 and up) . Here are the steps you would need to take to make use of the utility: Right click on the database you're interested in and go to Tasks -> Generate ScriptsSelect the tables and/or any other objects you'd like in order to get them into the script.Navigate to Set scripting options. Click on Advanced.Under the General category, navigate to Type of data to scriptSelect the Schema and Data option to get the insert statements generated. Click OK.

    Read the article

  • How do I generate terrain like that of Scorched Earth?

    - by alex
    Hi, I'm a web developer and I am keen to start writing my own games. For familiarity, I've chosen JavaScript and canvas element for now. I want to generate some terrain like that in Scorched Earth. My first attempt made me realise I couldn't just randomise the y value; there had to be some sanity in the peaks and troughs. I have Googled around a bit, but either I can't find something simple enough for me or I am using the wrong keywords. Can you please show me what sort of algorithm I would use to generate something in the example, keeping in mind that I am completely new to games programming (since making Breakout in 2003 with Visual Basic anyway)?

    Read the article

  • How do I randomly generate a top-down 2D level with separate sections and is infinite?

    - by Bagofsheep
    I've read many other questions/answers about random level generation but most of them deal with either randomly/proceduraly generating 2D levels viewed from the side or 3D levels. What I'm trying to achieve is sort of like you were looking straight down on a Minecraft map. There is no height, but the borders of each "biome" or "section" of the map are random and varied. I already have basic code that can generate a perfectly square level with the same tileset (randomly picking segments from the tileset image), but I've encountered a major issue for wanting the level to be infinite: Beyond a certain point, the tiles' positions become negative on one or both of the axis. The code I use to only draw tiles the player can see relies on taking the tiles position and converting it to the index number that represents it in the array. As you well know, arrays cannot have a negative index. Here is some of my code: This generates the square (or rectangle) of tiles: //Scale is in tiles public void Generate(int sX, int sY) { scaleX = sX; scaleY = sY; for (int y = 0; y <= scaleY; y++) { tiles.Add(new List<Tile>()); for (int x = 0; x <= scaleX; x++) { tiles[tiles.Count - 1].Add(tileset.randomTile(x * tileset.TileSize, y * tileset.TileSize)); } } } Before I changed the code after realizing an array index couldn't be negative my for loops looked something like this to center the map around (0, 0): for (int y = -scaleY / 2; y <= scaleY / 2; y++) for (int x = -scaleX / 2; x <= scaleX / 2; x++) Here is the code that draws the tiles: int startX = (int)Math.Floor((player.Position.X - (graphics.Viewport.Width) - tileset.TileSize) / tileset.TileSize); int endX = (int)Math.Ceiling((player.Position.X + (graphics.Viewport.Width) + tileset.TileSize) / tileset.TileSize); int startY = (int)Math.Floor((player.Position.Y - (graphics.Viewport.Height) - tileset.TileSize) / tileset.TileSize); int endY = (int)Math.Ceiling((player.Position.Y + (graphics.Viewport.Height) + tileset.TileSize) / tileset.TileSize); for (int y = startY; y < endY; y++) { for (int x = startX; x < endX; x++) { if (x >= 0 && y >= 0 && x <= scaleX && y <= scaleY) tiles[y][x].Draw(spriteBatch); } } So to summarize what I'm asking: First, how do I randomly generate a top-down 2D map with different sections (not chunks per se, but areas with different tile sets) and second, how do I get past this negative array index issue?

    Read the article

  • Is it feasible and useful to auto-generate some code of unit tests?

    - by skiwi
    Earlier today I have come up with an idea, based upon a particular real use case, which I would want to have checked for feasability and usefulness. This question will feature a fair chunk of Java code, but can be applied to all languages running inside a VM, and maybe even outside. While there is real code, it uses nothing language-specific, so please read it mostly as pseudo code. The idea Make unit testing less cumbersome by adding in some ways to autogenerate code based on human interaction with the codebase. I understand this goes against the principle of TDD, but I don't think anyone ever proved that doing TDD is better over first creating code and then immediatly therafter the tests. This may even be adapted to be fit into TDD, but that is not my current goal. To show how it is intended to be used, I'll copy one of my classes here, for which I need to make unit tests. public class PutMonsterOnFieldAction implements PlayerAction { private final int handCardIndex; private final int fieldMonsterIndex; public PutMonsterOnFieldAction(final int handCardIndex, final int fieldMonsterIndex) { this.handCardIndex = Arguments.requirePositiveOrZero(handCardIndex, "handCardIndex"); this.fieldMonsterIndex = Arguments.requirePositiveOrZero(fieldMonsterIndex, "fieldCardIndex"); } @Override public boolean isActionAllowed(final Player player) { Objects.requireNonNull(player, "player"); Hand hand = player.getHand(); Field field = player.getField(); if (handCardIndex >= hand.getCapacity()) { return false; } if (fieldMonsterIndex >= field.getMonsterCapacity()) { return false; } if (field.hasMonster(fieldMonsterIndex)) { return false; } if (!(hand.get(handCardIndex) instanceof MonsterCard)) { return false; } return true; } @Override public void performAction(final Player player) { Objects.requireNonNull(player); if (!isActionAllowed(player)) { throw new PlayerActionNotAllowedException(); } Hand hand = player.getHand(); Field field = player.getField(); field.setMonster(fieldMonsterIndex, (MonsterCard)hand.play(handCardIndex)); } } We can observe the need for the following tests: Constructor test with valid input Constructor test with invalid inputs isActionAllowed test with valid input isActionAllowed test with invalid inputs performAction test with valid input performAction test with invalid inputs My idea mainly focuses on the isActionAllowed test with invalid inputs. Writing these tests is not fun, you need to ensure a number of conditions and you check whether it really returns false, this can be extended to performAction, where an exception needs to be thrown in that case. The goal of my idea is to generate those tests, by indicating (through GUI of IDE hopefully) that you want to generate tests based on a specific branch. The implementation by example User clicks on "Generate code for branch if (handCardIndex >= hand.getCapacity())". Now the tool needs to find a case where that holds. (I haven't added the relevant code as that may clutter the post ultimately) To invalidate the branch, the tool needs to find a handCardIndex and hand.getCapacity() such that the condition >= holds. It needs to construct a Player with a Hand that has a capacity of at least 1. It notices that the capacity private int of Hand needs to be at least 1. It searches for ways to set it to 1. Fortunately it finds a constructor that takes the capacity as an argument. It uses 1 for this. Some more work needs to be done to succesfully construct a Player instance, involving the creation of objects that have constraints that can be seen by inspecting the source code. It has found the hand with the least capacity possible and is able to construct it. Now to invalidate the test it will need to set handCardIndex = 1. It constructs the test and asserts it to be false (the returned value of the branch) What does the tool need to work? In order to function properly, it will need the ability to scan through all source code (including JDK code) to figure out all constraints. Optionally this could be done through the javadoc, but that is not always used to indicate all constraints. It could also do some trial and error, but it pretty much stops if you cannot attach source code to compiled classes. Then it needs some basic knowledge of what the primitive types are, including arrays. And it needs to be able to construct some form of "modification trees". The tool knows that it needs to change a certain variable to a different value in order to get the correct testcase. Hence it will need to list all possible ways to change it, without using reflection obviously. What this tool will not replace is the need to create tailored unit tests that tests all kinds of conditions when a certain method actually works. It is purely to be used to test methods when they invalidate constraints. My questions: Is creating such a tool feasible? Would it ever work, or are there some obvious problems? Would such a tool be useful? Is it even useful to automatically generate these testcases at all? Could it be extended to do even more useful things? Does, by chance, such a project already exist and would I be reinventing the wheel? If not proven useful, but still possible to make such thing, I will still consider it for fun. If it's considered useful, then I might make an open source project for it depending on the time. For people searching more background information about the used Player and Hand classes in my example, please refer to this repository. At the time of writing the PutMonsterOnFieldAction has not been uploaded to the repo yet, but this will be done once I'm done with the unit tests.

    Read the article

  • Where to generate data in an Entity-Component System?

    - by Mark Mandel
    So I'm making a small game where I generate 2D landscape using perlin noise when the game first loads. I've got it working in a OO way, but want to move over to an ES architecure, and I'm just struggling to work out the right place for the code that does the generation to go? In OO world, I have a World object which gets passes a coordinate value that is used as the seed for the perlin noise, and generates all the points for the land mass when the world is created. I'm thinking I need a World component with a coordinate field on it - that's an easy part. From there - is it right for a component to generate data when it's first initialised (or is that too OO?)? Or should a System be doing that instead, when the game first starts? Or... some other solution I'm not aware of? Thanks in advance for any guidance.

    Read the article

  • How to generate a mixed-case hash in Python?

    - by pyrony
    I am having a hard time figuring out a reasonable way to generate a mixed-case hash in Python. I want to generate something like: aZeEe9E Right now I'm using MD5, which doesn't generate case-sensitive hashes. What is a good way to generate a hash value consisting of upper- and lower- case characters + numbers?

    Read the article

  • How can I generate a texture that looks like left-over tea leaves?

    - by Jedidja
    We are working on a project for iPhone and Windows Phone 7 where we'd like to be able to generate tea leaves at the bottom of a cup. It doesn't have to look photo-realistic, and actually cartoon-y is ok. What sort of techniques should we research to accomplish this? Are there any libraries (preferably in C, but we can translate) that would be helpful? Here are some samples pulled from a Google Image search

    Read the article

  • How to generate proxy for a child class when my web service return a parent class?

    - by Amir Borzoei
    Hi * I have a web method like this: public class ParentClass{ public String str1; } public class ChildClass : ParentClass{ public String str2; } public class WebService{ public ParentClass WebMethod(){ return GetFirstChildClass(); //Return a child class } } When I generate proxy for this web service by Visual Studio, VS just generate proxy for ParentClass but I need ChildClass too. For workaround I add a dummy method to WebService that return ChildClass to generate proxy for ChildClass in client. public class WebService{ ... //This is a dummy method to generate proxy for ChildClass in client. public ChildClass DummyWebMethod(){ return null; } } In addition I write web service in java (JAX-WS) and my client is a SilverLight Application. Is there a better solution for this problem? tanx for your help ;)

    Read the article

< Previous Page | 27 28 29 30 31 32 33 34 35 36 37 38  | Next Page >