Blödsinn mit Plot

Spiele, Demos, Grafikzeug und anderes unterhaltendes.
Benutzeravatar
dllfreak2001
Beiträge: 2925
Registriert: 07.09.2004 23:44
Wohnort: Bayern

Blödsinn mit Plot

Beitrag von dllfreak2001 »

Hab malsowas ähnliches gemacht was auch MAtlab bei der Ausgabe macht...

Code: Alles auswählen

InitSprite()
InitKeyboard()

OpenScreen(800,600,32,"Plotomatic")

#plotx = 200
#ploty = 140


Dim fx.f(#plotx,#ploty)

Global rot.f, offsetx.f, offsety.f, sizex.f,sizey.f,posx.f,posy.f,mode.b
sizex = 2
sizey = 2
offsetx = 100
offsety = 100
posx = -#plotx/2
posy = -#ploty/2

#exp = 2.7182818
pot = 1
Repeat
    ExamineKeyboard()

    If KeyboardPushed(#PB_Key_W)
        offsety - 5
    EndIf
    If KeyboardPushed(#PB_Key_S)
        offsety + 5
    EndIf
    If KeyboardPushed(#PB_Key_A)
        offsetx - 5
    EndIf
    If KeyboardPushed(#PB_Key_D)
        offsetx + 5
    EndIf
    If KeyboardPushed(#PB_Key_1)
        sizex + 0.1
    EndIf
    If KeyboardPushed(#PB_Key_2)
        sizex - 0.1
    EndIf
    If KeyboardPushed(#PB_Key_3)
        sizey + 0.1
    EndIf
    If KeyboardPushed(#PB_Key_4)
        sizey - 0.1
    EndIf
    If KeyboardPushed(#PB_Key_Up)
        posy - 5
    EndIf
    If KeyboardPushed(#PB_Key_Down)
        posy + 5
    EndIf
    If KeyboardPushed(#PB_Key_Left)
        posx - 5
    EndIf
    If KeyboardPushed(#PB_Key_Right)
        posx + 5
    EndIf

        If KeyboardReleased(#PB_Key_P)
        If pot = 0 
            pot = 1
        Else
         pot  = 0
        EndIf
        
    EndIf
    rot + 0.1
    min.f = 0
    max.f = 0
    For x = 0 To #plotx:For y = 0 To #ploty
        nx.f = x + posx
        ny.f =  y + posy
        rad.f = nx*ny
        
        ;Das ist die Formel
        fx(x,y) = (100/(Pow((posx+x)/50,2)+1))*1/(Pow((posy+y)/50,2)+1)*Sin(Sqr(Pow((x+posx)/10,2)+Pow((y+posy)/10,2))+rot)
        
        If x = 0 And y = 0
            min = fx(x,y)
            max = fx(x,y)
        EndIf
        
        If fx(x,y) < min
            min = fx(x,y)
        EndIf
        If fx(x,y) > max
            max = fx(x,y)
        EndIf

        
    Next:Next
    
    range.f = max - min
    
    StartDrawing(ScreenOutput())
        For x = 0 To #plotx:For y = 0 To #ploty
            tempx.f = x*sizex + y + offsetx
            tempy.f = y*sizey+fx(x,y)*pot + offsety
            
            
            
                If tempx > 10 And tempy > 10 And tempx < 790 And tempy < 590
                
                
                    If KeyboardPushed(#PB_Key_M) = 0
                        Plot(tempx,tempy,RGB((255/range)*(fx(x,y)-min),(255/range)*(fx(x,y)-min),200))
                    Else
                        If x < #plotx
                            xtempx.f = (x+1)*sizex + y + offsetx
                            xtempy.f = y*sizey+fx(x+1,y)*pot + offsety
                            LineXY(tempx,tempy,xtempx,xtempy,RGB((255/range)*(fx(x,y)-min),(255/range)*(fx(x,y)-min),200))
                        
                        EndIf
                        
                    EndIf
                    
                EndIf    

            
        Next:Next
    
    DrawText(0,0,StrF(range))
    
    StopDrawing()
    FlipBuffers()
    ClearScreen(RGB(0,0,0))

Until KeyboardPushed(#PB_Key_Escape)
CloseScreen()
End
Taste 1 : stretcht die ausgabe in x richtung + 1
Taste 2 : stretcht die ausgabe in x richtung - 1
Taste 3 : stretcht die ausgabe in y richtung + 1
Taste 4 : stretcht die ausgabe in y richtung - 1

W A S D : verschieben die Ausgabe entsprechend auf dem Screen

Pfeiltasten : verchieben den Offset

P : Flatmode

M : Linemode (extrem langsam)


läuft nicht besonders schnell, aber wollt mal wieder etwas Posten.
I´a dllfreak2001
Benutzeravatar
PureLust
Beiträge: 1145
Registriert: 21.07.2005 00:02
Computerausstattung: Hab aktuell im Grunde nur noch 'nen Lenovo Yoga 2 Pro im Einsatz.
Wohnort: am schönen Niederrhein

Beitrag von PureLust »

Hallo dllfreak,

als ich damals auch so einen ähnlichen Plotter gebastelt hatte, bemerkte ich, dass es im LineModus nicht unbedingt erforderlich ist, die gleiche 'Auflösung' (Steprate der For/Next Schleifen) zu benutzen wie im Plot-Modus.
Somit kann man also ruhig die Steprate im Line-Modus erhöhen, ohne gravierende Qualitätseinbussen zu erhalten.

Ich habe dies (und einige weitere kleine Änderungen) mal in Deinen Code eingebaut. Dadurch ist der Line-Modus halt 'etwas' schneller als zuvor.
Ich hoffe die Änderungen gehen so ok? ;)
(Potential zum weiteren Optimieren bietet das ganze natürlich immer noch.)

Code: Alles auswählen

DisableDebugger
InitSprite() 
InitKeyboard() 

OpenScreen(800,600,32,"Plotomatic") 

#plotx = 200 
#ploty = 140 


Dim fx.f(#plotx,#ploty) 

Global rot.f, offsetx.f, offsety.f, sizex.f,sizey.f,posx.f,posy.f,mode.b 
sizex = 2.5 
sizey = 2.5
offsetx = 60 
offsety = 130 
posx = -#plotx/2 
posy = -#ploty/2 

#exp = 2.7182818 
pot = 1 
Repeat 
    ExamineKeyboard() 

    If KeyboardPushed(#PB_Key_W) : offsety - 5 : EndIf 
    If KeyboardPushed(#PB_Key_S) : offsety + 5 : EndIf 
    If KeyboardPushed(#PB_Key_A) : offsetx - 5 : EndIf 
    If KeyboardPushed(#PB_Key_D) : offsetx + 5 : EndIf 
    If KeyboardPushed(#PB_Key_1) : sizex + 0.1 : offsetx - 7 : EndIf 
    If KeyboardPushed(#PB_Key_2) : sizex - 0.1 : offsetx + 7 : EndIf 
    If KeyboardPushed(#PB_Key_3) : sizey + 0.1 : offsety - 5 : EndIf 
    If KeyboardPushed(#PB_Key_4) : sizey - 0.1 : offsety + 5 : EndIf 
    If KeyboardPushed(#PB_Key_Up)    : posy + 5   : EndIf 
    If KeyboardPushed(#PB_Key_Down)  : posy - 5   : EndIf 
    If KeyboardPushed(#PB_Key_Left)  : posx + 5   : EndIf 
    If KeyboardPushed(#PB_Key_Right) : posx - 5   : EndIf
    If KeyboardReleased(#PB_Key_P) : pot = 1-pot  : EndIf
    If KeyboardReleased(#PB_Key_M) : LineMode = 1-LineMode : EndIf
    If LineMode : xStep = 3 : yStep = 1 : Else : xStep = 0 : yStep = 0 : EndIf
    rot + 0.1 
    min.f = 0 
    max.f = 0 
    min = fx(x,y) 
    max = fx(x,y) 
    For x = 0 To #plotx
        xPow1.f = (100/(Pow((posx+x)/50,2)+1))*1
        xPow2.f = Pow((x+posx)/10,2)
        nx.f = x + posx 
        For y = 0 To #ploty 
	        ny.f =  y + posy 
	        rad.f = nx*ny 
	        
	        ;Das ist die Formel 
	        fx(x,y) = xPow1/(Pow((posy+y)/50,2)+1)*Sin(Sqr(xPow2+Pow((y+posy)/10,2))+rot) 
	        
	        If fx(x,y) < min 
	            min = fx(x,y) 
	        EndIf 
	        If fx(x,y) > max 
	            max = fx(x,y) 
	        EndIf 
           y + yStep
        Next y
        x + xStep
     Next x
    
    range.f = max - min 
    StartDrawing(ScreenOutput()) 
        For x = 0 To #plotx
	        For y = 0 To #ploty
	            Color = (255/range)*(fx(x,y)-min)
	            tempx.f = x*sizex + y + offsetx 
	            tempy.f = y*sizey+fx(x,y)*pot + offsety 
                If tempx > 10 And tempy > 10 And tempx < 790 And tempy < 590 
                    If LineMode
                        If x < #plotx 
                            xtempx.f = (x+1+xStep)*sizex + y + offsetx 
                            xtempy.f = y*sizey+fx(x+1+xStep,y)*pot + offsety 
                            LineXY(tempx,tempy,xtempx,xtempy,RGB(Color,Color,200)) 
                        EndIf 
                    Else 
                        Plot(tempx,tempy,RGB(Color,Color,200)) 
                    EndIf 
                EndIf
           y + yStep
	        Next y
	        x + xStep
        Next x
    
    DrawText(0,0,"Range: "+StrF(range),$ffffff,0) 
    
    StopDrawing() 
    FlipBuffers(0) 
    ClearScreen(RGB(0,0,0))
    Delay(1)

Until KeyboardPushed(#PB_Key_Escape) 
EnableDebugger
CloseScreen() 
End
Gruß, PureLust.
[Dynamic-Dialogs] - komplexe dynamische GUIs einfach erstellen
[DeFlicker] - Fenster flimmerfrei resizen
[WinFX] - Window Effekte (inkl. 'durchklickbares' Window)
Benutzeravatar
dllfreak2001
Beiträge: 2925
Registriert: 07.09.2004 23:44
Wohnort: Bayern

Beitrag von dllfreak2001 »

Hast recht, so läuft alles schön Schnell.
man Könnte es aber auch noch beschleunigen wenn man für
den Plot-Modus direkt im DrawingBuffer rumpfuscht.
I´a dllfreak2001
Benutzeravatar
PureLust
Beiträge: 1145
Registriert: 21.07.2005 00:02
Computerausstattung: Hab aktuell im Grunde nur noch 'nen Lenovo Yoga 2 Pro im Einsatz.
Wohnort: am schönen Niederrhein

Beitrag von PureLust »

Klar, wie ich ja bereits geschrieben hatte, ist da noch massig Raum für weitere Optimierungen. ;)
[Dynamic-Dialogs] - komplexe dynamische GUIs einfach erstellen
[DeFlicker] - Fenster flimmerfrei resizen
[WinFX] - Window Effekte (inkl. 'durchklickbares' Window)
Antworten