Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 10-02-2004, 15:48   #1 (permalink)
on fire
 
Benutzerbild von H.Storm
 
Registriert seit: Jan 2003
Ort: Ljubljana
Beiträge: 613
Unhappy Mathe... mir fehlt der Ansatz

...eigentlich fehlt mir net nur der Anstatz. Es fehlt an allem:

Die Folgende Funktion bekommt die Werte
winkel 'ein Wert zwischen 0 und 360'
bri 'ein Wert zwischen 0 und 1'
sat 'ein Wert zwischen 0 und 1'
übergeben.

Daraus ergeben sich:
kreisR, kreisG, kreisB
und
R, G, B

Nun würde ich aber gern R, G, B selbst bestimmen. Das wären dann Werte zwischen 0 und 255 und daraus winkel, bri und sat errechnen. Ich habe keine Ahnung, wie ich das anstellen kann

ActionScript:
  1. function calc() {
  2.    
  3.     if (winkel >= 0 && winkel < 60) {
  4.         kreisR = 00;
  5.         kreisG = 255;
  6.         kreisB = (255 - (Math.floor(255 * (winkel / 60))))
  7.         R = Math.floor((255 * sat) * bri);
  8.         G = Math.floor(255 * bri);
  9.         B = Math.floor((kreisB + ((255 - kreisB) * sat)) * bri);
  10.     }
  11.    
  12.     else if (winkel >= 60 && winkel < 120) {
  13.         kreisR = Math.floor(255 * ((winkel - 60) / 60));
  14.         kreisG = 255;
  15.         kreisB = 00;
  16.         B = Math.floor((255 * sat) * bri);
  17.         G = Math.floor(255 * bri);
  18.         R = Math.floor((kreisR + ((255 - kreisR) * sat)) * bri);
  19.       
  20.     }
  21.    
  22.     else if (winkel >= 120 && winkel < 180) {
  23.         kreisR = 255;
  24.         kreisG = 255 - (Math.floor(255 * ((winkel - 120) / 60)));
  25.         kreisB = 00;
  26.         B = Math.floor((255 * sat) * bri);
  27.         R = Math.floor(255 * bri);
  28.         G = Math.floor((kreisG + ((255 - kreisG) * sat)) * bri);
  29.     }
  30.    
  31.     else if (winkel >= 180 && winkel < 240) {
  32.         kreisR = 255;
  33.         kreisG = 00;
  34.         kreisB = Math.floor(255 * ((winkel - 180) / 60));
  35.         G = Math.floor((255 * sat) * bri);
  36.         R = Math.floor(255 * bri);
  37.         B = Math.floor((kreisB + ((255 - kreisB) * sat)) * bri);
  38.     }
  39.    
  40.     else if (winkel >= 240 && winkel < 300) {
  41.         kreisR = 255 - Math.floor((255 * ((winkel - 240) / 60)));
  42.         kreisG = 00;
  43.         kreisB = 255;
  44.         G = Math.floor((255 * sat) * bri);
  45.         B = Math.floor(255 * bri);
  46.         R = Math.floor((kreisR + ((255 - kreisR) * sat)) * bri);
  47.     }
  48.    
  49.     else if (winkel >= 300 && winkel <= 360) {
  50.         kreisR = 00;
  51.         kreisG = Math.floor(255 * ((winkel - 300) / 60));
  52.         kreisB = 255;
  53.         R = Math.floor((255 * sat) * bri);
  54.         B = Math.floor(255 * bri);
  55.         G = Math.floor((kreisG + ((255 - kreisG) * sat)) * bri);
  56.     }
  57.  
  58. }

Hier mal zum schauen:
klick

Geändert von H.Storm (10-02-2004 um 16:41 Uhr)
H.Storm ist offline   Mit Zitat antworten
Alt 12-02-2004, 10:13   #2 (permalink)
on fire
 
Benutzerbild von H.Storm
 
Registriert seit: Jan 2003
Ort: Ljubljana
Beiträge: 613
*schnüff*

So rechnet der zwar teilweise richtig, aber irgendwas läuft schief

ActionScript:
  1. //setcolor.function
  2. function setcolor (hexstring) {
  3.    
  4.     feldcolor.setRGB(hexstring);
  5.     RTemp = parseInt("0x"+(hexstring.slice(2, 4)));
  6.     GTemp = parseInt("0x"+(hexstring.slice(4, 6)));
  7.     BTemp = parseInt("0x"+(hexstring.slice(6, 8)));
  8.    
  9.     decalc(RTemp, GTemp, BTemp);
  10.    
  11.     rtext = RTemp;
  12.     gtext = GTemp;
  13.     btext = BTemp;
  14.    
  15. }
  16.  
  17. //decalc.function
  18. function decalc (deR, deG, deB) {
  19.     trace("Ausgabe decalc: R: "+deR+" G: "+deG+" B: "+deB);
  20.     trace(" ");
  21.     //case1
  22.     tempbri = deG / 255;
  23.     tempsat = deR / (255 * tempbri);
  24.     tempkreisB = (255 * bri * sat - deB) / (bri * (sat - 1));
  25.     tempwinkel = 0 - 4 * tempkreisB / 17;
  26.     if (tempwinkel >= 0 && tempwinkel < 60) {
  27.         trace("----- Winkel in 0 - 60 -----");
  28.         trace("sat: "+tempsat);
  29.         trace("bri: "+tempbri);
  30.         trace("winkel: "+tempwinkel);
  31.         trace("kreisB: "+tempkreisB);
  32.         trace(" ");
  33.         //break
  34.     }
  35.    
  36.     //case2 
  37.     tempbri = deG / 255;
  38.     tempsat = deB / (255 * tempbri);
  39.     tempkreisR = (255 * bri * sat - deR) / (bri * (sat - 1));
  40.     tempwinkel = (60 * tempkreisR) / 255 + 60;
  41.     if (tempwinkel >= 60 && tempwinkel < 120) {
  42.         trace("----- Winkel in 60 - 120 ---");
  43.         trace("sat: "+tempsat);
  44.         trace("bri: "+tempbri);
  45.         trace("winkel: "+tempwinkel);
  46.         trace("kreisR: "+tempkreisR);
  47.         trace(" ");
  48.         //break
  49.     }
  50.    
  51.     //case3 
  52.     tempbri = deR / 255;
  53.     tempsat = deB / (255 * tempbri);
  54.     tempkreisG = (255 * bri * sat - deG) / (bri * (sat - 1));
  55.     tempwinkel = 180 - (4 * tempkreisG) / 17;
  56.     if (tempwinkel >= 120 && tempwinkel < 180) {
  57.         trace("----- Winkel in 120 - 180 --");
  58.         trace("sat: "+tempsat);
  59.         trace("bri: "+tempbri);
  60.         trace("winkel: "+tempwinkel);
  61.         trace("kreisG: "+tempkreisG);
  62.         trace(" ");
  63.         //break
  64.     }
  65.    
  66.     //case4
  67.     tempbri = deR / 255;
  68.     tempsat = deG / (255 * tempbri);
  69.     tempkreisB = (255 * bri * sat - deB) / (bri * (sat - 1));
  70.     tempwinkel = (4 * tempkreisB) / 17 + 180;
  71.     if (tempwinkel >= 180 && tempwinkel < 240) {
  72.         trace("----- Winkel in 180 - 240 --");
  73.         trace("sat: "+tempsat);
  74.         trace("bri: "+tempbri);
  75.         trace("winkel: "+tempwinkel);
  76.         trace("kreisB: "+tempkreisB);
  77.         trace(" ");
  78.         //break
  79.     }
  80.    
  81.     //case5
  82.     tempbri = deB / 255;
  83.     tempsat = deG / (255 * tempbri);
  84.     tempkreisR = (255 * bri * sat - deR) / (bri * (sat - 1));
  85.     tempwinkel = 300 - (4 * tempkreisR) / 17;
  86.     if (tempwinkel >= 240 && tempwinkel < 300) {
  87.         trace("----- Winkel in 240 - 300 --");
  88.         trace("sat: "+tempsat);
  89.         trace("bri: "+tempbri);
  90.         trace("winkel: "+tempwinkel);
  91.         trace("kreisR: "+tempkreisR);
  92.         trace(" ");
  93.         //break
  94.     }
  95.    
  96.     //case6
  97.     tempbri = deB / 255;
  98.     tempsat = deR / (255 * tempbri);
  99.     tempkreisG = (255 * bri * sat - deG) / (bri * (sat - 1));
  100.     tempwinkel = (4 * tempkreisG) / 17 + 300;
  101.     if (tempwinkel >= 300 && tempwinkel <= 360) {
  102.         trace("----- Winkel in 300 - 360 --");
  103.         trace("sat: "+tempsat);
  104.         trace("bri: "+tempbri);
  105.         trace("winkel: "+tempwinkel);
  106.         trace("kreisG: "+tempkreisG);
  107.         trace(" ");
  108.         //break
  109.     }
  110.    
  111. }

Also der erste Case gibt nur Quatsch raus...
Der Rest funktioniert - bis auf einige Ausnahmen. Division durch 0 z.B.

Geändert von H.Storm (12-02-2004 um 14:44 Uhr)
H.Storm ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind an
Pingbacks sind an
Refbacks sind an



Alle Zeitangaben in WEZ +1. Es ist jetzt 19:52 Uhr.

Domains, Webhosting & Vserver von Host Europe
Unterstützt das Flashforum!
Adobe User Group


Copyright ©1999 – 2012 Marc Thiele