This should be reasonably simple but then again, so am I ^_^
I need the white dot to curve up and meet the red dot where I clicked i.e. I need to adjust the frequency of the wave.
The most obvious way to do this is to scale the
...by somehow basing the change on the distance clicked from the origin but nothing I've tried gets the correct result.
I need the white dot to curve up and meet the red dot where I clicked i.e. I need to adjust the frequency of the wave.
The most obvious way to do this is to scale the
frequency parameter in the formula:z = -Sin( frequency * x + horiz_displacement ) * amplitude + vertical_displacement
...by somehow basing the change on the distance clicked from the origin but nothing I've tried gets the correct result.
Strict Graphics 800, 600, 0 Global mouse_x:Float Global mouse_y:Float Global distance:Float Global angle:Float Global list:TList = CreateList() Repeat Cls mouse_x = MouseX() mouse_y = MouseY() distance = getDistance( 0, 300, mouse_x, mouse_y ) angle = getAngle( 0, 300, mouse_x, mouse_y ) If MouseDown(1) ListAddLast( list, tObject.Create() ) EndIf For Local obj:tObject=EachIn list obj.update() obj.draw() Next SetColor( 255, 255, 255 ) DrawText("Distance from origin to mouse: "+distance, 0, 0) Flip Until KeyHit(KEY_ESCAPE) Function getAngle( x1:Double, y1:Double, x2:Double, y2:Double ) Return ATan2( y2 - y1, x2 - x1 ) End Function Function getDistance:Float(x1:Float, y1:Float, x2:Float, y2:Float) Local x_diff:Float = x2 - x1 Local y_diff:Float = y2 - y1 Return Sqr( (x_diff*x_diff) + (y_diff*y_diff) ) End Function '--------------------- '--- Moving object --- '--------------------- Type tObject Field x:Float Field y:Float Field z:Float Field x_target:Float Field y_target:Float Field dist_target:Float Field rot:Float Function Create:tObject() Local this:tObject= New tObject this.x = 1 this.y = 300 this.z = this.y this.x_target = mouse_x this.y_target = mouse_y this.rot = angle Return this End Function Method update() If x > 800 Or x < 0 Or y < 0 Or y > 600 ListRemove( list, Self ) Return EndIf dist_target = getDistance( 0, 300, x_target, y_target ) x:+2 * Cos( rot ) y:+2 * Sin( rot ) '-- Fake the white pixel travelling at an altitude which we refer to as z Local frequency:Float = 0.8 Local horiz_displacement:Float = 0 Local amplitude:Float = 200 Local vertical_displacement:Float = y z = -Sin( frequency * x + horiz_displacement ) * amplitude + vertical_displacement End Method Method draw() 'White is the "real" object SetColor( 255, 255, 255 ) Plot(x, z) 'Red is the "shadow" object, the object's footprint SetColor( 255, 0, 0 ) Plot(x, y) End Method End Type