Last active
December 21, 2015 01:38
-
-
Save amano41/6228703 to your computer and use it in GitHub Desktop.
ボールが色を変えながら回転するサンプル
http://amano41.hateblo.jp/entry/2013/08/14/170508
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
int fps = 15; | |
int radius = 50; | |
int cycle = 5; // 回転周期 | |
int speed = 5; // 拡散速度 | |
int degree = 360 / (cycle * fps); | |
void setup() { | |
size(200, 200); | |
frameRate(fps); | |
colorMode(HSB, 360, 100, 100); | |
} | |
void draw() { | |
float rad = radians(degree * frameCount); | |
float x = width/2 + radius * cos(rad); | |
float y = height/2 + radius * sin(rad); | |
color c = color(frameCount % 360, 100, 80); | |
// 波紋の不透明度と大きさの係数 | |
float k = sin(radians(speed * frameCount % 90)); | |
smooth(); | |
noStroke(); | |
background(0, 0, 100); | |
// 波紋 | |
fill(c, 50-50*k); | |
ellipse(x, y, width*k, width*k); | |
// 球体 | |
fill(c); | |
ellipse(x, y, 20, 20); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment