Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. Okay I changed the code a bit: function changeColor(color) { ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.drawImage(img, 0, 0); var imgData = ctx.getImageData(0, 0, canvas.width, canvas.height); var data = imgData.data, red, green, blue, alpha; var rgb = HexToRGB(color); var hsl = rgbToHsl(rgb.R, rgb.G, rgb.B); for (var i = 0, l = data.length; i < l; i += 4) { red = data[i]; green = data[i + 1]; blue = data[i + 2]; alpha = data[i + 3]; if (alpha < 200) continue; var imgHsl = rgbToHsl(red, green, blue); var newRgb = hslToRgb(hsl.h, hsl.s, imgHsl.l); data[i] = newRgb.r; data[i + 1] = newRgb.g; data[i + 2] = newRgb.b; data[i + 3] = 255; } ctx.putImageData(imgData, 0, 0); }This works for some reason well, I can now create blackish and brownish cars. White however I can't get to work. Because I maintain the luminance of the original image (which is red) the black or brown also appears lighter, so I somehow would need to adjust the luminance of the car according to the color I selected. For dark colors, make it darker, for lighter colors make it lighter. I also can't help but feel that this sort of thing has to be in some sort of game library but I tried EaselJS and THREE but none appear to have this feature.
  2. Hi, I am building a 2D car configurator and I need some help with the coloring. Currently I am using this technique to color the car: http://jsfiddle.net/m1erickson/2d7ZN/ But now I am wondering how can I select a color using a color picker like this: <form action="" method="post"> <label for="color">Pick color</color> <input type="color" name="color" id="color"> </form>And then transform the selected color to match the car's (thus keeping the reflection). I am not looking specifically for code more the name of the algorithm or technique to get me on my way. I am guessing it's something with taking the RGB value of a pixel of the car and then somehow closely represent this color in the other color. Entering that in Google returns squat. Maybe one of you have experience in this sort of thing?
  3. If you want to assign energy points to players every 5 minutes you'll need something like a cronjob that runs a script that awards energy points every 5 minutes. Something like: */5 * * * * mysql -uMyUsername -pMyPassword -e 'UPDATE players SET energy_points += 1' mydbnameTo train a specific stat you can then create a simple form where they select a stat and that stat gets 'trained'. That's basically it.
  4. If you have the finances you can find someone to develop it for you but then of course you need to be sure of a return on investment. Otherwise it becomes a blackhole where you throw money at. There are more efficient ways to make money with money (investing et al). If you want to learn how to develop a game go to https://unity3d.com/learn/tutorials. It contains tutorials on how to get started. If you need models you can also buy them here: https://www.assetstore.unity3d.com/en/ Though I would keep it 'free' for as long as possible (having 2 squares fight each other is fine for a prototype). A game that costs you thousands but never provide any returns isn't a good investment even if you have a great cashflow.
  5. If the problem persists to elude you. You can take the agile approach and use iterative development to get to the solution. What this means is that you start with very simple code that could work. For example a simple array with a mapping between products and tags/categories: <?php $tags = array( 'woman' => 'Woman (16 - 35)', 'infant' => 'Infant (0 - 1)', 'child' => 'Child (1 - 4)', .. ); return array( 11 => array( // assume 11 = product baby cream $tags['woman'], $tags['infant'], ), .. );Then in your code: <?php class ShoppingCartEvaluatorImpl implements ShoppingCartEvaluator { public function __construct(array $mappings) { $this->mappings = $mappings; } public function evaluateShoppingCart(ShoppingCart $cart) { // .. } } // in your shopping cart $evaluator = new ShoppingCartEvaluatorImpl(require '/path/to/product-mappings.php'); $evaluator->evaluateShoppingCart($cart);
  6. OT: It's less work and more precise to simply link your products to possible advertising directly. Instead of using pseudo-meta information that has several conceptual flaws. Like requinix pointed out that baby cream could be linked to either a mother between the age of 16 and 35 and an old man of 60+. This couldn't be more far apart. I understand this is homework and you won't have any say in the matter but nonetheless. Requinix already gave you the solution though I wouldn't generalize. So instead of simply stating Woman as a profile. I would add 'Mother (16 - 35)', 'Elderly man (60+)' etc.. Then for each new product that gets added like diapers for example will only contain 'Mother (16 - 35)' and do a array_intersect. So that 'Elderly man (60+)' gets excluded. As where Cane for example would exclude Mother. I wouldn't simply drop the excluded tags but keep them in a separate array as a second source of meta information (hard versus soft tags). For baby cream and diapers: Hard tags: Mother (16 - 35), Baby (0 - 4) Soft tags: Elderly man (60+)
  7. There's no need to re-invent the wheel: APIgility provides an API out-of-the-box. RESTler transforms your classes into REST objects. DREST does the same thing but for Doctrine entities. If you use Symfony, you can add the SyliusResourceBundle which is similar to DREST as it provides CRUD for Doctrine entities.
  8. Your application should only be database aware, not be the database. Define your database with proper referential integrity, events, views, and procedures as the database is optimised for this type of task. Your application should only know it's interface like every other REST API out there. If you use a (powerful) ORM you'll be able to translate these procedures and views to entities using a ResultSetMapper. Just like you would map an entity from a request when interfacing with a REST API. Now that you know this on to your question. ON DELETE [CASCADE|RESTRICT|SET NULL] depends on how the relations between your rows exists: ON DELETE CASCADE: You use this when it makes no sense to keep the child row if the parent row is removed. For example an OrderLine and an Order. If you don't have the Order, then having the OrderLine's makes no sense. ON DELETE RESTRICT: Like was already explained it simply prohibits you to delete a parent if it has childs. Just like you can't delete a directory if it contains files. You need to move or delete the dependent rows first in order to remove the parent. This is the default behaviour and you'll get a "Cannot add or update a child row: a foreign key contraint fails" if you do. ON DELETE SET NULL: This is useful for optional relationships. For example between a Customer and a Cart. If the Customer currently has a Cart the field contains a FK to the Cart.Id. If the Customer on the other hand does not have a Cart this is simply NULL and a Cart can be assigned. The Customer can exist regardless if he has a Cart or not. In order to impose theses restrictions you need to know how the relationships are between your data.
  9. I think most people simply misunderstood MVC because it's so dead simple. Only the View and Model part are significant, the Controller is nothing more but glue between them. In my career I never met anyone who understood MVC (and I simply assumed I understood by assuming that if their controllers had more code then their models, they were wrong). Even in the academic sphere when I was taught Java and .NET, their controllers were littered with model logic and their models mere data placeholders. One of those teachers even went as far as simply making every class static and just call them anywhere, everywhere. At that point I knew that self-taught was the way to go. And not all frameworks break the rules (I think none of them do). The one I show above is Symfony. Of course anyone can abuse a framework and put their model logic in their controllers. But I get why you think that, because a framework caters to all. And when you create something very simple there's no need to be all architect about it.
  10. Should validation be handled by your controller? No, because depending on the number of systems there may be more then 1 controller accepting the same data. Is validation part of the model? Yes. Don't get caught up on details. - View is what shows the response to a request of the user. - Controller is what accepts requests and acts upon them. - Model is everything else. That said, you should keep in mind to keep your controller code to a minimum. Because too much code in the controller means that you'll be copy-pasting a lot between controllers. Encapsulate (that means put it in a class) if you write something more then 2 times. You'll probably have come across services (if you are into SOA, (pun side note: in Belgium this is short for STD)). These services are a Facade to the model and mostly accept scalars (think productId). class UserController { public function registerAction(Request $request) { $service = $this->get('service.registration'); $form = $this->createForm('signup_form'); // another service $form->handleRequest($request); if ($form->isValid()) { $service->register($form->getData()); } return $this->render('register.html'); // return Response object } }Suppose that at some time you switch to AngularJS and use a REST back-end your code won't look much different: class RESTUserController { public function postUserAction(Request $request) { $service = $this->get('service.registration'); $form = $this->createForm('signup_form'); $form->handleRequest($request); if ($form->isValid()) { $service->register($form->getData()); } return $this->redirect('users_list'); }I say the $form is a service here, even though conceptually it's a client thing, it models how a client enters information into the system. It validates and turns the scalar input of the client into a model your system can work with.
  11. Our database only has that yes. requinix however has everything else. he knows where you live!!!!
  12. You don't need to worry about someone copying your code. We all suffer from Not Invented Here syndrome, so rest assured. And I am the guy who constanly keep telling everyone they SHOULD use other people's code (if available, well-tested, and adheres to some standard). Like minded people created an entire tool for plagiarists to do plagiarism and then sell it off as their own: $ composer require your/code
  13. Congratulations, you now know how the law works!
  14. So you want to school us on security. Let me school you how this works: 1. This website is owned by this guy and hasn't been around like forever and we have basically zero access to the server. 2. We are volunteers and do not get paid (that means people like you or those that cook soup for the homeless) 3. This is a forum for which the license costs 175$ which we need to pay for, while all profits of the ads go directly to no-show. 4. Be grateful you piece of sh*t instead of trying to school professionals that have lives just like you and donate their time and money to help people like you ALL FREE OF CHARGE!!! You are that homeless guy that complains when he finds a fly in his soup!
  15. Makes your requests per minute go over 9000!
  16. Here are the answers for reference: There are 4 in total: 1. Abstraction 2. Inheritance 3. Polymorphism 4. Encapsulation USE database_name; SHOW TABLES;
  17. $tmp = tmpfile(); fwrite($tmp, 'Hello, World!'); readfile(stream_get_meta_data($tmp)['uri']); fclose($tmp);
  18. Just add this to your code. GetSomeActualDeveloper()->solve($problem);
  19. There have been efforts to create a new front-end but we had to realize we all have busy lives. There is currently a private repo on github for the new front-end but nothing is happening currently.
  20. Can you show us your PHP project? And is this $99 per hour or per 10 hours? If this is per hour for a junior developer, then good luck landing a job. Also do you have a VAT registration number?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.