the world is a pixel
Posts tagged programming
OpenPixels: simple sprite sheet with Processing
Aug 22nd

/** * 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 32x49. Look guy.png, the "stand position" is at (36,102). */ player = createImage(32, 49, ARGB); player.copy(sprite_sheet, 36, 102, 32, 49, 0, 0, 32, 49); // set screen size and background size(bg.width, bg.height); background(bg); frameRate(30); } void draw() { background(bg); image(player, 100, 50); }
See more at OpenPixels.
Android screen height and width
Mar 12th
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 smaller, but this code is more general.
PHP: array, all elements but first
Mar 9th
$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 [1] => India [2] => China )
Reference: PHP array_shift at php.net.
Java: invoking a method by name
Apr 29th

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












