torch.pde 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. Flame torch;
  2. void setup()
  3. {
  4. torch = new Flame(
  5. 220 //xPos
  6. , 200 //yPos
  7. , 10 //width flux
  8. , 4 //tail length flux
  9. , 200 //torch thickness
  10. , 150 //torch source curve
  11. , 100 //torch tail slope
  12. , 200 //torch tail length
  13. , 8 //inner flame offset
  14. , 100 //inner flame tail difference
  15. , 160 //inner flame thickness difference
  16. , 0.8 //inner flame flux strength
  17. );
  18. size(640, 480);
  19. }
  20. void draw()
  21. {
  22. background(0,0,0);
  23. torch.draw();
  24. }
  25. class Flame
  26. {
  27. float positionX = 320;
  28. float positionY = 240;
  29. int fluxRange = 10;
  30. int fluxLength = 4;
  31. float torchThickness = 100;
  32. float torchSourceCurve = 60;
  33. float torchTailSlope = 50;
  34. float torchTailLength = 80;
  35. float innerFlameOffset = 2;
  36. float innerFlameTailDifference = 40;
  37. float innerFlameThicknessDifference = 60;
  38. float innerFlameFluxEffect = 0.5;
  39. Flame(
  40. float inPositionX
  41. , float inPositionY
  42. , int inFluxRange
  43. , int inFluxLength
  44. , float inTorchThickness
  45. , float inTorchSourceCurve
  46. , float inTorchTailSlope
  47. , float inTorchTailLength
  48. , float inInnerFlameOffset
  49. , float inInnerFlameTailDifference
  50. , float inInnerFlameThicknessDifference
  51. , float inInnerFlameFluxEffect
  52. ) {
  53. positionX = inPositionX;
  54. positionY = inPositionY;
  55. fluxRange = inFluxRange;
  56. fluxLength = inFluxLength;
  57. torchThickness = inTorchThickness;
  58. torchSourceCurve = inTorchSourceCurve;
  59. torchTailSlope = inTorchTailSlope;
  60. torchTailLength = inTorchTailLength;
  61. innerFlameOffset = inInnerFlameOffset;
  62. innerFlameTailDifference = inInnerFlameTailDifference;
  63. innerFlameThicknessDifference = inInnerFlameThicknessDifference;
  64. innerFlameFluxEffect = inInnerFlameFluxEffect;
  65. }
  66. void draw()
  67. {
  68. stroke(64,0,128);
  69. fill(32, 0, 64);
  70. float randomFlux = random(-fluxRange, fluxRange);
  71. float randomLength = random(-fluxLength, fluxLength);
  72. curve(
  73. positionX + torchSourceCurve, positionY + torchThickness + randomFlux
  74. , positionX, positionY
  75. , positionX + torchTailLength + randomLength, positionY
  76. , positionX + torchTailLength, positionY + torchTailSlope
  77. );
  78. curve(
  79. positionX + torchSourceCurve, positionY - torchThickness - randomFlux
  80. , positionX, positionY
  81. , positionX + torchTailLength + randomLength, positionY
  82. , positionX + torchTailLength, positionY - torchTailSlope
  83. );
  84. stroke(128, 64, 212);
  85. fill(128, 64, 212);
  86. curve(
  87. positionX + torchSourceCurve, positionY + (torchThickness - innerFlameThicknessDifference) + (randomFlux * innerFlameFluxEffect)
  88. , positionX + innerFlameOffset, positionY
  89. , positionX + (torchTailLength - innerFlameTailDifference) + (randomLength * innerFlameFluxEffect) + innerFlameOffset, positionY
  90. , positionX + torchTailLength, positionY + torchTailSlope
  91. );
  92. curve(
  93. positionX + torchSourceCurve, positionY - (torchThickness - innerFlameThicknessDifference) - (randomFlux * innerFlameFluxEffect)
  94. , positionX + innerFlameOffset, positionY
  95. , positionX + (torchTailLength - innerFlameTailDifference) + (randomLength * innerFlameFluxEffect) + innerFlameOffset, positionY
  96. , positionX + torchTailLength, positionY - torchTailSlope
  97. );
  98. }
  99. }