Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions clickme.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html>

<head>

</head>

<body>
<script type="text/javascript"
src="https://rawgit.com/patriciogonzalezvivo/glslCanvas/master/dist/GlslCanvas.js"></script>
<!-- if you use data-fragment-url,you should run in a server -->
<canvas class="glslCanvas" data-fragment="#ifdef GL_ES
precision mediump float;
#endif

uniform vec2 u_resolution;
uniform float u_time;

vec3 colorA = vec3(0.149,0.141,0.912);
vec3 colorB = vec3(1.000,0.833,0.224);

void main() {
vec3 color = vec3(0.0);

float pct = abs(sin(u_time));


// Mix uses pct (a value from 0-1) to
// mix the two colors
color = mix(colorA, colorB, pct);

gl_FragColor = vec4(color,1.0);
}" width="500" height="500"></canvas>
</body>
24 changes: 24 additions & 0 deletions codes/code_gonlyk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var code = {}

code.red = function (x, y) {
const [dx, dy] = [2 * x / 1024 - 1, 2 * y / 1024 - 1]
const r = Math.abs(Math.atan2(dy, dx))
return Math.sin(r) * 255
}

code.blue = function (x, y) {
const [dx, dy] = [2 * x / 1024 - 1, 2 * y / 1024 - 1]
const l = Math.sqrt(dx * dx + dy * dy)
return Math.cos((Math.ceil(l) - l) * 3) * 255
}

code.green = function (x, y) {
const [dx, dy] = [2 * x / 1024 - 1, 2 * y / 1024 - 1]
return Math.cos(dx + 1 - dy) * 255
}

code.author = {
id: 'gonlyk',
githubId: 'your github gonlyk',
description: '燕宝 燕宝 撒鼻息'
}
43 changes: 41 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,59 @@
var code = {}

const tsubame = function (x, y) {
const [tx1, ty1] = [x / 1024 - 0.8, y / 1024 - 0.2]
const [tx2, ty2] = [x / 1024 - 0.95, y / 1024 - 0.2]
const r1 = Math.atan2(ty1, tx1)
const l1 = Math.sqrt(tx1 * tx1 + ty1 * ty1)
const r2 = Math.atan2(ty2, tx2)
const l2 = Math.sqrt(tx2 * tx2 + ty2 * ty2)
if ((l1 > 0.07 && l1 < 0.08 && r1 > -Math.PI / 2 && r1 < 0) ||
(l2 > 0.07 && l2 < 0.08 && r2 > -Math.PI && r2 < -Math.PI / 2))
return 1

return 0
}
code.red = function (x, y) {
const [dx, dy] = [2 * x / 1024 - 1, 2 * y / 1024 - 1]
const r = -(Math.atan2(dy, dx))
const l = Math.sqrt(dx * dx + dy * dy)

const background = Math.sin(r)
const sun = (l > 0.3 ? 0 : 1)

const tbm = tsubame(x, y)
if (l < 0.3) {
return (0.2 * background + 0.8 * sun) * 255
} else {
return (tbm === 1 ? 1 - background : background) * 255
}
}

code.blue = function (x, y) {

const [dx, dy] = [2 * x / 1024 - 1, 2 * y / 1024 - 1]
const l = Math.sqrt(dx * dx + dy * dy)
const background = Math.cos((Math.ceil(l) - l) * 3)
const sun = (l > 0.3 ? 0 : 0.3)
const tbm = tsubame(x, y)
if (l < 0.3) {
return (0.2 * background + 0.8 * sun) * 255
} else {
return (tbm === 1 ? 1 - background : background) * 255
}
}

code.green = function (x, y) {

const [dx, dy] = [2 * x / 1024 - 1, 2 * y / 1024 - 1]
const background = Math.cos(dx + 1 - dy)
const tbm = tsubame(x, y)
return (tbm === 1 ? 1 - background : background) * 255
}

let canvas = document.getElementById('canvas')
let ctx = canvas.getContext('2d')
let size = 1024
window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;

for (let x = 0; x < size; x++) {
for (let y = 0; y < size; y++) {
ctx.fillStyle = 'rgb(' + code.red(x, y) + ',' + code.green(x, y) + ',' + code.blue(x, y) + ')'
Expand Down
22 changes: 22 additions & 0 deletions shader.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifdef GL_ES
precision mediump float;
#endif

uniform vec2 u_resolution;
uniform float u_time;

vec3 colorA = vec3(0.149,0.141,0.912);
vec3 colorB = vec3(1.000,0.833,0.224);

void main() {
vec3 color = vec3(0.0);

float pct = abs(sin(u_time));


// Mix uses pct (a value from 0-1) to
// mix the two colors
color = mix(colorA, colorB, pct);

gl_FragColor = vec4(color,1.0);
}