Advertisement
Guest User

Week 04

a guest
Mar 7th, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. // Author:Qinxinrui Zhu
  2. // Title:Color Harmony
  3.  
  4. #ifdef GL_ES
  5. precision mediump float;
  6. #endif
  7.  
  8. #define PI 3.14159265359
  9. #define Orange vec3(1.,0.427,0.)
  10. #define Purple vec3(0.141,0.,0.275)
  11. #define Green vec3(0.0,1.0,0.0)
  12. #define White vec3(1.0)
  13.  
  14.  
  15. uniform vec2 u_resolution;
  16. uniform vec2 u_mouse;
  17. uniform float u_time;
  18. //rotate the canvas
  19. mat2 rotate2d(float angle){
  20. return
  21. mat2(
  22. cos (angle), - sin(angle),
  23. sin(angle), - cos(angle)
  24.  
  25. );
  26. }
  27.  
  28. //Create many small square bars to divide the canvas by x-axis
  29. float create_blind(float start, float blind_width,float direction){
  30. return -1.0*(step(start, direction) - smoothstep(start + blind_width, start + blind_width+0.05,direction) - 1.0);
  31.  
  32. }
  33.  
  34.  
  35. void main() {
  36. vec2 st = gl_FragCoord.xy/u_resolution.xy;
  37. float blind_width =0.15;
  38. //rotate our st make the animation move in the opposite direction
  39. st.x -= 1.0;
  40. st = rotate2d(PI)*st;
  41.  
  42.  
  43. // canvas color
  44. vec3 lights = mix(Purple, Orange,st.x);
  45. lights = mix(lights,Green,sin(20.0*u_time)*1.0-st.x);
  46.  
  47. //Animated values
  48. //Use abs() to keep the motion in a range with a spacing of 0.15 for each frame
  49. float Animated_blind_width = blind_width - abs(blind_width*sin(1.5*u_time));
  50.  
  51. //Parameters and position of each small bar
  52. float blind0 = create_blind(0.00,Animated_blind_width,st.x);
  53. float blind1 = create_blind(0.15,Animated_blind_width,st.x);
  54. float blind2 = create_blind(0.30,Animated_blind_width,st.x);
  55. float blind3 = create_blind(0.45,Animated_blind_width,st.x);
  56. float blind4 = create_blind(0.60,Animated_blind_width,st.x);
  57. float blind5 = create_blind(0.75,Animated_blind_width,st.x);
  58. float blind6 = create_blind(0.90,Animated_blind_width,st.x);
  59.  
  60.  
  61.  
  62. vec3 allblinds = White * blind0 * blind1 * blind2 * blind3 * blind4 * blind5 * blind6;
  63.  
  64. gl_FragColor = vec4(allblinds*lights,1.0);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement