cryton2707 Posted October 3, 2007 Posted October 3, 2007 Im wanting to create a sin wave the width of the screen.. I did find some C code my maths aint up to the job of properly understanding the code.. can any one help me convert it .. Thanks CODE void draw_sine () { int length = 50; fixed x, y; fixed angle = 0; fixed angle_stepsize = itofix (5); while (fixtoi(angle) < 256) { // the angle is plotted along the x-axis x = angle; // the sine function is plotted along the y-axis y = length * fsin (angle); putpixel (screen, fixtoi (x), fixtoi (y) + SCREEN_H / 2, makecol (255, 255, 255)); angle += angle_stepsize; } } whats this fixtoi above and itofix used for above.. Thanks Chris Welcome to the internet :) where men are men! Women are men! and 16 year old women are FBI agents!
Blue_Drache Posted October 3, 2007 Posted October 3, 2007 Hmm... A sin wave is drawn on a unit graph, usually. For a single iteration, using the whole screen, transpose the existing coordinates to a unit graph like so: 0, 0 = $x = @DesktopWidth / 2, $y = @DesktopHeight/2 1, -1 = @DesktopWidth, @DesktopHeight -1, 1 = 0, 0 1, 1 = @DesktopWidth, 0 -1, -1 = 0, @DesktopHeight Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache
Nahuel Posted October 4, 2007 Posted October 4, 2007 (edited) Hey! I was SUPER bored... I should have been studying though...warning!: Selecting the highest accuracy will cause 100% CPU load and it will take it a while (At least on an average comp..)expandcollapse popup#include <GUIConstants.au3> #Region ### START Koda GUI section ### Form= $Main = GUICreate("Super Trigonométrico", 228, 364) GUICtrlCreateLabel("more", 184, 156, 27, 17) GUICtrlSetColor(-1, 0xFF0000) GUICtrlCreateLabel("Please select the function you wish to draw", 8, 24, 208, 17) $Sin = GUICtrlCreateRadio("Sin", 32, 48, 41, 17) GUICtrlSetState(-1,$GUI_CHECKED) $Cos = GUICtrlCreateRadio("Cos", 88, 48, 49, 17) $Tan = GUICtrlCreateRadio("Tan", 144, 48, 65, 17) GUICtrlCreateLabel("Select accuracy", 16, 104, 81, 17) $Acc = GUICtrlCreateSlider (16, 128, 185, 17) GUICtrlSetLimit(-1,4,1) GUICtrlSetData(-1,2) GUICtrlCreateGroup("", 0, 0, 225, 89) GUICtrlCreateGroup("", 0, 88, 225, 89) GUICtrlCreateGroup("", 0, 176, 225, 113) GUICtrlCreateLabel("less", 8, 156, 22, 17) GUICtrlSetColor(-1, 0xFFFF00) GUICtrlCreateLabel("Recommended!", 72, 158, 79, 17) GUICtrlSetColor(-1, 0x008080) GUICtrlCreateLabel("Select axis scales", 16, 192, 88, 17) $Xscale = GUICtrlCreateSlider(40, 216, 137, 17) GUICtrlSetLimit(-1,100,1) GUICtrlSetData(-1,50) $Yscale = GUICtrlCreateSlider(40, 240, 137, 17) GUICtrlSetLimit(-1,100,1) GUICtrlSetData(-1,50) GUICtrlCreateLabel("X", 24, 216, 11, 17) GUICtrlCreateLabel("Y", 24, 240, 11, 17) $draw = GUICtrlCreateButton("Draw!", 32, 312, 161, 33, $BS_DEFPUSHBUTTON) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $draw If GUICtrlRead($Sin)=$GUI_CHECKED Then draw("sin") Else If GUICtrlRead($Cos)=$GUI_CHECKED Then draw("Cos") Else draw("Tan") EndIf EndIf EndSwitch WEnd Func draw($sFunc) Local $GrAcc=1 $Accuracy=GUICtrlRead($Acc) Switch $Accuracy Case 1 $GrAcc=1 Case 2 $GrAcc=0.5 Case 3 $GrAcc=0.05 case 4 $GrAcc=0.005 EndSwitch $scaleX=GUICtrlRead($Xscale) $scaleY=GUICtrlRead($Yscale) ;Create Child Gui $child=GUICreate("",@DesktopWidth,@DesktopHeight) GUISetBkColor(0xFFFFFF,$child) $exit=GUICtrlCreateButton("Exit",@DesktopWidth-150,@DesktopHeight-50,100) $g = GUICtrlCreateGraphic(1,1,@DesktopWidth-1,@DesktopHeight-1) SplashTextOn("","Drawing...",150,25,-1,-1,1) If $sFunc="sin" Then For $i=1 to @DesktopWidth Step $GrAcc $y0=(Sin($i/$scaleX)*$scaleY)+(@DesktopHeight/2) GUICtrlSetGraphic($g,$GUI_GR_DOT,$i,$y0) Next EndIf If $sFunc="cos" Then For $i=1 to @DesktopWidth Step $GrAcc $y0=(Cos($i/$scaleX)*$scaleY)+(@DesktopHeight/2) GUICtrlSetGraphic($g,$GUI_GR_DOT,$i,$y0) Next EndIf If $sFunc="tan" Then For $i=1 to @DesktopWidth Step $GrAcc $y0=(Tan($i/$scaleX)*$scaleY)+(@DesktopHeight/2) GUICtrlSetGraphic($g,$GUI_GR_DOT,$i,$y0) Next EndIf SplashOff() GUISetState() While 1 $msg=GUIGetMsg() Select Case $msg=$GUI_EVENT_CLOSE GUIDelete($child) ExitLoop Case $msg=$exit GUidelete($child) ExitLoop EndSelect WEnd EndFuncI thought of using the dll GDI32.dll so the graphic would be actually on the screen! But for some reasong it fucked up and I had to restart like 3 times... Edited October 4, 2007 by Nahuel
BrettF Posted October 4, 2007 Posted October 4, 2007 Hey! I was SUPER bored... I should have been studying though... warning!: Selecting the highest accuracy will cause 100% CPU load and it will take it a while (At least on an average comp..) expandcollapse popup#include <GUIConstants.au3> #Region ### START Koda GUI section ### Form= $Main = GUICreate("Super Trigonométrico", 228, 364) GUICtrlCreateLabel("more", 184, 156, 27, 17) GUICtrlSetColor(-1, 0xFF0000) GUICtrlCreateLabel("Please select the function you wish to draw", 8, 24, 208, 17) $Sin = GUICtrlCreateRadio("Sin", 32, 48, 41, 17) GUICtrlSetState(-1,$GUI_CHECKED) $Cos = GUICtrlCreateRadio("Cos", 88, 48, 49, 17) $Tan = GUICtrlCreateRadio("Tan", 144, 48, 65, 17) GUICtrlCreateLabel("Select accuracy", 16, 104, 81, 17) $Acc = GUICtrlCreateSlider (16, 128, 185, 17) GUICtrlSetLimit(-1,4,1) GUICtrlSetData(-1,2) GUICtrlCreateGroup("", 0, 0, 225, 89) GUICtrlCreateGroup("", 0, 88, 225, 89) GUICtrlCreateGroup("", 0, 176, 225, 113) GUICtrlCreateLabel("less", 8, 156, 22, 17) GUICtrlSetColor(-1, 0xFFFF00) GUICtrlCreateLabel("Recommended!", 72, 158, 79, 17) GUICtrlSetColor(-1, 0x008080) GUICtrlCreateLabel("Select axis scales", 16, 192, 88, 17) $Xscale = GUICtrlCreateSlider(40, 216, 137, 17) GUICtrlSetLimit(-1,100,1) GUICtrlSetData(-1,50) $Yscale = GUICtrlCreateSlider(40, 240, 137, 17) GUICtrlSetLimit(-1,100,1) GUICtrlSetData(-1,50) GUICtrlCreateLabel("X", 24, 216, 11, 17) GUICtrlCreateLabel("Y", 24, 240, 11, 17) $draw = GUICtrlCreateButton("Draw!", 32, 312, 161, 33, $BS_DEFPUSHBUTTON) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $draw If GUICtrlRead($Sin)=$GUI_CHECKED Then draw("sin") Else If GUICtrlRead($Cos)=$GUI_CHECKED Then draw("Cos") Else draw("Tan") EndIf EndIf EndSwitch WEnd Func draw($sFunc) Local $GrAcc=1 $Accuracy=GUICtrlRead($Acc) Switch $Accuracy Case 1 $GrAcc=1 Case 2 $GrAcc=0.5 Case 3 $GrAcc=0.05 case 4 $GrAcc=0.005 EndSwitch $scaleX=GUICtrlRead($Xscale) $scaleY=GUICtrlRead($Yscale) ;Create Child Gui $child=GUICreate("",@DesktopWidth,@DesktopHeight) GUISetBkColor(0xFFFFFF,$child) $exit=GUICtrlCreateButton("Exit",@DesktopWidth-150,@DesktopHeight-50,100) $g = GUICtrlCreateGraphic(1,1,@DesktopWidth-1,@DesktopHeight-1) SplashTextOn("","Drawing...",150,25,-1,-1,1) If $sFunc="sin" Then For $i=1 to @DesktopWidth Step $GrAcc $y0=(Sin($i/$scaleX)*$scaleY)+(@DesktopHeight/2) GUICtrlSetGraphic($g,$GUI_GR_DOT,$i,$y0) Next EndIf If $sFunc="cos" Then For $i=1 to @DesktopWidth Step $GrAcc $y0=(Cos($i/$scaleX)*$scaleY)+(@DesktopHeight/2) GUICtrlSetGraphic($g,$GUI_GR_DOT,$i,$y0) Next EndIf If $sFunc="tan" Then For $i=1 to @DesktopWidth Step $GrAcc $y0=(Tan($i/$scaleX)*$scaleY)+(@DesktopHeight/2) GUICtrlSetGraphic($g,$GUI_GR_DOT,$i,$y0) Next EndIf SplashOff() GUISetState() While 1 $msg=GUIGetMsg() Select Case $msg=$GUI_EVENT_CLOSE GUIDelete($child) ExitLoop Case $msg=$exit GUidelete($child) ExitLoop EndSelect WEnd EndFunc I thought of using the dll GDI32.dll so the graphic would be actually on the screen! But for some reasong it fucked up and I had to restart like 3 times... Language mister Thats pretty cool. I like how it looks if i go TAN, More, X & Y = lowest. Its like. Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
Nahuel Posted October 4, 2007 Posted October 4, 2007 (edited) Language mister Thats pretty cool. I like how it looks if i go TAN, More, X & Y = lowest. Its like. haha, awesome!Try:TanAccuracy:3rd positionX=LowestY=Highest Edited October 4, 2007 by Nahuel
BrettF Posted October 4, 2007 Posted October 4, 2007 lol... awesome =P Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
JBeef Posted October 4, 2007 Posted October 4, 2007 $size = WinGetPos("Program Manager") $hdc = DllCall("user32.dll","int","GetDC","hwnd",0) $x = 0 while $x < $size[2] DllCall("gdi32.dll","int","SetPixel","int",$hdc[0],"int",$x,"int",getNormalizedSine($x, ($size[3]/2), $size[2]),"int",0xFF00FF) $x += 1 WEnd DllCall("user32.dll","int","ReleaseDC","hwnd",0,"int",$hdc[0]) Func getNormalizedSine($xxx, $halfY, $maxX) $piDouble = 2 * 3.14 $factor = $piDouble / $maxX Return Int(Sin($xxx * $factor) * $halfY + $halfY) EndFunc
Nahuel Posted October 4, 2007 Posted October 4, 2007 $size = WinGetPos("Program Manager") $hdc = DllCall("user32.dll","int","GetDC","hwnd",0) $x = 0 while $x < $size[2] DllCall("gdi32.dll","int","SetPixel","int",$hdc[0],"int",$x,"int",getNormalizedSine($x, ($size[3]/2), $size[2]),"int",0xFF00FF) $x += 1 WEnd DllCall("user32.dll","int","ReleaseDC","hwnd",0,"int",$hdc[0]) Func getNormalizedSine($xxx, $halfY, $maxX) $piDouble = 2 * 3.14 $factor = $piDouble / $maxX Return Int(Sin($xxx * $factor) * $halfY + $halfY) EndFunc Oooohhhh that's so far away from what I had done, haha..
cryton2707 Posted October 4, 2007 Author Posted October 4, 2007 O' Wow.. Thanks guys.. This is fantastic.. Just what I need.. Im trying to create a sin wave scroller.. and having never done one before.. This will really help me. (way cool) Thanks Welcome to the internet :) where men are men! Women are men! and 16 year old women are FBI agents!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now