triangle.vp

#version 130

in vec4 vVertex;

void main(void) 
{ 
	gl_Position = vVertex;
}
import numpy as np import matplotlib.pyplot as plt # 设置仿真参数 f = 1000 # 频率 1kHz t = np.linspace(0, 0.003, 1000) # 显示 3ms (3个周期) # 1. 方波 (Pin 9) # ICL8038 在 +/-12V 供电下,方波低电平接近 -12V,高电平接近 +12V square_wave = 11.5 * np.sign(np.sin(2 * np.pi * f * t)) # 2. 三角波 (Pin 3) # 原始输出约 8Vpp,通过电位器衰减到 6Vpp (+/- 3V) # 生成完美的三角波 triangle_wave = 3 * (2 * np.abs(2 * (t * f - np.floor(t * f + 0.5))) - 1) # 3. 正弦波 (Pin 2) # 原始输出约 5.2Vpp,通过电位器衰减到 1Vpp (+/- 0.5V) sine_wave = 0.5 * np.sin(2 * np.pi * f * t) # 绘制示波器风格图表 plt.figure(figsize=(10, 8)) plt.suptitle('ICL8038 Waveform Simulation Result (f = 1kHz)', fontsize=16) # 方波通道 plt.subplot(3, 1, 1) plt.plot(t * 1000, square_wave, 'g', linewidth=2) plt.title('Channel 1: Square Wave (Output from Pin 9)', fontsize=12) plt.ylabel('Voltage (V)') plt.grid(True, linestyle='--', alpha=0.7) plt.ylim(-15, 15) plt.text(0.1, 13, 'Vp-p $\approx$ 23V (Limit <= 24V)', color='green', fontweight='bold') # 三角波通道 plt.subplot(3, 1, 2) plt.plot(t * 1000, triangle_wave, 'orange', linewidth=2) plt.title('Channel 2: Triangle Wave (Output from Pin 3 + Potentiometer)', fontsize=12) plt.ylabel('Voltage (V)') plt.grid(True, linestyle='--', alpha=0.7) plt.ylim(-5, 5) plt.text(0.1, 3.5, 'Vp-p = 6V (Adjusted)', color='orange', fontweight='bold') # 正弦波通道 plt.subplot(3, 1, 3) plt.plot(t * 1000, sine_wave, 'b', linewidth=2) plt.title('Channel 3: Sine Wave (Output from Pin 2 + Potentiometer)', fontsize=12) plt.xlabel('Time (ms)') plt.ylabel('Voltage (V)') plt.grid(True, linestyle='--', alpha=0.7) plt.ylim(-1, 1) plt.text(0.1, 0.6, 'Vp-p = 1V (Adjusted)', color='blue', fontweight='bold') plt.tight_layout(rect=[0, 0.03, 1, 0.95]) plt.show()
最新发布
12-16
import { SceneOption, Scene, SCENE } from '../gl-renderer/types' import Texture from '../texture' // 目前没有额外配置项,先预留配置项类型,方便后续扩展 export type WebcodecNormalSceneOption = SceneOption<object> /** * @description: 顶点着色器 * @return {*} */ export const vertexShaderSource = ` attribute vec2 xy; uniform vec2 scale; uniform vec2 translate; varying highp vec2 uv; void main(void) { vec2 scaledPosition = xy * scale+ translate; gl_Position = vec4(scaledPosition, 0.0, 1.0); // Map vertex coordinates (-1 to +1) to UV coordinates (0 to 1). // UV coordinates are Y-flipped relative to vertex coordinates. uv = vec2((1.0 + xy.x) / 2.0, (1.0 - xy.y) / 2.0); } ` /** * @description: 片元着色器 * @return {*} */ export const fragmentShaderSource = ` varying highp vec2 uv; uniform sampler2D texture; void main(void) { gl_FragColor = texture2D(texture, uv); } ` export class WebcodecNormalScene extends Scene { static sceneType = SCENE.WEBCODEC_NORMAL vertexShaderSource = vertexShaderSource fragmentShaderSource = fragmentShaderSource gl!: WebGLRenderingContext program!: WebGLProgram options!: WebcodecNormalSceneOption yTexture!: Texture uTexture!: Texture vTexture!: Texture get sceneType() { return WebcodecNormalScene.sceneType } private applyOptions(sceneGl: WebGLRenderingContext, sceneProgram: WebGLProgram, sceneOption: WebcodecNormalSceneOption) { this.gl = sceneGl this.program = sceneProgram this.options = sceneOption } public initializer(sceneGl: WebGLRenderingContext, sceneProgram: WebGLProgram, sceneOption: WebcodecNormalSceneOption) { this.applyOptions(sceneGl, sceneProgram, sceneOption) const gl = this.gl const shaderProgram = this.program const vertexBuffer = gl.createBuffer() gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer) gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0]), gl.STATIC_DRAW) const xyLocation = gl.getAttribLocation(shaderProgram, 'xy') gl.vertexAttribPointer(xyLocation, 2, gl.FLOAT, false, 0, 0) gl.enableVertexAttribArray(xyLocation) const scaleLocation = gl.getUniformLocation(shaderProgram, 'scale') const scaleFactor = [1, 1] // 缩放因子为 1.5x gl.uniform2fv(scaleLocation, scaleFactor) const translateLocation = gl.getUniformLocation(shaderProgram, 'translate') const translateFactor = [0, 0] // 平移因子为 0,0 gl.uniform2fv(translateLocation, translateFactor) //纹理 const texture = gl.createTexture() const enableMipMap = this.options.isAntialias ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR gl.bindTexture(gl.TEXTURE_2D, texture) gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR) gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, enableMipMap) gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE) gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE) } public render(frameData: VideoFrame) { const gl = this.gl gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, frameData) this.options.isAntialias && gl.generateMipmap(gl.TEXTURE_2D) // Configure and clear the drawing area. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight) gl.clearColor(0.0, 0.0, 0.0, 0.0) gl.clear(gl.COLOR_BUFFER_BIT) gl.drawArrays(gl.TRIANGLE_FAN, 0, 4) } public clear() { const gl = this.gl gl.clearColor(0.0, 0.0, 0.0, 0.0) gl.clear(gl.COLOR_BUFFER_BIT) gl.getExtension('WEBGL_lose_context')?.loseContext() } } 结合这段代码说一下优化的方式
07-05
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值