Program rysujący krzywe problem z deklaracją procedury w klasie tform1

0

Mam napisac program rysujący krzywą określoną w procedurze rozeta tylko nie wiem jak to do konca zrobic

to jest to co napisałem do tej pory

 
  unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Spin, ExtCtrls;

type
  TForm1 = class(TForm)
    PaintBox1: TPaintBox;
    SpinEdit1: TSpinEdit;
    procedure PaintBox1Paint(Sender: TObject);
    procedure SpinEdit1Change(Sender: TObject);
    procedure TForm1.Rozeta;  //to ma być tutaj czy w sekcji private?
  private
    { Private declarations }    
  public
    { Public declarations }

  end;

var
  Form1: TForm1;
  mx,my,R:integer;
  t:real;

implementation

{$R *.dfm}


 procedure TForm1.Rozeta;
 var x,y:real;
   begin
      x:=mx+R*sin(2*t)*cos(t);
      y:=my+R*sin(2*t)*sin(t);
   end;


procedure TForm1.PaintBox1Paint(Sender: TObject);
var x,y:real;
begin
   mx:=(PaintBox1.Width div 2);
   my:=(PaintBox1.Height div 2);
   R:=SpinEdit1.Value;
   t:=0;
   Rozeta;
   PaintBox1.Canvas.MoveTo(round(x),round(y));
     while t<2*pi do
     begin
         Rozeta;
         Paintbox1.Canvas.LineTo(round(x),round(y));
         t:=t+0.01;
     end;
end;

procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
    PaintBox1.Repaint;
    PaintBox1Paint(Sender);
end;

end.
0

Spróbuj zmienne x,y typu real ustawić jako globalne. (Nie zapomnij usunąć ich deklaracji w funkcji onPaint oraz Rozeta)

0

dobra poradziłem. Tam było więcej błędów, ale sam doszedłem;p

 unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Spin, ExtCtrls;

type
  TForm1 = class(TForm)
    PaintBox1: TPaintBox;
    SpinEdit1: TSpinEdit;
    procedure PaintBox1Paint(Sender: TObject);
    procedure SpinEdit1Change(Sender: TObject);
   
  private
    { Private declarations }
    procedure Rozeta;       //uwaga na to
  public
    { Public declarations }

  end;

var
  Form1: TForm1;
  mx,my,R:integer;
  t:real;

implementation

{$R *.dfm}


 procedure TForm1.Rozeta;
 var x,y:real;
   begin
      x:=mx+R*sin(2*t)*cos(t);
      y:=my+R*sin(2*t)*sin(t);
      PaintBox1.Canvas.MoveTo(round(x),round(y));
      repeat
         x:=mx+R*sin(2*t)*cos(t);
         y:=my+R*sin(2*t)*sin(t);
         PaintBox1.Canvas.LineTo(round(x),round(y));
         t:=t+0.01;
      until (t>(2*pi));
   end;


procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
   mx:=(PaintBox1.Width div 2);
   my:=(PaintBox1.Height div 2);
   R:=SpinEdit1.Value;
   t:=0;
   Rozeta;
end;


procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
  PaintBox1.Repaint;
  PaintBox1Paint(Sender);
end;

end.
0

Dobra robota, Karol. Tak trzymaj!

0

Mam problem z kodem w C# odnośnie tego samego problemu:

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        Bitmap bmp;
        float R = (float)100.0;
        public Form1()
        {
            InitializeComponent();
            bmp = new Bitmap(600, 600);
            draw();
        }
        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            R = (float)numericUpDown1.Value;
            draw();
        }
        private void draw()
        {
            Graphics g = Graphics.FromImage(bmp);
            g.FillRectangle(Brushes.White, 25, 25, 625, 625);
            List<PointF> points = new List<PointF>();
            PointF center = new PointF(300, 300);
            float t = 0;
            while (t <= Math.PI * 2)
            {
                points.Add(new PointF(center.X + (float)(R * Math.Sin(2 * t) * Math.Cos(t)), center.Y + R * (float)(Math.Sin(2 * t) * Math.Sin(t))));
                t += 0.1f;
            }
           g.DrawPolygon(Pens.Blaca, points.ToArray());
           pictureBox1.Image = bmp;

        }
    }

}

Co jest nie tak??

0

Ok, już doszłam do błędu.

" g.DrawPolygon(Pens.Blaca, points.ToArray());"  

na

 " g.DrawPolygon(Pens.Black, points.ToArray());" 

1 użytkowników online, w tym zalogowanych: 0, gości: 1