Seite 1 von 1

Pixle Fun after Returning :)

Verfasst: 11.09.2005 19:43
von satzzeichen
Hallo,

nachdem ich einige Zeit kein PB mehr programmiert habe (großes BB Projekt gehabt), wollte ich mich heute mal wieder ein wenig einüben und hab ein paar nette Plot und Line Sachen erstellt, ziehts euch einfach rein ich hoffe ihr habt wenigstens bisl Spass dabei! Es handelt sich übrigens um 9 Beispiele was man mit Plot/Line und Box alles machen kann, ihr braucht nur den Code.

MfG satzzeichen

EDIT:Habe den aktuellsten Code gleich hier editet, damit ihr nicht alle Posts absuchen müsst.

Code: Alles auswählen

;-----INIT PART-----;
InitSprite()
InitKeyboard()
OpenScreen(640,480,16,"Graphic Games")
var_y.l = 0
var_x.f = 0
;-----SIMULATOR BEGINS-----;
Repeat
ClearScreen(0,0,0)
StartDrawing(ScreenOutput())
FrontColor(255,0,0)

Locate(5, 0)
DrawText("Die angezeigte Taste gedrückt halten um den Effekt zu sehen!(ESC zum beenden)")
Locate(5, 25)
DrawText("1.Augenkrebs (langsam)")
Locate(5, 50)
DrawText("2.Augenkrebs (klein)")
Locate(5, 75)
DrawText("3.Augenkrebs (mittel) II")
Locate(5, 100)
DrawText("4.Augenkrebs (groß) III")
Locate(5, 125)
DrawText("5.Augenkrebs (sehr groß) IV")
Locate(5, 150)
DrawText("6.Pfeil I")
Locate(5, 175)
DrawText("7.Pfeil (getrennt) II")
Locate(5, 200)
DrawText("8.Pentagramm I")
Locate(5, 225)
DrawText("9.Pentagramm (leuchtend) II")
Locate(5, 250)
DrawText("0.Pentagramm (besser) III")
Locate(5, 400)
DrawText("Es können auch 2 Effekte übereinander gelegt werden...")

LineXY(200,150,521,150)
LineXY(200,351,521,351)
LineXY(200,150,200,350)
LineXY(521,150,521,350)

;Beispiel 1 und 2 sind identisch, allerdings soll Beispiel 2 verdeutlichen,
;wie man es nicht machen sollte :).

ExamineKeyboard()

If KeyboardPushed(#PB_Key_1)
    For y = 0 To 199
      For x = 0 To 319
      FrontColor(Random(255),Random(255),Random(255))
        Plot(x+201,y+151)
      Next
    Next
EndIf

If KeyboardPushed(#PB_Key_2)
    For y = 0 To 199
      For x = 0 To 319
        Plot(x+201,y+151,RGB(Random(255),Random(255),Random(255)))
      Next
    Next
EndIf 

If KeyboardPushed(#PB_Key_3)
    For y = 0 To 19
      For x = 0 To 31
        Box(x*10+201,y*10+151,10,10,RGB(Random(255),Random(255),Random(255)))
      Next
    Next 
EndIf

If KeyboardPushed(#PB_Key_4)
  Box(201,151,160,100,RGB(Random(255),Random(255),Random(255)))
  Box(361,151,160,100,RGB(Random(255),Random(255),Random(255)))
  Box(201,251,160,100,RGB(Random(255),Random(255),Random(255)))
  Box(361,251,160,100,RGB(Random(255),Random(255),Random(255)))
EndIf

If KeyboardPushed(#PB_Key_5)
  Box(201,151,320,200,RGB(Random(255),Random(255),Random(255)))
EndIf

If KeyboardPushed(#PB_Key_6)
  For anzahl = 1 To 150
    var_y.l = 0
    For x = -20 To 20
      Plot(anzahl+x+291,var_y+201,RGB(Random(255),Random(255),Random(255)))
      var_y.l = var_y.l + 1
    Next
   
    var_y.l = 0
    For x = -20 To 20
      Plot(anzahl+x+291,var_y+281,RGB(Random(255),Random(255),Random(255)))
      var_y.l = var_y.l - 1
    Next
  Next
EndIf

If KeyboardPushed(#PB_Key_7)

    For anzahl = 1 To 15
    var_y.l = 0
    For x = -20 To 20
      Plot(anzahl*10+x+291,var_y+201,RGB(Random(255),Random(255),Random(255)))
      var_y.l = var_y.l + 1
    Next
   
    var_y.l = 0
    For x = -20 To 20
      Plot(anzahl*10+x+291,var_y+281,RGB(Random(255),Random(255),Random(255)))
      var_y.l = var_y.l - 1
    Next
  Next

EndIf

If KeyboardPushed(#PB_Key_8)
  FrontColor(255,255,255)
  LineXY(360,175,310,325)
  LineXY(360,175,410,325)
  LineXY(285,225,435,225)
  LineXY(285,225,410,325)
  LineXY(435,225,310,325)
EndIf

If KeyboardPushed(#PB_Key_9)
  LineXY(360,175,310,325,RGB(Random(255),Random(55),Random(55)))
  LineXY(360,175,410,325,RGB(Random(255),Random(55),Random(55)))
  LineXY(285,225,435,225,RGB(Random(255),Random(55),Random(55)))
  LineXY(285,225,410,325,RGB(Random(255),Random(55),Random(55)))
  LineXY(435,225,310,325,RGB(Random(255),Random(55),Random(55)))
EndIf

If KeyboardPushed(#PB_Key_0)
  For x = 1 To 150
    Plot(285+x,225,RGB(Random(255),Random(55),Random(55)))
  Next
  For x = 1 To 150
    Plot(360-(x*0.3391),175+x,RGB(Random(255),Random(55),Random(55)))
  Next
  For x = 1 To 150
    Plot(360+(x*0.3391),175+x,RGB(Random(255),Random(55),Random(55)))
  Next
  For x = 1 To 150
    Plot(285+(x*0.838),225+(x*0.675),RGB(Random(255),Random(55),Random(55)))
  Next
  For x = 1 To 150
    Plot(435-(x*0.838),225+(x*0.675),RGB(Random(255),Random(55),Random(55)))
  Next
EndIf

StopDrawing()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
;-----END-----;

Verfasst: 11.09.2005 19:56
von orange-blue
Boa! der Pfeil ist echt heftig! :shock:

Verfasst: 11.09.2005 19:57
von DarkDragon
Error: ExamineKeyboard must be called before KeyboardPushed()
Zeile: 41

Verfasst: 11.09.2005 20:05
von merlin
@satzzeichen: nice work!
btw, hab deinen source etwas abgeändert... wenn du z.b. Plot() benutzt, so schreib direkt die farbe mit ins argument! Das bringt etwas mehr performance, da Plot() bei übergabe von Farbwerten DX optimiert ist und nicht per GDI plotted afaik...

Code: Alles auswählen

;-----INIT PART-----;
InitSprite()
InitKeyboard()
OpenScreen(640,480,16,"Graphic Games")
var_y.l = 0
;-----SIMULATOR BEGINS-----;
Repeat
 ClearScreen(0,0,0)
 StartDrawing(ScreenOutput())
 FrontColor(255,0,0)
 
 Locate(5, 0)
 DrawText("Die angezeigte Taste gedrückt halten um den Effekt zu sehen!(ESC zum beenden)")
 Locate(5, 25)
 DrawText("1.Augenkrebs (klein)")
 Locate(5, 50)
 DrawText("2.Augenkrebs (mittel) II")
 Locate(5, 75)
 DrawText("3.Augenkrebs (groß) III")
 Locate(5, 100)
 DrawText("4.Augenkrebs (sehr groß) IV")
 Locate(5, 125)
 DrawText("5.Pfeil I")
 Locate(5, 150)
 DrawText("6.Pfeil (getrennt) II")
 Locate(5, 175)
 DrawText("7.Pentagramm I")
 Locate(5, 200)
 DrawText("8.Pentagramm (leuchtend) II")
 Locate(5, 225)
 DrawText("9.Pentagramm (besser) III")
 Locate(5, 400)
 DrawText("Es können auch 2 Effekte übereinander gelegt werden...")
 
 LineXY(200,150,521,150)
 LineXY(200,351,521,351)
 LineXY(200,150,200,350)
 LineXY(521,150,521,350)
 
 If KeyboardPushed(#PB_Key_1)
  For y = 0 To 199
   For x = 0 To 319
;   FrontColor(Random(255),Random(255),Random(255))
    Plot(x+201,y+151,RGB(Random(255),Random(255),Random(255)))
   Next
  Next
 EndIf 
 
 If KeyboardPushed(#PB_Key_2)
  For y = 0 To 19
   For x = 0 To 31
    Box(x*10+201,y*10+151,10,10,RGB(Random(255),Random(255),Random(255)))
   Next
  Next 
 EndIf
 
 If KeyboardPushed(#PB_Key_3)
  Box(201,151,160,100,RGB(Random(255),Random(255),Random(255)))
  Box(361,151,160,100,RGB(Random(255),Random(255),Random(255)))
  Box(201,251,160,100,RGB(Random(255),Random(255),Random(255)))
  Box(361,251,160,100,RGB(Random(255),Random(255),Random(255)))
 EndIf
 
 If KeyboardPushed(#PB_Key_4)
  Box(201,151,320,200,RGB(Random(255),Random(255),Random(255)))
 EndIf
 
 If KeyboardPushed(#PB_Key_5)
  For anzahl = 1 To 150
   var_y.l = 0
   For x = -20 To 20
;   FrontColor(Random(255),Random(255),Random(255))
    Plot(anzahl+x+291,var_y+201,RGB(Random(255),Random(255),Random(255)))
    var_y.l = var_y.l + 1
   Next
   
   var_y.l = 0
   For x = -20 To 20
;   FrontColor(Random(255),Random(255),Random(255))
    Plot(anzahl+x+291,var_y+281,RGB(Random(255),Random(255),Random(255)))
    var_y.l = var_y.l - 1
   Next
  Next
 EndIf
 
 If KeyboardPushed(#PB_Key_6)
  
  For anzahl = 1 To 15
   var_y.l = 0
   For x = -20 To 20
;   FrontColor(Random(255),Random(255),Random(255))
    Plot(anzahl*10+x+291,var_y+201,RGB(Random(255),Random(255),Random(255)))
    var_y.l = var_y.l + 1
   Next
   
   var_y.l = 0
   For x = -20 To 20
;   FrontColor(Random(255),Random(255),Random(255))
    Plot(anzahl*10+x+291,var_y+281,RGB(Random(255),Random(255),Random(255)))
    var_y.l = var_y.l - 1
   Next
  Next
  
 EndIf
 
 If KeyboardPushed(#PB_Key_7)
; FrontColor(255,255,255)
  LineXY(360,175,310,325,RGB(255,255,255))
  LineXY(360,175,410,325,RGB(255,255,255))
  LineXY(285,225,435,225,RGB(255,255,255))
  LineXY(285,225,410,325,RGB(255,255,255))
  LineXY(435,225,310,325,RGB(255,255,255))
 EndIf
 
 If KeyboardPushed(#PB_Key_8)
; FrontColor(Random(255),Random(55),Random(55))
  LineXY(360,175,310,325,RGB(Random(255),Random(255),Random(255)))
; FrontColor(Random(255),Random(55),Random(55))
  LineXY(360,175,410,325,RGB(Random(255),Random(255),Random(255)))
; FrontColor(Random(255),Random(55),Random(55))
  LineXY(285,225,435,225,RGB(Random(255),Random(255),Random(255)))
; FrontColor(Random(255),Random(55),Random(55))
  LineXY(285,225,410,325,RGB(Random(255),Random(255),Random(255)))
; FrontColor(Random(255),Random(55),Random(55))
  LineXY(435,225,310,325,RGB(Random(255),Random(255),Random(255)))
 EndIf
 
 If KeyboardPushed(#PB_Key_9)
  For x = 1 To 150
;  FrontColor(Random(255),Random(55),Random(55))
   Plot(285+x,225,RGB(Random(255),Random(55),Random(55)))
  Next
  For x = 1 To 150
;  FrontColor(Random(255),Random(55),Random(55))
   Plot(360-(x*0.3391),175+x,RGB(Random(255),Random(55),Random(55)))
  Next
  For x = 1 To 150
;  FrontColor(Random(255),Random(55),Random(55))
   Plot(360+(x*0.3391),175+x,RGB(Random(255),Random(55),Random(55)))
  Next
  For x = 1 To 150
;  FrontColor(Random(255),Random(55),Random(55))
   Plot(285+(x*0.838),225+(x*0.675),RGB(Random(255),Random(55),Random(55)))
  Next
  For x = 1 To 150
;  FrontColor(Random(255),Random(55),Random(55))
   Plot(435-(x*0.838),225+(x*0.675),RGB(Random(255),Random(55),Random(55)))
  Next
  
  ;Wenn aktiviert, bessere sichtbarkeit der einzelnen Schnittpunkte. . .
  ;FrontColor(255,0,0)
  ;Plot(360,175)
  ;Plot(285,225)
  ;Plot(435,225)
  ;Plot(310,325)
  ;Plot(410,325)
  ;Plot(343,225)
  ;Plot(377,225)
  
 EndIf
 StopDrawing()

 ExamineKeyboard()
 FlipBuffers()
Until KeyboardPushed(#PB_Key_All)
;-----END-----; 
Btw... würde in deiner STelle "ExamineKeyboard()" nicht innerhalb von Start/SopDrawing setzen...

Außerdem "KeyboardPushed(1)" ist falsch... siehe Help! Hab es mal geändert..

Verfasst: 11.09.2005 20:11
von satzzeichen
Okay, das ja schon eine Verbesserung aber jetzt hast du Frontfont und Plot RGB ja immer doppelt?! Werde morgen mal eine verbesserte Version ausarbeiten.

Verfasst: 11.09.2005 20:12
von NicTheQuick
Die zweitletzte Zeile sollte vielleicht eher so heißen:

Code: Alles auswählen

Until KeyboardPushed(#PB_Key_Escape) 

Verfasst: 11.09.2005 20:58
von merlin
satzzeichen hat geschrieben:Okay, das ja schon eine Verbesserung aber jetzt hast du Frontfont und Plot RGB ja immer doppelt?! Werde morgen mal eine verbesserte Version ausarbeiten.
Ok, du übergibts jeden Plot() direkt die farbe... also daher kann sich das ganze öfters wiederholen (je nach codingstyle) ... aber auch wenn du ein paar werte mehr, bzw RGB übergibts, so wird es einiges schneller!

Ich würd mir statt Plot() und RGB() in kürzerer Schreibweise oder wie auch immer zu optimieren, lieber mal die Random() - Geschichte optimieren oder zumindest abändern... da steckt auch noch einiges an versteckter leistung hinter..

Verfasst: 11.09.2005 20:59
von merlin
NicTheQuick hat geschrieben:Die zweitletzte Zeile sollte vielleicht eher so heißen:

Code: Alles auswählen

Until KeyboardPushed(#PB_Key_Escape) 
naja :wink: ich bin generell auch absolut deiner meinung... habe aber einfach mal in dem source - weil vorher der wert (1) stand... mal zeigen wollen das auch jede taste gültig ist :)

Verfasst: 12.09.2005 15:06
von satzzeichen
So ich habe alle eure Wünsche erfüllt und habe bemerkt, das wenn man bei Plot direkt RGB mit reinschreibt ja gleich 500% mehr Performance da ist :P damit ihr den Unterschied seht, habe ich Beispiel 1 mit der langsamen Methode und 2. mit der schnellen gemacht :). Habe den 1. beitrag editet und den neuen Code reingeschrieben.

Viel Spass noch damit!!!

MfG satzzeichen