Created
October 17, 2011 11:11
-
-
Save mharju/1292407 to your computer and use it in GitHub Desktop.
Quick & Dirty screensaver for PyCon.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.opengl.*; | |
void setup() | |
{ | |
size(1440, 960, OPENGL); | |
background(0); | |
} | |
void star(int size) | |
{ | |
pushMatrix(); | |
beginShape(LINES); | |
vertex(-size, -size, 0); | |
vertex(size, size, 0); | |
vertex(size, -size, 0); | |
vertex(-size, size, 0); | |
endShape(); | |
popMatrix(); | |
} | |
color colors[] = { | |
color(0x55ffff, 0xff), | |
color(0x55ff55, 0xff), | |
color(0xffff55, 0xff), | |
color(0xff55ff, 0xff) | |
}; | |
void generate() | |
{ | |
for(int i=0;i<N;i++) { | |
if(stars[i] == null || stars[i].y < frameCount) { | |
stars[i] = new PVector(random(0, frameCount + width), random(0, frameCount + height), random(0, 500)); | |
starColors[i] = colors[ (int)random(colors.length) ]; | |
starSizes[i] = (int)random(1, 7); | |
} | |
} | |
} | |
int N = 100; | |
PVector[] stars = new PVector[N]; | |
color[] starColors = new color[N]; | |
int[] starSizes = new int[N]; | |
// Available from https://github.com/python-finland/fi.pycon.org/blob/master/media/2011/site/logo.png | |
PImage logo = loadImage("logo.png"); | |
void draw() | |
{ | |
generate(); | |
background(0); | |
pushMatrix(); | |
translate(0, -frameCount); | |
for(int i=0;i<N;i++) { | |
pushMatrix(); | |
stroke(starColors[i]); | |
translate(stars[i].x, stars[i].y, stars[i].z); | |
star(starSizes[i]); | |
popMatrix(); | |
} | |
popMatrix(); | |
translate(width/2, height/2 + sin(radians(frameCount)) * 50 ); | |
image(logo, -logo.width / 2, -logo.height / 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment