Bezier splines
A simple Bezier spline implementation. Allows the user to select control 'points on a picture box and then draw a Bezier curve between them. NEW!! - User can now move control points!!
AI
Riepilogo AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Codice sorgente
Dim nc As Integer
Dim Cont(100, 1) As Integer
Dim NewLocPoint As Integer
Const Smooth = 0.02
Dim Dragging As Boolean
Function B(k, n, u)
'Bezier blending function
B = C(n, k) * (u ^ k) * (1 - u) ^ (n - k)
End Function
Function C(n, r)
' Implements c!/r!*(n-r)!
C = fact(n) / (fact(r) * fact(n - r))
End Function
Function fact(n)
' Recursive factorial fucntion
If n = 1 Or n = 0 Then
fact = 1
Else
fact = n * fact(n - 1)
End If
End Function
Private Sub AddCont(X, Y)
Cont(nc, 0) = X: Cont(nc, 1) = Y
nc = nc + 1
End Sub
Private Sub cmdReset_Click()
nc = 0
picDisplay.Cls
End Sub
Private Sub Form_Load()
Form1.ScaleMode = vbTwips
Form1.Caption = "Bezier Curves by Mark Roberts"
Form1.Move 900, 900, 5900, 5200
picDisplay.Move 120, 120, 5535, 4250
cmdReset.Move 4640, 4435, 1015, 255
cmdReset.Caption = "&Reset"
With Label1
.BackColor = &HC0FFFF
.BorderStyle = vbFixedSingle
.Move 120, 4440, 4435, 255
.Alignment = vbCenter
.Caption = "Select new points or drag points to move"
End With
picDisplay.ScaleMode = vbPixels
picDisplay.FontSize = 5
End Sub
Private Sub picDisplay_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
xv = Int(X): yv = Int(Y) 'In case not pixels
cval = Clicked(xv, yv)
If cval > -1 And Button = 1 Then ' In case you want multiple points
Dragging = True
NewLocPoint = cval
Label1.Caption = "Dragging point " + Trim$(cval + 1)
Else
AddCont xv, yv 'Add the control points
picDisplay.Circle (xv, yv), 2, 255
picDisplay.Print nc
If nc = 1 Then
PSet (xv, yv)
Else
picDisplay.DrawStyle = vbDot
picDisplay.Line (Cont(nc - 2, 0), Cont(nc - 2, 1))-(Cont(nc - 1, 0), Cont(nc - 1, 1)), 0
picDisplay.DrawStyle = vbSolid
End If
If nc > 1 Then Redraw
End If
End Sub
Private Sub picDisplay_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Clicked(X, Y) > -1 Then
MousePointer = vbCrosshair
Else
MousePointer = vbDefault
End If
If Dragging = True Then
xv = Int(X): yv = Int(Y)
Cont(NewLocPoint, 0) = xv: Cont(NewLocPoint, 1) = yv
Redraw
End If
End Sub
Private Sub picDisplay_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
' End dragging operation
If Dragging = True Then
Dragging = False
Redraw
Label1.Caption = "Select new points or drag current ones"
End If
End Sub
Private Function Clicked(X, Y)
' Has the user clicked within the circle
' of a current point
For i = 0 To nc
xp = Cont(i, 0): yp = Cont(i, 1)
If Abs(xp - X) < 3 And Abs(yp - Y) < 3 Then
Clicked = i
Exit Function
End If
Next i
Clicked = -1
End Function
Sub Redraw()
'Redraws entire display
picDisplay.Cls
For i = 1 To nc
xv = Cont(i - 1, 0): yv = Cont(i - 1, 1)
picDisplay.Circle (xv, yv), 2, 255
picDisplay.Print i
Next i
picDisplay.DrawStyle = vbDot
For i = 0 To nc - 2
picDisplay.Line (Cont(i, 0), Cont(i, 1))-(Cont(i + 1, 0), Cont(i + 1, 1)), 0
Next i
picDisplay.DrawStyle = vbSolid
DrawBezier Smooth
End Sub
Sub DrawBezier(du)
' Draws a Bezier curve using the control points given in
' Cont(...). Uses delta u steps
n = nc - 1 'N = number of control points -1
If n < 1 Then
MsgBox "Need more control points", vbInformation
Exit Sub
End If
picDisplay.PSet (Cont(0, 0), Cont(0, 1)) 'Plot the first point
For u = 0 To 1 Step du
X = 0: Y = 0
For k = 0 To n ' For each control point
bv = B(k, n, u) ' Calculate blending function
X = X + Cont(k, 0) * bv
Y = Y + Cont(k, 1) * bv
Next k
picDisplay.Line -(X, Y), 65535 ' Draw to the point
Next u
picDisplay.Line -(Cont(n, 0), Cont(n, 1)), 65535
End Sub
import java.awt.*;
import javax.swing.*;
public class SplashScreen extends JWindow
{
private SplashScreenImage image;
private int top, left;
private int Seconds =1;
public SplashScreen(int width, int height, String imagePath, int Seconds)
{
super.setSize(width, height);
this.Seconds = Seconds;
image = new SplashScreenImage(Toolkit.getDefaultToolkit().getImage(imagePath));
super.getContentPane().add(image);
top = (super.getToolkit().getScreenSize().height / 2) - (size().height / 2);
left = (super.getToolkit().getScreenSize().width / 2) - (size().width / 2);
super.setLocation(top, left);
image.setSize(width, height);
}
public void show()
{
super.show();
try{Thread.sleep(Seconds * 1000);}
catch(InterruptedException e){}
super.hide();
}
}
class SplashScreenImage extends Canvas
{
Image Splashimage;
public SplashScreenImage(Image Splashimage)
{
this.Splashimage = Splashimage;
}
public void paint(Graphics g)
{
g.drawImage(Splashimage,0,0,this);
}
}
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
//**********************************************
int color=10; // Change the number to change the text color
int highlight=14; // Change the number to change the text color
int choice=8;
void options()
{
system ("cls");
if (choice==8)
{
cout << "You Chose New Game!!!\n";
// your code goes here
}
else if (choice==9)
{
cout << "You Chose To Highscores!!\n";
// your code goes here
}
}
//*********************************************************************************************
//Do not edit Below This line
//*******************************************************************************************
void menu()
{
textcolor(color);
gotoxy(35,8);
textbackground(0);
if (choice==8)
{
textbackground(highlight);
}
cprintf("New Game");
gotoxy(35,9);
textbackground(0);
if (choice==9)
{
textbackground(highlight);
}
cprintf ("High Scores");
gotoxy(35,10);
textbackground(0);
if (choice==10)
{
textbackground(highlight);
}
cprintf ("Exit");
cout <<endl;
}
int main()
{
system ("cls");
menu();
char key;
for (;;)
{
key=getch();
if (key=='\r')
{
options();
break;
}
switch (key)
{
case 'H':
if (choice-1<8)
{
break;
}
else
{
choice--;
}
menu();
break;
case 'P':
if (choice+1>10)
{
break;
}
else
{
choice++;
}
menu();
break;
}
}
return 0;
}
Commenti originali (3)
Recuperato da Wayback Machine