à dessiner des chapeaux

Les derniers trucs auxquels vous avez joué, les derniers ordinateurs que vous avez bidouillés.

Modérateur : Politburo

Avatar de l’utilisateur
jvernet
Fonctionne à 14400 bauds
Fonctionne à 14400 bauds
Messages : 7527
Inscription : 24 mai 2002 09:57
Localisation : France 69
Contact :

Re: à dessiner des chapeaux

Message par jvernet » 29 mars 2018 19:06

Une autre version, trouvé sur une vieille disquette datant de mes études, qui ressemblent un peu au autres, toujours pour Quick Basic:
Elle trace en fil de fer, mais sans face cachées.
Votre devoir: ajouter les faces cachées.
La encore, c'est pas bien foutu: fait deux fois le calcul, une fois pour trouver les limites, une fois pour tracer.

Code : Tout sélectionner

REM Surface
DECLARE SUB FindWindow ()
DECLARE SUB FindEyeCoordinates ()
DECLARE SUB FindScreenCoordinates ()
DECLARE SUB FindLimits ()
DECLARE FUNCTION Fun! (x AS SINGLE, y AS SINGLE)
CONST x1 = 0, y1 = 0, x2 = 639, y2 = 479
COMMON SHARED xMin  AS SINGLE, xMax AS SINGLE, yMin AS SINGLE, yMax AS SINGLE
COMMON SHARED x AS SINGLE, y AS SINGLE, dx AS SINGLE, dy AS SINGLE, Ax AS SINGLE, Ay AS SINGLE, Bx AS SINGLE, By AS SINGLE
COMMON SHARED dxMin AS SINGLE, dxMax AS SINGLE, dyMin AS SINGLE, dyMax AS SINGLE
COMMON SHARED xOld AS INTEGER, yOld AS INTEGER, xNew AS INTEGER, yNew AS INTEGER
COMMON SHARED Rad AS INTEGER, D AS INTEGER
COMMON SHARED sinT AS SINGLE, cosT AS SINGLE, sinP AS SINGLE, cosP AS SINGLE
CONST Big = 9.999999E+10, Margin = .1
REM DIM SHOW2 AS INTEGER


  xCount% = 30
  yCount% = 30
  xMin = -10
  xMax = 10
  yMin = -10
  yMax = 10
  Rad = 30
  Theta# = -.1
  Phi# = .8
  D = 10
  SCREEN 12
  COLOR 15
  CLS
  LINE (0, 0)-(639, 479), , B
  sinT = SIN(Theta#)
  cosT = COS(Theta#)
  sinP = SIN(Phi#)
  cosP = COS(Phi#)
  xStep# = (xMax - xMin) / xCount%
  yStep# = (yMax - yMin) / yCount%
  dxMin = Big
  dxMax = -Big
  dyMin = Big
  dyMax = -Big
  FOR SHOW2 = 0 TO -1 STEP -1
    FOR i% = 0 TO xCount%
      x = xMin + i% * xStep#
      y = yMin
       CALL FindEyeCoordinates
      IF SHOW2 THEN
        CALL FindScreenCoordinates
        xOld = xNew
        yOld = yNew
        PSET (xOld, yOld)
        ELSE CALL FindLimits
      END IF
      FOR j% = 0 TO yCount%
        y = yMin + j% * yStep#
        CALL FindEyeCoordinates
        IF SHOW2 THEN
          CALL FindScreenCoordinates
          LINE (xOld, yOld)-(xNew, yNew)
          xOld = xNew
          yOld = yNew
          ELSE CALL FindLimits
        END IF
      NEXT j%
    NEXT i%
    FOR i% = 0 TO yCount%
      y = yMin + i% * yStep#
      x = xMin
      CALL FindEyeCoordinates
      IF SHOW2 THEN
        CALL FindScreenCoordinates
        xOld = xNew
        yOld = yNew
        PSET (xOld, yOld)
        ELSE CALL FindLimits
      END IF
      FOR j% = 0 TO xCount%
        x = xMin + j% * xStep#
        CALL FindEyeCoordinates
        IF SHOW2 THEN
          CALL FindScreenCoordinates
          LINE (xOld, yOld)-(xNew, yNew)
          xOld = xNew
          yOld = yNew
          ELSE CALL FindLimits
        END IF
      NEXT j%
    NEXT i%
    IF NOT SHOW2 THEN CALL FindWindow
  NEXT SHOW2
  WHILE INKEY$ = "": WEND
  SCREEN 0: WIDTH 80, 25
END

SUB FindEyeCoordinates ()
  z# = Fun(x, y)
  xx = -x * sinT + y * cosT
  yy = -x * cosT * cosP - y * sinT * cosP + z# * sinP
  zz = -x * cosT * sinP - y * sinT * sinP - z# * cosP + Rad
  dx = D * xx / zz
  dy = D * yy / zz
END SUB

SUB FindLimits ()
  IF dx > dxMax THEN dxMax = dx
  IF dx < dxMin THEN dxMin = dx
  IF dy > dyMax THEN dyMax = dy
  IF dy < dyMin THEN dyMin = dy
END SUB

SUB FindScreenCoordinates ()
  xNew = FIX(Ax + Bx * dx)
  yNew = y2 - FIX(Ay + By * dy)
END SUB

SUB FindWindow ()
  xSize = dxMax - dxMin
  ySize = dyMax - dyMin
  dxMin = dxMin - Margin * xSize
  dxMax = dxMax + Margin * xSize
  dyMin = dyMin - Margin * ySize
  dyMax = dyMax + Margin * ySize
  Bx = (x2 - x1) / (dxMax - dxMin)
  By = (y2 - y1) / (dyMax - dyMin)
  Ax = x1 - dxMin * Bx
  Ay = y1 - dyMin * By
END SUB

FUNCTION Fun (x AS SINGLE, y AS SINGLE)
  Fun = COS(SQR(x * x + y * y))
REM     Fun = COS((EXP(x * x - y * y)))
END FUNCTION

"l'ordinateur et l'homme sont les deux opposés les plus intégraux qui existent. L'homme est lent, peu rigoureux et très intuitif. L'ordinateur est super rapide, très rigoureux et complètement con."

Répondre

Revenir vers « A quoi t'as joué hier ? »