본문 바로가기

전체 글163

[자료구조 프로그래밍 연습문제] 다항식 계수 배열, 다항식 곱하기, 구조체 1. 다항식 : 계수 배열 representation 교재 2.4.2절에 기술된 다항식 표현 방법 두 가지 중 앞부분에 먼저 기술된 계수 배열 표현의 C 구현으로 다항식 A(x) = a_n*x^n + a_(n-1)*x^(n-1) + ... + a_(1)*x^1 + a_(0)*x^0 을 표현하였다고 하자. 최고차항 a_(n)*x^n의 계수 a_(n)은 0이 아니고 나머지 항들의 계수는 0일 수도 있다고 가정한다. A(x)를 나타내는 변수 a를 교재에서 정의한 구조체 자형 polynomial로 선언하면 C 코드로 polynomial a; 이다. A. 구조체 자료형 polynomial에서 degree의 의미는 무엇인가? 차수, 즉 다항식에서 가장 큰 지수를 뜻한다. B. a.coef[i] = a_(n-i) 라.. 2022. 1. 11.
[자료구조 프로그래밍 연습문제] 재귀함수, 선택정렬, 배열 1. recursion 교재 Figure 1.3의 C 코드에서 수업시간에 언급된 오류를 차고 정확한 코드로 수정하시오. 수정하지 않을 경우 실행 결과에 어떤 오류가 발생하는지 간단한 예를 들어 설명하시오. float rsum(float list[], int n) { if (n) return rsum(list, n-1) + list[n-1]; return 0; } 0 대신 list[0]의 값을 반환하면, list배열의 값들의 전체 합에 첫번째 요소 값이 한 번 더 더하여져서 값이 달라진다. 예를 들어, list == [1, 2, 3, 4, 5] 인 경우, rsum의 결과 값은 1 + 1 + 2 + 3 + 4+ 5, 16으로 첫번째 요소인 1만큼의 오차가 발생한다. 2. recursive implementa.. 2022. 1. 10.
[GLSL] Fractal Brownian Motion https://thebookofshaders.com/13/ The Book of Shaders Gentle step-by-step guide through the abstract and complex universe of Fragment Shaders. thebookofshaders.com float amplitude = 1.; float frequency = 1.; y = sin(x * frequency); float t = 0.01*(-u_time*130.0); y += sin(x*frequency*2.1 + t)*4.5; y += sin(x*frequency*1.72 + t*1.121)*4.0; y += sin(x*frequency*2.221 + t*0.437)*5.0; y += sin(x*freq.. 2022. 1. 6.
[GLSL] Voronoi https://thebookofshaders.com/12/ The Book of Shaders Gentle step-by-step guide through the abstract and complex universe of Fragment Shaders. thebookofshaders.com #ifdef GL_ES precision mediump float; #endif uniform vec2 u_resolution; uniform vec2 u_mouse; void main(){ vec2 coord = gl_FragCoord.xy/u_resolution; coord.x *= u_resolution.x/u_resolution.y; vec2 mouse = u_mouse.xy/u_resolution; mouse.. 2022. 1. 6.
[GLSL] Gradient Noise https://thebookofshaders.com/11/ The Book of Shaders Gentle step-by-step guide through the abstract and complex universe of Fragment Shaders. thebookofshaders.com #ifdef GL_ES precision mediump float; #endif uniform vec2 u_resolution; // vec2 vec2 random vec2 random(vec2 st){ float x = fract(sin(dot(st*25., vec2(17.34,50.13)))*84239.523); float y = fract(cos(dot(st*25., vec2(28.13,39.49)))*94820.. 2022. 1. 6.
[GLSL] Value Noise https://thebookofshaders.com/11/ The Book of Shaders Gentle step-by-step guide through the abstract and complex universe of Fragment Shaders. thebookofshaders.com Vec2-float noise. #ifdef GL_ES precision mediump float; #endif uniform vec2 u_resolution; float random(vec2 st){ float c = fract(sin(dot(st*25., vec2(17.34,50.13)))*84239.523); return c; } float noise(vec2 st){ vec2 i = floor(st); vec2.. 2022. 1. 6.
[GLSL] Float-float Noise https://thebookofshaders.com/11/ The Book of Shaders Gentle step-by-step guide through the abstract and complex universe of Fragment Shaders. thebookofshaders.com The left side is a noise graph, and the right side is a random graph. A noise and a random are different. Let's make a noise function. float i = floor(x); // integer float f = fract(x); // fraction y = rand(i); float i = floor(x); // i.. 2022. 1. 6.
[GLSL] Maze and Glitch #ifdef GL_ES precision mediump float; #endif #define ROOT2 1.414 uniform vec2 u_resolution; uniform vec2 u_mouse; uniform float u_time; float random(float f); float random(vec2 f); float random(vec3 f); float line(vec2 coord, bool dir){ float y; float thc = .2; if(dir){ y = coord.x; }else{ y = 1. - coord.x; } return smoothstep(y-thc, y, coord.y) - smoothstep(y, y+thc, coord.y); } void main(){ ve.. 2022. 1. 6.
[GLSL] Random https://thebookofshaders.com/10/ The Book of Shaders Gentle step-by-step guide through the abstract and complex universe of Fragment Shaders. thebookofshaders.com Let's write the function 'random' that returns randomed-float data. float random(float st); float random(vec2 st); float random(vec3 st); float random(float f){ float y = fract(sin(f*100.)*100.); return y; } The function 'dot' downgrad.. 2022. 1. 6.