the world is a pixel
Pointers to functions in C++
I need to implements some codes in C++. Just remembering some concepts like pointers to functions.
A simple example:
#include <stdlib.h>
#include <iostream>
using namespace std;
double evalFunction(double (*f)(double), double param){
return f(param);
}
double function(double x){
return x/2;
}
int main(int argc, char** argv) {
cout << function(5.0) << endl;
cout << evalFunction(function, 5.0) << endl;
return (EXIT_SUCCESS);
}
No comments yet.
You must be logged in to post a comment.
No trackbacks yet.
C# class properties example
15 December, 2011 - 12:26 pm
Tags: .Net, C, C-Sharp, celsius, fahrenheit, kelvin, temperature
Posted in english | No comments
A example of use of C# class properties to convert temperatures in Celsius, Fahrenheit or Kelvin. The temperature is encapsulated and stored in a internal representation, in this example, in Celcius (private double c). Each conversion is accessible by getting or setting a property. using System; public class Temperature { private double c; [...]
Python, flatten a list
Surprisingly python doesn’t have a shortcut for flatten a list (more generally a list of lists of lists of…). I made a simple implementation that doesn’t use recursion and tries to be written clearly. I get a element from a “bad” list (a list that can have another lists). If the element is not a [...]
OpenPixels: simple sprite sheet with Processing
22 August, 2011 - 10:54 pm
Tags: Openpixels, Pixelart, Processing, programming
Posted in english | No comments
/** * Openpixels example in Processing. * This simple example of how to get a sprite * from a sprite sheet. */ PImage bg; PImage sprite_sheet; PImage player; void setup() { // load images bg = loadImage("kitchen.png"); sprite_sheet = loadImage("guy.png"); /* The sprite size is 32×49. Look guy.png, the "stand position" is [...]
Atiaia early releases
23 July, 2011 - 9:57 pm
Tags: Atiaia, C, Marco Diego, programming, Ray Tracying
Posted in english | 1 comment
This was a project that me and Marco Diego created during our graduation for the Computer Graphics course. It is a ray tracing engine build from scratch in C. It was great exercise of experimentation on how implement object-oriented design patterns in ANSI C. Later Marco continued it in his master’s degree thesis implementing more [...]
Android screen height and width
12 March, 2011 - 9:30 pm
Tags: Android, Java, mobile, programming, screensize
Posted in english | 1 comment
Context ctx = getContext(); Display display = ((WindowManager)ctx.getSystemService(ctx.WINDOW_SERVICE)).getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); Yes, there are easier ways to retrieve the screen width on Android but there are cases that this long code is the only solution. You may already have the Context. WindowManager or the Display and so it would be [...]
PHP: array, all elements but first
9 March, 2011 - 12:52 pm
Tags: array, array_shift, PHP, programming
Posted in english | No comments
$bric = array("Brazil", "Russia", "India", "China"); $ric = $bric; // array copy $br = array_shift($ric); // left shift at $ric. $br stores "Brazil" print_r($bric); // $bric remains the same print_r($ric); // $ric lost "Brazil" Output: Array ( [0] => Brazil [1] => Russia [2] => India [3] => China ) Array ( [0] => Russia [...]
Java: invoking a method by name
29 April, 2010 - 10:29 am
Tags: Class, Java, method, programming, Reflection
Posted in english | 2 comments
import java.lang.reflect.*; public class Foo { public void bar(int param){ System.out.println(param); } public static void main(String args[]){ Object f = new Foo(); try { Method m = f.getClass().getMethod("bar", int.class); m.invoke(f, 42); } catch (Exception e){ System.err.println(e); } } } $ java Foo 42
calling commands in Java
8 April, 2010 - 1:09 pm
Tags: getruntime, Java, programming, runtime
Posted in english | No comments
I don’t like the approach of calling native shell commands in any language instead of using multi platform libraries, but here is a little prof of concept Java program to call native commands. import java.io.*; import java.util.*; public class Exec { public static void main(String args[]) throws IOException { Process proc = Runtime.getRuntime().e xec(args); BufferedReader [...]
Iterating over a HashMap
8 April, 2010 - 11:22 am
Tags: collections, enhanced loop, foreach, hashmap, iterating, Java, programming
Posted in english | No comments
Iterating over a HashMap using the enhanced loop (foreach) in Java is a good way to keep your code smaller, more legible and usually more semantically coherent. import java.util.HashMap; import java.util.Map; class Foo {} public class Main { public static void main(String args[]){ Map<Byte, Foo> mHash; mHash = new HashMap<Byte, Foo>(); [...]
Getting an Android app source
18 March, 2010 - 12:00 am
Tags: Android, branch, cmd, git, programming
Posted in english | 1 comment
Getting the Android’s AlarmClock application source from official repositories: git clone git://android.git.kernel.org/platform/packages/apps/AlarmClock.git To get the head version for an old platform like the 1.4 (codename donut), choose the correspondent branch using -o or –origin: git clone git://android.git.kernel.org/platform/packages/apps/AlarmClock.git –origin donut












