2d

Allocate 2D Array on Device Memory in CUDA

穿精又带淫゛_ 提交于 2019-11-27 19:07:42
How do I allocate and transfer(to and from Host) 2D arrays in device memory in Cuda? Gitmo I found a solution to this problem. I didn't have to flatten the array. The inbuilt cudaMallocPitch() function did the job. And I could transfer the array to and from device using cudaMemcpy2D() function. For example cudaMallocPitch((void**) &array, &pitch, a*sizeof(float), b); This creates a 2D array of size a*b with the pitch as passed in as parameter. The following code creates a 2D array and loops over the elements. It compiles readily, you may use it. #include<stdio.h> #include<cuda.h> #define

Android - How to draw an arc based gradient

谁说我不能喝 提交于 2019-11-27 18:34:06
I am trying to create an arc (variable number of degrees) that gradually goes from one color to another. From example from blue to red: This is my code: SweepGradient shader = new SweepGradient(center.x, center.y, resources.getColor(R.color.startColor),resources.getColor(R.color.endColor)); Paint paint = new Paint() paint.setStrokeWidth(1); paint.setStrokeCap(Paint.Cap.FILL); paint.setStyle(Paint.Style.FILL); paint.setShader(shader); canvas.drawArc(rectF, startAngle, sweepAngle, true, paint); But the result is the entire arc is painted with the same color. Edit: After more experimenting, I

Finding closest non-black pixel in an image fast

一笑奈何 提交于 2019-11-27 18:20:44
问题 I have a 2D image randomly and sparsely scattered with pixels. given a point on the image, I need to find the distance to the closest pixel that is not in the background color (black). What is the fastest way to do this? The only method I could come up with is building a kd-tree for the pixels. but I would really want to avoid such expensive preprocessing. also, it seems that a kd-tree gives me more than I need. I only need the distance to something and I don't care about what this something

Declare an empty two-dimensional array in Javascript?

余生颓废 提交于 2019-11-27 18:18:06
I want to create a two dimensional array in Javascript where I'm going to store coordinates (x,y). I don't know yet how many pairs of coordinates I will have because they will be dynamically generated by user input. Example of pre-defined 2d array: var Arr=[[1,2],[3,4],[5,6]]; I guess I can use the PUSH method to add a new record at the end of the array. How do I declare an empty two dimensional array so that when I use my first Arr.push() it will be added to the index 0, and every next record written by push will take the next index? This is probably very easy to do, I'm just a newbie with JS

Java 2D Game engine for tile-based Game

非 Y 不嫁゛ 提交于 2019-11-27 18:08:33
问题 Can anyone recommend a good Java game engine for developing simple tile-based games? I'm looking for an engine that will allow me to build maps using something like Tiled www.mapeditor.org Slick is exactly what I'm looking for, slick.cokeandcode.com but I can't get it working on Vista-64. The best I can manage is:Can't load IA 32-bit .dll on a AMD 64-bit platform (and this after downloading the latest LWJGL version). Can anyone suggest something similar that will run on 64-bit vista? 回答1: I'd

LibGDX - Application crashes when call TiledMapRenderer.render()

余生长醉 提交于 2019-11-27 16:38:24
问题 @Override public void render(float delta) { Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); camera.update(); sprite.setProjectionMatrix(camera.combined); mLevel.getTiledMapRenderer().getProjectionMatrix().set(camera.combined); Vector3 tmp = new Vector3(); tmp.set(0, 0, 0); camera.unproject(tmp); mLevel.getTiledMapRenderer().render(tmp.x, tmp.y, camera.viewportWidth, camera.viewportHeight); sprite.begin(); ... sprite.end(); } Here is what I get when launching the desktop version : Exception in

Need to store a 2d list but not using array

不羁的心 提交于 2019-11-27 16:32:47
Consider that I have a txt file containing data of the following format: "Home" "A1" "Car" "A2" "Home" "B1" "Home" "A1" "Car" "A2" "Man" "B1" How I can store this kind of data and also in sorted format, without duplicate data? But The first and third element must not be deleted as they are different with 2nd parameter (repetition of second parameter is allowed but not both 1st and 2nd). Please suggest any better collection from Java suitable. Also please give an example as I am new to Java. Best option in Java is a Map<String, String> . As is so urgent, take a look by yourself in the MAP API

Bezier clipping

荒凉一梦 提交于 2019-11-27 16:04:12
问题 I'm trying to find/make an algorithm to compute the intersection (a new filled object) of two arbitrary filled 2D objects. The objects are defined using either lines or cubic beziers and may have holes or self-intersect. I'm aware of several existing algorithms doing the same with polygons, listed here. However, I'd like to support beziers without subdividing them into polygons, and the output should have roughly the same control points as the input in areas where there are no intersections.

OpenGL stretched shapes - aspect ratio

风格不统一 提交于 2019-11-27 11:59:06
I got my openGL view at a size of (lets say..) 800(width)x600(height). Then i got a 2D object of coords: 0.0 , 0.0 0.1 , 0.0 0.1 , 0.1 0.0 , 0.1 this, as you understand is supposed to be a square (based on analogy). But on my openGL view prints this stretched. Now, i understand why this is happening. Its basically because im working on the default matrix of -1,1. And since my resolution of 800x600 doesnt have an aspect ratio of 1, my shape is getting stretched. Now im more interested on how to fix this. Ive read about functions like glFrustum, glOrtho, glViewPort which are happening on the

How do i tint an image with HTML5 Canvas?

落花浮王杯 提交于 2019-11-27 11:56:13
My question is, what is the best way to tint an image that is drawn using the drawImage method. The target useage for this is advanced 2d particle-effects (game development) where particles change colors over time etc. I am not asking how to tint the whole canvas, only the current image i am about to draw. I have concluded that the globalAlpha parameter affects the current image that is drawn. //works with drawImage() canvas2d.globalAlpha = 0.5; But how do i tint each image with an arbitrary color value ? It would be awesome if there was some kind of globalFillStyle or globalColor or that kind