Skip to content

Instantly share code, notes, and snippets.

The scene has a perspective projection.
I want to know if a fragment is inside the cone formed by the camera and a sphere.
sphereCentre is set by mvMatrix*vec3(0,0,0) and radius is 1; I am drawing a unit sphere.
The camera is at 0,0,0 in view space.
The fragment shader just passes the scene position to the fragment shader:
function Sphere(iterations) {
// returns an object with a 'draw' method
// we cache ready-built spheres
if(!Sphere.spheres)
Sphere.spheres = [];
if(iterations in Sphere.spheres)
return Sphere.spheres[iterations];
// we have to create it...
var vertices = [],
vIndex = {},
import sys
queue = ["a"+"-"*9]
boards = {queue[0]:set()}
ends = set()
next = {"a":"b","b":"a"}
def won(side,board):
line = side*3
@williame
williame / gist:4087256
Created November 16, 2012 13:12
a dot-file for all moves in a simple tic-tac-toe-like game
digraph luffarschack {
node [shape=none];
"baabb--ba-" [label=<<TABLE BORDER="1" BGCOLOR="white">
<TR><TD BGCOLOR="red"></TD><TD BGCOLOR="red"></TD><TD BGCOLOR="blue"></TD></TR>
<TR><TD BGCOLOR="blue"></TD><TD BGCOLOR="white"></TD><TD BGCOLOR="white"></TD></TR>
<TR><TD BGCOLOR="blue"></TD><TD BGCOLOR="red"></TD><TD BGCOLOR="white"></TD></TR>
</TABLE>>];
"baabb--ba-" -> "abbaa-a-b-";
"baabb--ba-" -> "ab-aaba--b";
"baabb--ba-" -> "abbaaba---";
import signal, time, traceback, threading
def start(interval=0.1):
global _interval, _samples
_samples = []
signal.signal(signal.SIGALRM,_sample)
signal.setitimer(signal.ITIMER_REAL,interval,interval)
def stop():
global _samples
from PIL import Image, ImageDraw, ImageSequence
from random import random as rnd
from math import sqrt
def vec3_scale(v,f):
return (v[0]*f,v[1]*f,v[2]*f)
def vec3_add(a,b):
return (a[0]+b[0],a[1]+b[1],a[2]+b[2])
@williame
williame / IntrusiveList.java
Created September 19, 2012 18:00
An intrusive list class for Java
public final class IntrusiveList<T> {
/** private constructor used by makeList() */
private IntrusiveList() {
t = null; // is null so we know this must be the head/tail
prev = next = this; // cyclic
}
/** returns a new head/tail pointer */
public static <T> IntrusiveList<T> makeList() {
from PIL import Image, ImageDraw, ImageSequence
from random import random as rnd
from math import sqrt
def vec3_scale(v,f):
return (v[0]*f,v[1]*f,v[2]*f)
def vec3_add(a,b):
return (a[0]+b[0],a[1]+b[1],a[2]+b[2])
<html><head><title> 165888,79872 </title></head><body><table cellspacing="0" cellpadding="0">
<tr>
<td><img src="http://imgs.xkcd.com/clickdrag/48n0e.png" alt=""/>
<td><img src="http://imgs.xkcd.com/clickdrag/48n1e.png" alt=""/>
<td><img src="http://imgs.xkcd.com/clickdrag/48n2e.png" alt=""/>
<td><img src="http://imgs.xkcd.com/clickdrag/48n3e.png" alt=""/>
<td><img src="http://imgs.xkcd.com/clickdrag/48n4e.png" alt=""/>
<td><img src="http://imgs.xkcd.com/clickdrag/48n5e.png" alt=""/>
<td><img src="http://imgs.xkcd.com/clickdrag/48n6e.png" alt=""/>
<td><img src="http://imgs.xkcd.com/clickdrag/48n7e.png" alt=""/>
size=[14,48,25,33]
tilesize=2048
map_size=[(size[1]+size[3])*tilesize,(size[0]+size[2])*tilesize]
print '<html><head><title>',",".join("%s"%i for i in map_size),'</title></head><body><table cellspacing="0" cellpadding="0">'
for ns in "ns":
for y in range(48):
print "<tr>"
for x in range(25):