rotate drawing with matrix

P

Peter Proost

Hi group,


I got the following piece of code which draws a square with stars round it,
now I want the stars to rotate round the square, I can do this with the
mx.rotate and a timer and an angle, but this rotates the whole drawing of
the stars but what I realy want is for the stars to rotate round it's center
point, is this possible? I hope I was clear enough in my explanation.

Thanks in advance

Peter



Imports System.Drawing.Drawing2D

Private pentje As New Pen(Color.White)
Private brush As New SolidBrush(Color.White)
Private hoek As Single


e.Graphics.FillRectangle(brush, 100, 100, 100, 100)

'Place inside form paint event
'Dim mx As New Matrix
'mx.Rotate(hoek, MatrixOrder.Append)
'mx.Translate(Me.ClientSize.Width / 2, Me.ClientSize.Height / 2,
MatrixOrder.Append)
'e.Graphics.Transform = mx

'grote ster
e.Graphics.DrawLine(pentje, 100, 100, 150, 0)
e.Graphics.DrawLine(pentje, 150, 0, 200, 100)
e.Graphics.DrawLine(pentje, 200, 100, 300, 150)
e.Graphics.DrawLine(pentje, 300, 150, 200, 200)
e.Graphics.DrawLine(pentje, 200, 200, 150, 300)
e.Graphics.DrawLine(pentje, 150, 300, 100, 200)
e.Graphics.DrawLine(pentje, 100, 200, 0, 150)
e.Graphics.DrawLine(pentje, 0, 150, 100, 100)
'kleine ster
e.Graphics.DrawLine(pentje, 100, 100, 150, 25)
e.Graphics.DrawLine(pentje, 150, 25, 200, 100)
e.Graphics.DrawLine(pentje, 200, 100, 275, 150)
e.Graphics.DrawLine(pentje, 275, 150, 200, 200)
e.Graphics.DrawLine(pentje, 200, 200, 150, 275)
e.Graphics.DrawLine(pentje, 150, 275, 100, 200)
e.Graphics.DrawLine(pentje, 100, 200, 25, 150)
e.Graphics.DrawLine(pentje, 25, 150, 100, 100)
'kleinere ster
e.Graphics.DrawLine(pentje, 100, 100, 150, 50)
e.Graphics.DrawLine(pentje, 150, 50, 200, 100)
e.Graphics.DrawLine(pentje, 200, 100, 250, 150)
e.Graphics.DrawLine(pentje, 250, 150, 200, 200)
e.Graphics.DrawLine(pentje, 200, 200, 150, 250)
e.Graphics.DrawLine(pentje, 150, 250, 100, 200)
e.Graphics.DrawLine(pentje, 100, 200, 50, 150)
e.Graphics.DrawLine(pentje, 50, 150, 100, 100)
'kleinste ster
e.Graphics.DrawLine(pentje, 100, 100, 150, 75)
e.Graphics.DrawLine(pentje, 150, 75, 200, 100)
e.Graphics.DrawLine(pentje, 200, 100, 225, 150)
e.Graphics.DrawLine(pentje, 225, 150, 200, 200)
e.Graphics.DrawLine(pentje, 200, 200, 150, 225)
e.Graphics.DrawLine(pentje, 150, 225, 100, 200)
e.Graphics.DrawLine(pentje, 100, 200, 75, 150)
e.Graphics.DrawLine(pentje, 75, 150, 100, 100)


Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Timer1.Tick
hoek += 3
If hoek > 359 Then
hoek = 0
End If
Invalidate()
End Sub
 
R

Robby

What you need it do is change the position of of where you draw the stars
each time you draw them. One way would be to setup the star as if you are
drawing at the origin. Then translate the Graphics object to the star's
rotate position. Next draw the star and then reset the Graphic object's
translation. Repeat this until all stars are drawn for that rotation part.

Robby
 
P

Peter Proost

Have you got some sample code? Because I'm not 100% sure how to go about
this

Thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top