java——100行代码,构建函数图像绘制程序的核心部分

这篇博客展示了如何使用Java编写代码来绘制包括正态分布函数f(x)=0.25²π1e^(-2*0.25²(x-0.3)²)和一个含有高频成分的周期性信号波的图像y=sin(13x)*(sin(2x)+cos(5x)-0.5sin(3x)+cos(4x)+sin(13x))。文章还提到了去掉高频部分后的函数图像,并计划后续添加定积分算法以验证周期函数的积分特性。
摘要由CSDN通过智能技术生成

绘图类

import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import static java.lang.Math.*;

public class GenerateGraph{
   
	private int x_axis=50;
	private int y_axis=50;
	double div;
	private int scale=10;
	public BufferedImage image;
	
	public GenerateGraph(){
   }
	
	public void drawGraph(int width, int height){
   
		//创建图像栅格
		this.image=new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
		WritableRaster raster=image.getRaster();
		ColorModel model=image.getColorModel();
		
		Color curvecolor=Color.red;
		int argb=curvecolor.getRGB();
		//依据颜色模型获取颜色数据
		Object colordata=model.getDataElements(argb, null);
		
		int backgroundcolor[]={
   255, 255, 255, 255};//背景颜色
		int axiscolor[]={
   0, 0, 0, 255};//坐标轴颜色
		
		for (int i=0;i<width;i++){
   
			raster.setPixel(i, height-x_axis, axiscolor);
			if (i%scale==0){
   
				raster.setPixel(i, height-x_axis-1, axiscolor);
				raster.setPixel(i, height-x_axis-2, axiscolor);
				raster.setPixel(i, height-x_axis-3, axiscolor);
			}//may occur out of bound exception!
		}//绘制x轴
		
		for (int j=0;j<height;j++){
   
			raster.setPixel(y_axis, j, axiscolor);
			if (j%scale==0){
   
				raster.setPixel(y_axis+1, j, axiscolor);
				raster
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Unicode718A

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值