Avançar para o conteúdo principal

Mensagens

A mostrar mensagens de 2018

Unity 3D Coroutines Part II

Coroutines are functions useful to implement tasks that need to happen across multiple frames. In this post we will see how to make the camera animate from one point to other across some time, the amount of time will be set in a variable so it can be changed. The function will be called when the user press the space bar. void Update () {         if (Input.GetKeyDown(KeyCode.Space))         {             if(func!=null)                 StopCoroutine(func);             func = StartCoroutine(smoothMoveCamera());// moveCamera());         } } We need some variables in the class:     public float duration = 2.0f;     public float xStart = -5.0f;     public float xFinish = 5.0f;     Coroutine func; The first variable sets the number of seconds the animation will endure. Second is the start point and the third the final point, both are points in the x axis. Then there's a reference to the coroutine so we can stop it if needed. The coroutine code is this:     IEnumer

Unity3D Coroutines

Coroutines are functions that maintain status while returning code execution to the method that called them. They are useful for the development of games to allow the execution of certain code over several frames. For example to animate the camera of the game we could execute the following code: for(int i=0;i<100;i++){     transform.position += new Vector3(1, 0,0); } If this code is within a function that is executed normally it is not possible to see the camera moving along the X axis since the game scenario update only occurs at the end of the cycle and not during the execution of this. In order to see the movement of the camera, it is necessary to perform an iteration of the cycle and then update the scene (rendering) and then continue the cycle with one more iteration and refresh the scene again, in this case what's needed is to interrupt the execution and to resume without losing the state, for this we can implement a coroutine. A coroutine is just an IEnumera

ASP.NET MVC with Entity, Identity and Migrations Part 3 - File Upload

In the third part of this MVC tutorial we add two new controllers and models with the ability to upload files to our web site. The Room model is pretty simple:  public class Room {         [Key]         public int nr { get; set; }         [Required(ErrorMessage = "Deve indicar o piso do quarto")]         public int piso { get; set; }         [Required(ErrorMessage = "Deve indicar a lotação")]         public int lotacao { get; set; }         [Required(ErrorMessage = "Deve indicar o estado do quarto")]         public bool estado { get; set; }         [DataType(DataType.Currency)]         [Required(ErrorMessage = "Deve indicar o preço por dia do quarto")]         public decimal custo_dia { get; set; }     } Just add the controller with Entity framework and that's it. Next add the Client model:     public class Client {         [Key]         public int ClientId { get; set; }         [Required(ErrorMessage = "Tem

TensorFlow Variables and Placeholders

In this second part of the introduction to TensorFlow we add two new node types: variables and placeholders. Let's use the same example that we have used in the first part. We start by importing TensorFlow: import tensorflow as tf Next we start a session, but before let's make a reset to the graph internal state: tf.reset_default_graph() sess=tf.Session() And now we create two variables of type 32 bit float: x = tf.Variable(2.0,tf.float32) y = tf.Variable(3.0,tf.float32) Since we are using variables we must initialize them: init = tf.global_variables_initializer() sess.run(init) The mathematical expression is this: sumnodes = x + y To evaluate the expression: print(sess.run(sumnodes)) Because we are using variables we can change the values like so: sess.run(x.assign(5.0)) As always we must execute the assign operation inside a TF session. To make multiple assigns we create references to the operations and execu

Introduction to TensorFlow - Part 1

"TensorFlow is an open source software library for numerical computation" in tensorflow.org In TensorFlow each node can be a constant, a variable or a numerical expression that uses variables and/or constants. This nodes can be executed in a CPU or a GPU taking advantage of multicore devices. Start by import the tensorflow library: import tensorflow as tf Create a constant with: node1 = tf.constant(3.0) or node2 = tf.constant(4.0, dtype=tf.float32) The first line allows tensorflow to guess the data type. Start a tensorflow session: sess = tf.Session() If you need to see the node type use: print(node1,node2) With this line you get to evaluate the nodes value: print(sess.run([node1,node2])) Create a mathematical function that adds the two constants with: sumnodes = tf.add(node1,node2) Evaluate the function: print(sess.run(sumnodes)) Youtube video: Code on GiHub How to install TensorFlow in Anaconda:

ASP.NET MVC with Entity, Identity and Migrations Part 2 - Dropdownlist

In the second part of this MVC tutorial we add a dropdown list to select the user role when creating or editing a user. In the User model we must add a new field that represents an interface that stores the options: public IEnumerable<System.Web.Mvc.SelectListItem> perfis { get; set; } Now in the User controller the Create and Edit functions must be changed. Each function must add the options to the perfis interface before showing the view. Something like this:         // GET: Users/Create         public ActionResult Create()         {             //perfis options for the dropdownlist             var user = new User();             user.perfis = new[] {                 new SelectListItem{Value="0",Text="Admin"},                 new SelectListItem{Value="1",Text="User"},             };             return View(user);         } In the views the text box must be deleted and a drop down must be added to the field. The line

ASP.NET MVC with Entity, Identity and Migrations

In this tutorial we explore the Microsoft MVC architecture with Entity framework, Identity framework and Migrations for the database manipulation. Entity framework is responsible for Object-Relational Mapping, i.e., storing objects in a relational SQL Server database, without SQL. Identity framework controls the user credentials, login and access control with different roles for each user. The database will be created with migrations (code first), we start by creating the class that represents the data in memory and then with migrations the table gets created. Checkout the video bellow The code is available on Github .

Decision Trees

In this article we create a decision tree to classify the gender of people based on their height, weight and size of footwear. To begin we import from the tree from framework sklearn. from sklearn import tree Then we create a vector X with the values ​​that allow us to create a trend. X=[[181,80,44],[177,70,43],[160,60,38],[154,54,37],[166,65,40],[190,90,47],[175,64,39],[177,70,40],[159,55,37],[171,75,42],[181,85,43]] To these values ​​we have to join the classification of each element, so we created the vector Y. Y=['male','female','female','female','male','male','male','female','male','female','male'] Now we can create an object of type DecisionTreeClassifier. clf=tree.DecisionTreeClassifier() We enter values ​​and ratings. clf=clf.fit(X,Y) Finally we can make a prediction based on a new example. prediction=clf.predict([[160,50,33]]) print(prediction) Just change the values ​​to get a diffe

Installing TensorFlow in Windows 10 with Anaconda

This video shows how to install TensorFlow in Windows 10 with Anaconda without the need to use the terminal window. Start by opening the Anaconda Navigator tool and create an Environment. Now, with the environment selected, search for the TensorFlow package e click install. Next install the Anaconda code editor, Spyder. When all is finished, update the TensorFlow version with this command:      conda install -c conda-forge tensorflow Don't forget that you must start Spyder through the terminal window of this environment, other wise it won't be running in the new environment and, for that, you must start the terminal window and type spyder.