Размер видео: 1280 X 720853 X 480640 X 360
Показать панель управления
Автовоспроизведение
Автоповтор
This is the first time that I have seen anyone use the go programming language for something like this. Great work!
Amazing content do not stop at all keep going bro
Underrated channel.
i appreciate your channel and videos. looking forward to all you bring to youtube for go :)
I appreciate that!
beautiful physics to art
Thank you! Cheers!
Nice video! New sub
I don't need it but this is great
Thanks for watching!
tnx, really good and educating, appreciate it a lot
Thank You!!!
Is this doable in C++ or python?
Certainly, why not?
package mainimport "math"type Vector struct { X float64 Y float64}// Vector operationsfunc (v Vector) add(other Vector) Vector { return Vector{X: v.X + other.X, Y: v.Y + other.Y}}func (v Vector) subtract(other Vector) Vector { return Vector{X: v.X - other.X, Y: v.Y - other.Y}}func (v Vector) multiply(scalar float64) Vector { return Vector{X: v.X * scalar, Y: v.Y * scalar}}func (v Vector) distance(other Vector) float64 { dx := v.X - other.X dy := v.Y - other.Y return math.Sqrt(dx*dx + dy*dy)}func (v Vector) projection(other Vector) Vector { dotProduct := v.X*other.X + v.Y*other.Y magSquared := other.X*other.X + other.Y*other.Y if magSquared == 0 { return Vector{} } scale := dotProduct / magSquared return other.multiply(scale)}type Ball struct { r Vector v Vector mass float64 radius float64}func (b *Ball) addGravity(level float64) { const pxPerM = 50 const fps = 60 b.v.Y += level * 9.8 / (fps * fps) * pxPerM}func (b *Ball) handleWallCollision(Cr, screenWidth, screenHeight float64) { if b.r.X-b.radius = screenWidth { b.v.X = -Cr * b.v.X b.r.X = screenWidth - b.radius } if b.r.Y-b.radius = screenHeight { b.v.Y = -Cr * b.v.Y b.r.Y = screenHeight - b.radius }}func (b *Ball) ballHitVelocity(b2 *Ball, Cr float64) Vector { mRatio := (Cr + 1) * b2.mass / (b.mass + b2.mass) vDiff := b.v.subtract(b2.v) rDiff := b.r.subtract(b2.r) proj := vDiff.projection(rDiff) return b.v.subtract(proj.multiply(mRatio))}func (b *Ball) isHit(b2 *Ball) bool { dist := b.r.distance(b2.r) return dist
This is the first time that I have seen anyone use the go programming language for something like this. Great work!
Amazing content do not stop at all keep going bro
Underrated channel.
i appreciate your channel and videos. looking forward to all you bring to youtube for go :)
I appreciate that!
beautiful physics to art
Thank you! Cheers!
Nice video! New sub
I don't need it but this is great
Thanks for watching!
tnx, really good and educating, appreciate it a lot
Thank You!!!
Is this doable in C++ or python?
Certainly, why not?
package main
import "math"
type Vector struct {
X float64
Y float64
}
// Vector operations
func (v Vector) add(other Vector) Vector {
return Vector{X: v.X + other.X, Y: v.Y + other.Y}
}
func (v Vector) subtract(other Vector) Vector {
return Vector{X: v.X - other.X, Y: v.Y - other.Y}
}
func (v Vector) multiply(scalar float64) Vector {
return Vector{X: v.X * scalar, Y: v.Y * scalar}
}
func (v Vector) distance(other Vector) float64 {
dx := v.X - other.X
dy := v.Y - other.Y
return math.Sqrt(dx*dx + dy*dy)
}
func (v Vector) projection(other Vector) Vector {
dotProduct := v.X*other.X + v.Y*other.Y
magSquared := other.X*other.X + other.Y*other.Y
if magSquared == 0 {
return Vector{}
}
scale := dotProduct / magSquared
return other.multiply(scale)
}
type Ball struct {
r Vector
v Vector
mass float64
radius float64
}
func (b *Ball) addGravity(level float64) {
const pxPerM = 50
const fps = 60
b.v.Y += level * 9.8 / (fps * fps) * pxPerM
}
func (b *Ball) handleWallCollision(Cr, screenWidth, screenHeight float64) {
if b.r.X-b.radius = screenWidth {
b.v.X = -Cr * b.v.X
b.r.X = screenWidth - b.radius
}
if b.r.Y-b.radius = screenHeight {
b.v.Y = -Cr * b.v.Y
b.r.Y = screenHeight - b.radius
}
}
func (b *Ball) ballHitVelocity(b2 *Ball, Cr float64) Vector {
mRatio := (Cr + 1) * b2.mass / (b.mass + b2.mass)
vDiff := b.v.subtract(b2.v)
rDiff := b.r.subtract(b2.r)
proj := vDiff.projection(rDiff)
return b.v.subtract(proj.multiply(mRatio))
}
func (b *Ball) isHit(b2 *Ball) bool {
dist := b.r.distance(b2.r)
return dist