Tutorial by Examples: 2d

using System.Runtime.InteropServices; class PInvokeExample { [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern uint MessageBox(IntPtr hWnd, String text, String caption, int options); public static void test() { MessageBox(IntPtr.Zero,...
This example will show you how to create a simple animation using the canvas and the 2D context. It is assumed you know how to create and add a canvas to the DOM and obtain the context // this example assumes ctx and canvas have been created const textToDisplay = "This is an example that uses...
In MATLAB versions prior to R2014b, using the old HG1 graphics engine, it was not obvious how to create color coded 2D line plots. With the release of the new HG2 graphics engine arose a new undocumented feature introduced by Yair Altman: n = 100; x = linspace(-10,10,n); y = x.^2; p = plot(x,y,'r...
You can use raycasts to check if an ai can walk without falling off the edge of a level. using UnityEngine; public class Physics2dRaycast: MonoBehaviour { public LayerMask LineOfSightMask; void FixedUpdate() { RaycastHit2D hit = Physics2D.Raycas...
// A fixed size raw array matrix (that is, a 2D raw array). #include <iostream> #include <iomanip> using namespace std; auto main() -> int { int const n_rows = 3; int const n_cols = 7; int const m[n_rows][n_cols] = // A raw array matrix. ...
The objects created within a Tiled Map (.tmx), can be simply loaded as bodies into a Box2D world using the Libgdx MapObject class as following: public void buildBuildingsBodies(TiledMap tiledMap, World world, String layer){ MapObjects objects = tiledMap.getLayers().get(layer).getObjects(); ...
This can be done with a bit of modification in the above regex ^(?=.{10,}$)(?=(?:.*?[A-Z]){2})(?=.*?[a-z])(?=(?:.*?[0-9]){2}).*$ or ^(?=.{10,}$)(?=(?:.*[A-Z]){2})(?=.*[a-z])(?=(?:.*[0-9]){2}).* Let's see how a simple regex ^(?=(?:.*?[A-Z]){2}) works on string abcAdefD Image Credit :- ht...
For more complex applications, flat execution profiles may be difficult to follow. This is why many profiling tools also generate some form of annotated callgraph information. gperf2dot converts text output from many profilers (Linux perf, callgrind, oprofile etc.) into a callgraph diagram. You can...
Like for 1D signals, it's possible to filter images by applying a Fourier transformation, multiplying with a filter in the frequency domain, and transforming back into the space domain. Here is how you can apply high- or low-pass filters to an image with Matlab: Let image be the original, unfiltere...
Sprite animation consists in showing an existing sequence of images or frames. First import a sequence of images to the asset folder. Either create some images from scratch or download some from the Asset Store. (This example uses this free asset.) Drag every individual image of a single animati...
db.collection.createIndex() method is used to create a 2dsphere index. The blueprint of a 2dsphere index : db.collection.createIndex( { <location field> : "2dsphere" } ) Here, the location field is the key and 2dsphere is the type of the index. In the following example we are goi...
NOTE: for best results, make sure your project was created using the Angular-CLI. npm install angular/{core,common,compiler,platform-browser,platform-browser-dynamic,http,router,forms,compiler-cli,tsc-wrapped,platform-server} You don't have to do this step if you project already has angular 2 an...
Passing a 2d array to a functions seems simple and obvious and we happily write: #include <stdio.h> #include <stdlib.h> #define ROWS 3 #define COLS 2 void fun1(int **, int, int); int main() { int array_2D[ROWS][COLS] = { {1, 2}, {3, 4}, {5, 6} }; int n = ROWS; int m...
We initialize the data: [X,Y] = meshgrid(1:2:10); Z = X.*cos(Y) - Y.*sin(X); The surface looks like the following. Now we set the points where we want to interpolate: [Vx,Vy] = meshgrid(1:0.25:10); We now can perform nearest interpolation, Vz = interp2(X,Y,Z,Vx,Vy,'nearest'); line...
Most of the time, we'll need to find out the shortest path from single source to all other nodes or a specific node in a 2D graph. Say for example: we want to find out how many moves are required for a knight to reach a certain square in a chessboard, or we have an array where some cells are blocked...
Often the easiest solution is simply to pass 2D and higher arrays around as flat memory. /* create 2D array with dimensions determined at runtime */ double *matrix = malloc(width * height * sizeof(double)); /* initialise it (for the sake of illustration we want 1.0 on the diagonal) */ int x, y...
In this Example we are going to take a sqaure shaped line plotted using line and perform transformations on it. Then we are going to use the same tranformations but in different order and see how it influences the results. First we open a figure and set some initial parameters (square point coordin...
Display a two dimensional (2D) array on the axes. import numpy as np from matplotlib.pyplot import imshow, show, colorbar image = np.random.rand(4,4) imshow(image) colorbar() show()
Example of how to calculate the output shape and overcome the difficulties of using tf.nn.conv2d_transpose with unknown batch size (when input.get_shape() is (?, H, W, C) or (?, C, H, W)). def upconvolution (input, output_channel_size, filter_size_h, filter_size_w, stride_h, str...
Datepicker allow the user to select date and time. <md2-datepicker [(ngModel)]="date"></md2-datepicker> see for more details here

Page 1 of 2